DWDanmu.min.js 11 KB

1
  1. !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.DWDanmu=n():t.DWDanmu=n()}(window,function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=7)}([function(t,n,e){"use strict";t.exports=function(t){var n=[];return n.toString=function(){return this.map(function(n){var e=function(t,n){var e=t[1]||"",r=t[3];if(!r)return e;if(n&&"function"==typeof btoa){var o=(s=r,a=btoa(unescape(encodeURIComponent(JSON.stringify(s)))),c="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(a),"/*# ".concat(c," */")),i=r.sources.map(function(t){return"/*# sourceURL=".concat(r.sourceRoot).concat(t," */")});return[e].concat(i).concat([o]).join("\n")}var s,a,c;return[e].join("\n")}(n,t);return n[2]?"@media ".concat(n[2],"{").concat(e,"}"):e}).join("")},n.i=function(t,e){"string"==typeof t&&(t=[[null,t,""]]);for(var r={},o=0;o<this.length;o++){var i=this[o][0];null!=i&&(r[i]=!0)}for(var s=0;s<t.length;s++){var a=t[s];null!=a[0]&&r[a[0]]||(e&&!a[2]?a[2]=e:e&&(a[2]="(".concat(a[2],") and (").concat(e,")")),n.push(a))}},n}},function(t,n,e){var r,o,i={},s=(r=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===o&&(o=r.apply(this,arguments)),o}),a=function(t){var n={};return function(t,e){if("function"==typeof t)return t();if(void 0===n[t]){var r=function(t,n){return n?n.querySelector(t):document.querySelector(t)}.call(this,t,e);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(t){r=null}n[t]=r}return n[t]}}(),c=null,f=0,u=[],l=e(4);function p(t,n){for(var e=0;e<t.length;e++){var r=t[e],o=i[r.id];if(o){o.refs++;for(var s=0;s<o.parts.length;s++)o.parts[s](r.parts[s]);for(;s<r.parts.length;s++)o.parts.push(y(r.parts[s],n))}else{var a=[];for(s=0;s<r.parts.length;s++)a.push(y(r.parts[s],n));i[r.id]={id:r.id,refs:1,parts:a}}}}function d(t,n){for(var e=[],r={},o=0;o<t.length;o++){var i=t[o],s=n.base?i[0]+n.base:i[0],a={css:i[1],media:i[2],sourceMap:i[3]};r[s]?r[s].parts.push(a):e.push(r[s]={id:s,parts:[a]})}return e}function h(t,n){var e=a(t.insertInto);if(!e)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var r=u[u.length-1];if("top"===t.insertAt)r?r.nextSibling?e.insertBefore(n,r.nextSibling):e.appendChild(n):e.insertBefore(n,e.firstChild),u.push(n);else if("bottom"===t.insertAt)e.appendChild(n);else{if("object"!=typeof t.insertAt||!t.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var o=a(t.insertAt.before,e);e.insertBefore(n,o)}}function m(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t);var n=u.indexOf(t);n>=0&&u.splice(n,1)}function g(t){var n=document.createElement("style");if(void 0===t.attrs.type&&(t.attrs.type="text/css"),void 0===t.attrs.nonce){var r=function(){0;return e.nc}();r&&(t.attrs.nonce=r)}return v(n,t.attrs),h(t,n),n}function v(t,n){Object.keys(n).forEach(function(e){t.setAttribute(e,n[e])})}function y(t,n){var e,r,o,i;if(n.transform&&t.css){if(!(i="function"==typeof n.transform?n.transform(t.css):n.transform.default(t.css)))return function(){};t.css=i}if(n.singleton){var s=f++;e=c||(c=g(n)),r=x.bind(null,e,s,!1),o=x.bind(null,e,s,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(e=function(t){var n=document.createElement("link");return void 0===t.attrs.type&&(t.attrs.type="text/css"),t.attrs.rel="stylesheet",v(n,t.attrs),h(t,n),n}(n),r=function(t,n,e){var r=e.css,o=e.sourceMap,i=void 0===n.convertToAbsoluteUrls&&o;(n.convertToAbsoluteUrls||i)&&(r=l(r));o&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var s=new Blob([r],{type:"text/css"}),a=t.href;t.href=URL.createObjectURL(s),a&&URL.revokeObjectURL(a)}.bind(null,e,n),o=function(){m(e),e.href&&URL.revokeObjectURL(e.href)}):(e=g(n),r=function(t,n){var e=n.css,r=n.media;r&&t.setAttribute("media",r);if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}.bind(null,e),o=function(){m(e)});return r(t),function(n){if(n){if(n.css===t.css&&n.media===t.media&&n.sourceMap===t.sourceMap)return;r(t=n)}else o()}}t.exports=function(t,n){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(n=n||{}).attrs="object"==typeof n.attrs?n.attrs:{},n.singleton||"boolean"==typeof n.singleton||(n.singleton=s()),n.insertInto||(n.insertInto="head"),n.insertAt||(n.insertAt="bottom");var e=d(t,n);return p(e,n),function(t){for(var r=[],o=0;o<e.length;o++){var s=e[o];(a=i[s.id]).refs--,r.push(a)}t&&p(d(t,n),n);for(o=0;o<r.length;o++){var a;if(0===(a=r[o]).refs){for(var c=0;c<a.parts.length;c++)a.parts[c]();delete i[a.id]}}}};var b,w=(b=[],function(t,n){return b[t]=n,b.filter(Boolean).join("\n")});function x(t,n,e,r){var o=e?"":r.css;if(t.styleSheet)t.styleSheet.cssText=w(n,o);else{var i=document.createTextNode(o),s=t.childNodes;s[n]&&t.removeChild(s[n]),s.length?t.insertBefore(i,s[n]):t.appendChild(i)}}},function(t,n,e){var r=e(3);"string"==typeof r&&(r=[[t.i,r,""]]);var o={hmr:!0,transform:void 0,insertInto:void 0};e(1)(r,o);r.locals&&(t.exports=r.locals)},function(t,n,e){(t.exports=e(0)(!1)).push([t.i,"#dwdanmu {\n width: 100%;\n height: 100%;\n left: 0;\n top: 0;\n overflow: hidden;\n background-color: transparent;\n position: absolute; }\n #dwdanmu span {\n position: absolute;\n right: 0;\n top: 0;\n font-size: 14px;\n -webkit-transform: translateX(100%);\n transform: translateX(100%);\n white-space: nowrap; }\n #dwdanmu span.animate {\n -webkit-transition-property: all;\n transition-property: all;\n -webkit-transition-timing-function: linear;\n transition-timing-function: linear; }\n",""])},function(t,n){t.exports=function(t){var n="undefined"!=typeof window&&window.location;if(!n)throw new Error("fixUrls requires window.location");if(!t||"string"!=typeof t)return t;var e=n.protocol+"//"+n.host,r=e+n.pathname.replace(/\/[^\/]*$/,"/");return t.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(t,n){var o,i=n.trim().replace(/^"(.*)"$/,function(t,n){return n}).replace(/^'(.*)'$/,function(t,n){return n});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?t:(o=0===i.indexOf("//")?i:0===i.indexOf("/")?e+i:r+i.replace(/^\.\//,""),"url("+JSON.stringify(o)+")")})}},function(t,n,e){var r=e(6);"string"==typeof r&&(r=[[t.i,r,""]]);var o={hmr:!0,transform:void 0,insertInto:void 0};e(1)(r,o);r.locals&&(t.exports=r.locals)},function(t,n,e){(n=t.exports=e(0)(!1)).push([t.i,".Fe214AWPaiU9RQxhedaZD {\n -webkit-transition-property: all;\n transition-property: all;\n -webkit-transition-timing-function: linear;\n transition-timing-function: linear; }\n",""]),n.locals={animate:"Fe214AWPaiU9RQxhedaZD"}},function(t,n,e){"use strict";e.r(n);var r=function(t,n){return Math.floor(Math.random()*(n-t+1)+t)};var o={colorList:["rgb(128,208,198)","rgb(224,125,148)","rgb(127,214,255)","rgb(236,198,130)","rgb(33,33,33)"],danmuList:["xxx","yyyy","zzzzzz"],timeInterval:800,transitionDuration:6e3,grabComment:!1};e(2);var i=e(5),s=function(){function t(t){if(this.config=t,!this.config.el)throw new Error("An element must be provided for mounting the node.");if("string"==typeof this.config.el){if(!document.querySelector(this.config.el))throw new Error("Element does not exist.");this.$parent=document.querySelector(this.config.el)}else this.$parent=this.config.el;var n=function(){var t=document.createElement("div");return t.setAttribute("id","dwdanmu"),t}();this.$wrapper=n,this.$parent.appendChild(this.$wrapper),this.width=this.config.width?this.config.width:this.$parent.offsetWidth,this.height=this.config.height?this.config.height:this.$wrapper.offsetHeight,this._initWrapper(),this._processConfig(),this._init()}return t.prototype._init=function(){var t=this,n=[];setInterval(function(){for(var e=t.config.danmuList[r(0,t.config.danmuList.length-1)],o=0;n.includes(e);)if(e=t.config.danmuList[r(0,t.config.danmuList.length-1)],++o>=10)return;n.push(e);var s,a,c=(s={message:e,color:t.config.colorList[r(0,t.config.colorList.length-1)],maxHeight:t.height},(a=document.createElement("span")).style.color=s.color,a.style.fontSize=r(14,20)+"px",a.style.top=r(0,s.maxHeight-20)+"px",a.innerText=s.message,a);t.$wrapper.appendChild(c),c.classList.add(i.animate),c.style.transitionDuration=t.config.transitionDuration+"ms",c.style.transform="translateX(-"+(t.width+c.offsetWidth)+"px)",setTimeout(function(){c.remove(),n.shift()},t.config.transitionDuration)},this.config.timeInterval),this.config.grabComment&&this._getDanmuTextFromComments()},t.prototype._processConfig=function(){this.config.colorList=this.config.colorList?this.config.colorList:o.colorList,this.config.danmuList=this.config.danmuList?this.config.danmuList:o.danmuList,this.config.timeInterval=this.config.timeInterval?this.config.timeInterval:o.timeInterval,this.config.transitionDuration=this.config.transitionDuration?this.config.transitionDuration:o.transitionDuration,this.config.grabComment=this.config.grabComment?this.config.grabComment:o.grabComment},t.prototype._initWrapper=function(){this.config.top&&(this.$wrapper.style.top=this.config.top+"px"),this.config.left&&(this.$wrapper.style.left=this.config.left+"px"),this.$wrapper.style.width=this.width+"px",this.$wrapper.style.height=this.height+"px"},t.prototype._getDanmuTextFromComments=function(){var t=this,n=setInterval(function(){document.querySelectorAll(".dw-comment-comment_list .comment_text")&&setTimeout(function(){Array.from(document.querySelectorAll(".dw-comment-comment_list .comment_text")).forEach(function(n){t.config.danmuList.push(n.innerText)}),clearInterval(n)},1e3)},300)},t}();n.default=s}])});