Browse Source

new option: danmaku.user, cc #50

DIYgod 8 years ago
parent
commit
18acaad609
6 changed files with 13 additions and 9 deletions
  1. 2 1
      demo/index.html
  2. 0 0
      dist/DPlayer.min.js
  3. 0 0
      dist/DPlayer.min.js.map
  4. 8 7
      src/DPlayer.js
  5. 0 1
      src/DPlayer.scss
  6. 3 0
      src/option.js

+ 2 - 1
demo/index.html

@@ -83,7 +83,8 @@
             id: '9E2E3368B56CDBB4',
             api: 'https://api.prprpr.me/dplayer/',
             token: 'tokendemo',
-            maximum: 3000
+            maximum: 3000,
+            user: 'DIYgod的女粉'
         }
     });
     function switchDPlayer() {

File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js.map


+ 8 - 7
src/DPlayer.js

@@ -1,7 +1,6 @@
 console.log("\n %c DPlayer 1.1.4 %c http://dplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;");
 
 require('./DPlayer.scss');
-const defaultApiBackend = require('./api.js');
 const svg = require('./svg.js');
 const handleOption = require('./option.js');
 const i18n = require('./i18n.js');
@@ -252,10 +251,12 @@ class DPlayer {
             }, 100);
             if (this.option.danmaku && showdan) {
                 danmakuTime = setInterval(() => {
-                    let item = this.dan[this.danIndex];
-                    while (item && this.video.currentTime > parseFloat(item.time)) {
-                        this.pushDanmaku(item.text, item.color, item.type);
-                        item = this.dan[++this.danIndex];
+                    if (this.dan) {
+                        let item = this.dan[this.danIndex];
+                        while (item && this.video.currentTime > parseFloat(item.time)) {
+                            this.pushDanmaku(item.text, item.color, item.type);
+                            item = this.dan[++this.danIndex];
+                        }
                     }
                 }, 100);
             }
@@ -661,7 +662,7 @@ class DPlayer {
             const danmakuData = {
                 token: this.option.danmaku.token,
                 player: this.option.danmaku.id,
-                author: 'DIYgod',
+                author: this.option.danmaku.user,
                 time: this.video.currentTime,
                 text: commentInput.value,
                 color: this.element.querySelector('.dplayer-comment-setting-color input:checked').value,
@@ -748,7 +749,7 @@ class DPlayer {
          * full screen
          */
         const resetAnimation = () => {
-            danWidth = danContainer.offsetWidth;
+            let danWidth = danContainer.offsetWidth;
             const items = this.element.getElementsByClassName('dplayer-danmaku-item');
             for (let i = 0; i < items.length; i++) {
                 items[i].style.transform = `translateX(-${danWidth}px)`;

+ 0 - 1
src/DPlayer.scss

@@ -176,7 +176,6 @@
             user-select: none;
             cursor: default;
             white-space: nowrap;
-            font-weight: bolder;
             text-shadow: .5px .5px .5px rgba(0,0,0,.5);
 
             &--demo {

+ 3 - 0
src/option.js

@@ -27,6 +27,9 @@ module.exports = (option) => {
     if (!option.video.hasOwnProperty('type')) {
         option.video.type = 'auto';
     }
+    if (!option.danmaku.hasOwnProperty('user')) {
+        option.danmaku.user = 'DIYgod';
+    }
 
     return option;
 };

Some files were not shown because too many files changed in this diff