优化弹幕库

This commit is contained in:
Harvey Zack committed 2019-04-28 11:14:32 +08:00
1 parent cd67baae94
commit b73611b126
4 files changed
+14 -3024

No files matched your search

+8 -8
View File
@@ -1,6 +1,6 @@
// 使用 Github Issues Api 做弹幕接口
// 接口每小时限制 5000 次请求,勿滥用
var github = new ArtplayerToolGithub({
var danmuku = new ArtplayerToolGithub({
api: 'zhw2590582/github-issues-api-as-danmuku/issues/1',
clientID: '749a95aad589f8849abe',
clientSecret: '7bb6fa67ef6e525e5bd5fda46cd3925ecc4a3760',
@@ -19,8 +19,8 @@ var art = new Artplayer({
click: () => {
if (window.location.href.includes('code=')) {
art.notice.show('正在登陆中,请稍等!!!');
} else if (!github.isLogin) {
github.login();
} else if (!danmuku.isLogin) {
danmuku.login();
} else {
var text = prompt('请输入:', '弹幕内容');
if (!text || !text.trim()) return;
@@ -28,26 +28,26 @@ var art = new Artplayer({
art.notice.show('弹幕字数不能大于20字!!!');
return;
}
if (github.remaining <= 10) {
if (danmuku.remaining <= 10) {
art.notice.show('接口请求到达上限,请稍后再试!!!');
return;
}
art.notice.show('弹幕发送中...');
github
danmuku
.send({
text: text,
time: art.player.currentTime,
color: '#' + Math.floor(Math.random() * 0xffffff).toString(16),
})
.then(data => {
art.notice.show(`发送弹幕成功: ${github.remaining} / ${github.limit}`);
art.notice.show(`发送弹幕成功: ${danmuku.remaining} / ${danmuku.limit}`);
art.plugins.artplayerPluginDanmu.emit({
...data,
time: art.player.currentTime,
border: data.color,
});
}).catch(() => {
art.notice.show(`发送弹幕失败: ${github.remaining} / ${github.limit}`);
art.notice.show(`发送弹幕失败: ${danmuku.remaining} / ${danmuku.limit}`);
});
}
},
@@ -55,7 +55,7 @@ var art = new Artplayer({
],
plugins: [
artplayerPluginDanmu({
danmus: () => github.cache(),
danmus: () => danmuku.load(),
speed: 5,
opacity: 1,
color: '#fff',
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"artplayer-tool-github.js","sources":["../../packages/artplayer-tool-github/node_modules/localforage/dist/localforage.js","../../packages/artplayer-tool-github/node_modules/issues-danmuku/src/utils.js","../../packages/artplayer-tool-github/node_modules/issues-danmuku/src/index.js","../../packages/artplayer-tool-github/src/index.js"],"sourcesContent":["/*!\n localForage -- Offline Storage, Improved\n Version 1.7.3\n https://localforage.github.io/localForage\n (c) 2013-2017 Mozilla, Apache License 2.0\n*/\n(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}g.localforage = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw (f.code=\"MODULE_NOT_FOUND\", f)}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){\n(function (global){\n'use strict';\nvar Mutation = global.MutationObserver || global.WebKitMutationObserver;\n\nvar scheduleDrain;\n\n{\n if (Mutation) {\n var called = 0;\n var observer = new Mutation(nextTick);\n var element = global.document.createTextNode('');\n observer.observe(element, {\n characterData: true\n });\n scheduleDrain = function () {\n element.data = (called = ++called % 2);\n };\n } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {\n var channel = new global.MessageChannel();\n channel.port1.onmessage = nextTick;\n scheduleDrain = function () {\n channel.port2.postMessage(0);\n };\n } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {\n scheduleDrain = function () {\n\n // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted\n // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.\n var scriptEl = global.document.createElement('script');\n scriptEl.onreadystatechange = function () {\n nextTick();\n\n scriptEl.onreadystatechange = null;\n scriptEl.parentNode.removeChild(scriptEl);\n scriptEl = null;\n };\n global.document.documentElement.appendChild(scriptEl);\n };\n } else {\n scheduleDrain = function () {\n setTimeout(nextTick, 0);\n };\n }\n}\n\nvar draining;\nvar queue = [];\n//named nextTick for less confusing stack traces\nfunction nextTick() {\n draining = true;\n var i, oldQueue;\n var len = queue.length;\n while (len) {\n oldQueue = queue;\n queue = [];\n i = -1;\n while (++i < len) {\n oldQueue[i]();\n }\n len = queue.length;\n }\n draining = false;\n}\n\nmodule.exports = immediate;\nfunction immediate(task) {\n if (queue.push(task) === 1 && !draining) {\n scheduleDrain();\n }\n}\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{}],2:[function(_dereq_,module,exports){\n'use strict';\nvar immediate = _dereq_(1);\n\n/* istanbul ignore next */\nfunction INTERNAL() {}\n\nvar handlers = {};\n\nvar REJECTED = ['REJECTED'];\nvar FULFILLED = ['FULFILLED'];\nvar PENDING = ['PENDING'];\n\nmodule.exports = Promise;\n\nfunction Promise(resolver) {\n if (typeof resolver !== 'function') {\n throw new TypeError('resolver must be a function');\n }\n this.state = PENDING;\n this.queue = [];\n this.outcome = void 0;\n if (resolver !== INTERNAL) {\n safelyResolveThenable(this, resolver);\n }\n}\n\nPromise.prototype[\"catch\"] = function (onRejected) {\n return this.then(null, onRejected);\n};\nPromise.prototype.then = function (onFulfilled, onRejected) {\n if (typeof onFulfilled !== 'function' && this.state === FULFILLED ||\n typeof onRejected !== 'function' && this.state === REJECTED) {\n return this;\n }\n var promise = new this.constructor(INTERNAL);\n if (this.state !== PENDING) {\n var resolver = this.state === FULFILLED ? onFulfilled : onRejected;\n unwrap(promise, resolver, this.outcome);\n } else {\n this.queue.push(new QueueItem(promise, onFulfilled, onRejected));\n }\n\n return promise;\n};\nfunction QueueItem(promise, onFulfilled, onRejected) {\n this.promise = promise;\n if (typeof onFulfilled === 'function') {\n this.onFulfilled = onFulfilled;\n this.callFulfilled = this.otherCallFulfilled;\n }\n if (typeof onRejected =Line truncated
{"version":3,"file":"artplayer-tool-github.js","sources":["../../packages/artplayer-tool-github/node_modules/issues-danmuku/dist/issuesDanmuku.js","../../packages/artplayer-tool-github/src/index.js"],"sourcesContent":["!function(t,e){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=e():\"function\"==typeof define&&define.amd?define(e):(t=t||self).IssuesDanmuku=e()}(this,function(){\"use strict\";var o=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t};var i=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);\"function\"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(t){o(e,t,r[t])})}return e};var t,a=(function(t){var e=function(i){var u,t=Object.prototype,s=t.hasOwnProperty,e=\"function\"==typeof Symbol?Symbol:{},o=e.iterator||\"@@iterator\",r=e.asyncIterator||\"@@asyncIterator\",n=e.toStringTag||\"@@toStringTag\";function a(t,e,r,n){var o=e&&e.prototype instanceof c?e:c,i=Object.create(o.prototype),a=new j(n||[]);return i._invoke=function(i,a,c){var u=f;return function(t,e){if(u===p)throw new Error(\"Generator is already running\");if(u===y){if(\"throw\"===t)throw e;return S()}for(c.method=t,c.arg=e;;){var r=c.delegate;if(r){var n=O(r,c);if(n){if(n===d)continue;return n}}if(\"next\"===c.method)c.sent=c._sent=c.arg;else if(\"throw\"===c.method){if(u===f)throw u=y,c.arg;c.dispatchException(c.arg)}else\"return\"===c.method&&c.abrupt(\"return\",c.arg);u=p;var o=h(i,a,c);if(\"normal\"===o.type){if(u=c.done?y:l,o.arg===d)continue;return{value:o.arg,done:c.done}}\"throw\"===o.type&&(u=y,c.method=\"throw\",c.arg=o.arg)}}}(t,r,a),i}function h(t,e,r){try{return{type:\"normal\",arg:t.call(e,r)}}catch(t){return{type:\"throw\",arg:t}}}i.wrap=a;var f=\"suspendedStart\",l=\"suspendedYield\",p=\"executing\",y=\"completed\",d={};function c(){}function g(){}function v(){}var m={};m[o]=function(){return this};var w=Object.getPrototypeOf,b=w&&w(w(P([])));b&&b!==t&&s.call(b,o)&&(m=b);var k=v.prototype=c.prototype=Object.create(m);function x(t){[\"next\",\"throw\",\"return\"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function L(u){var e;this._invoke=function(r,n){function t(){return new Promise(function(t,e){!function e(t,r,n,o){var i=h(u[t],u,r);if(\"throw\"!==i.type){var a=i.arg,c=a.value;return c&&\"object\"==typeof c&&s.call(c,\"__await\")?Promise.resolve(c.__await).then(function(t){e(\"next\",t,n,o)},function(t){e(\"throw\",t,n,o)}):Promise.resolve(c).then(function(t){a.value=t,n(a)},function(t){return e(\"throw\",t,n,o)})}o(i.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}}function O(t,e){var r=t.iterator[e.method];if(r===u){if(e.delegate=null,\"throw\"===e.method){if(t.iterator.return&&(e.method=\"return\",e.arg=u,O(t,e),\"throw\"===e.method))return d;e.method=\"throw\",e.arg=new TypeError(\"The iterator does not provide a 'throw' method\")}return d}var n=h(r,t.iterator,e.arg);if(\"throw\"===n.type)return e.method=\"throw\",e.arg=n.arg,e.delegate=null,d;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,\"return\"!==e.method&&(e.method=\"next\",e.arg=u),e.delegate=null,d):o:(e.method=\"throw\",e.arg=new TypeError(\"iterator result is not an object\"),e.delegate=null,d)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type=\"normal\",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:\"root\"}],t.forEach(_,this),this.reset(!0)}function P(e){if(e){var t=e[o];if(t)return t.call(e);if(\"function\"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(s.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=u,t.done=!0,t};return n.next=n}}return{next:S}}function S(){return{value:u,done:!0}}return g.prototype=k.constructor=v,v.constructor=g,v[n]=g.displayName=\"GeneratorFunction\",i.isGeneratorFunction=function(t){var e=\"function\"==typeof t&&t.constructor;return!!e&&(e===g||\"GeneratorFunction\"===(e.displayName||e.name))},i.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,n in t||(t[n]=\"GeneratorFunction\")),t.prototype=Object.create(k),t},i.awrap=function(t){return{__await:t}},x(L.prototype),L.prototype[r]=function(){return this},i.AsyncIterator=L,i.async=function(t,e,r,n){var o=new L(a(t,e,r,n));return i.isGeneratorFunction(e)?o:o.next().then(function(t){return t.done?t.value:o.next()})},x(k),k[n]=\"Generator\",k[o]=function(){return this},k.toString=function(){return\"[object Generator]\"},i.keys=function(r){var n=[];for(var t in r)n.push(t);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},i.values=P,j.prototype={constructor:j,rLine truncated
+1 -1
View File
@@ -21,6 +21,6 @@
},
"homepage": "https://github.com/zhw2590582/ArtPlayer#readme",
"dependencies": {
"issues-danmuku": "^1.0.3"
"issues-danmuku": "^1.0.4"
}
}