mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 11:56:15 -08:00
9 lines
41 KiB
JavaScript
9 lines
41 KiB
JavaScript
/*!
|
|
* artplayer-tool-github.js v3.1.7
|
|
* Github: https://github.com/zhw2590582/ArtPlayer#readme
|
|
* (c) 2017-2019 Harvey Zack
|
|
* Released under the MIT License.
|
|
*/
|
|
|
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self)["artplayer-tool-github"]=t()}(this,function(){"use strict";var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e,t=(function(e,t){e.exports=function(){var u=function(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()},c=function(o){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},t=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),t.forEach(function(e){var t,n,r;t=o,r=i[n=e],n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r})}return o},r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==n?n:"undefined"!=typeof self?self:{};function l(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function e(e,t){return e(t={exports:{}},t.exports),t.exports}var s=e(function(e){var t=function(i){var c,e=Object.prototype,s=e.hasOwnProperty,t="function"==typeof Symbol?Symbol:{},o=t.iterator||"@@iterator",n=t.asyncIterator||"@@asyncIterator",r=t.toStringTag||"@@toStringTag";function a(e,t,n,r){var o=t&&t.prototype instanceof u?t:u,i=Object.create(o.prototype),a=new j(r||[]);return i._invoke=function(i,a,u){var c=l;return function(e,t){if(c===h)throw new Error("Generator is already running");if(c===v){if("throw"===e)throw t;return O()}for(u.method=e,u.arg=t;;){var n=u.delegate;if(n){var r=E(n,u);if(r){if(r===p)continue;return r}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(c===l)throw c=v,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);c=h;var o=f(i,a,u);if("normal"===o.type){if(c=u.done?v:d,o.arg===p)continue;return{value:o.arg,done:u.done}}"throw"===o.type&&(c=v,u.method="throw",u.arg=o.arg)}}}(e,n,a),i}function f(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}i.wrap=a;var l="suspendedStart",d="suspendedYield",h="executing",v="completed",p={};function u(){}function y(){}function b(){}var m={};m[o]=function(){return this};var g=Object.getPrototypeOf,w=g&&g(g(N([])));w&&w!==e&&s.call(w,o)&&(m=w);var _=b.prototype=u.prototype=Object.create(m);function I(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function S(c){var t;this._invoke=function(n,r){function e(){return new Promise(function(e,t){!function t(e,n,r,o){var i=f(c[e],c,n);if("throw"!==i.type){var a=i.arg,u=a.value;return u&&"object"==typeof u&&s.call(u,"__await")?Promise.resolve(u.__await).then(function(e){t("next",e,r,o)},function(e){t("throw",e,r,o)}):Promise.resolve(u).then(function(e){a.value=e,r(a)},function(e){return t("throw",e,r,o)})}o(i.arg)}(n,r,e,t)})}return t=t?t.then(e,e):e()}}function E(e,t){var n=e.iterator[t.method];if(n===c){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=c,E(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var r=f(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,p;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=c),t.delegate=null,p):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function x(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function j(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(x,this),this.reset(!0)}function N(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,r=function e(){for(;++n<t.length;)if(s.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=c,e.done=!0,e};return r.next=r}}return{next:O}}function O(){return{value:c,done:!0}}return y.prototype=_.constructor=b,b.constructor=y,b[r]=y.displayName="GeneratorFunction",i.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},i.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,r in e||(e[r]="GeneratorFunction")),e.prototype=Object.create(_),e},i.awrap=function(e){return{__await:e}},I(S.prototype),S.prototype[n]=function(){return this},i.AsyncIterator=S,i.async=function(e,t,n,r){var o=new S(a(e,t,n,r));return i.isGeneratorFunction(t)?o:o.next().then(function(e){return e.done?e.value:o.next()})},I(_),_[r]="Generator",_[o]=function(){return this},_.toString=function(){return"[object Generator]"},i.keys=function(n){var r=[];for(var e in n)r.push(e);return r.reverse(),function e(){for(;r.length;){var t=r.pop();if(t in n)return e.value=t,e.done=!1,e}return e.done=!0,e}},i.values=N,j.prototype={constructor:j,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&s.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=c)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var r=this;function e(e,t){return i.type="throw",i.arg=n,r.next=e,t&&(r.method="next",r.arg=c),!!t}for(var t=this.tryEntries.length-1;0<=t;--t){var o=this.tryEntries[t],i=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),u=s.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return e(o.catchLoc,!0);if(this.prev<o.finallyLoc)return e(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return e(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return e(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;0<=t;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),k(n),p}},catch:function(e){for(var t=this.tryEntries.length-1;0<=t;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;k(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:N(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=c),p}},i}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}});function f(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,o)}var d=function(u){return function(){var e=this,a=arguments;return new Promise(function(t,n){var r=u.apply(e,a);function o(e){f(r,t,n,o,i,"next",e)}function i(e){f(r,t,n,o,i,"throw",e)}o(void 0)})}};function h(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var v=e(function(e,t){e.exports=function i(a,u,c){function s(n,e){if(!u[n]){if(!a[n]){var t=l;if(!e&&t)return t(n,!0);if(f)return f(n,!0);var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}var o=u[n]={exports:{}};a[n][0].call(o.exports,function(e){var t=a[n][1][e];return s(t||e)},o,o.exports,i,a,u,c)}return u[n].exports}for(var f=l,e=0;e<c.length;e++)s(c[e]);return s}({1:[function(e,f,t){(function(t){var n,r,e=t.MutationObserver||t.WebKitMutationObserver;if(e){var o=0,i=new e(s),a=t.document.createTextNode("");i.observe(a,{characterData:!0}),n=function(){a.data=o=++o%2}}else if(t.setImmediate||void 0===t.MessageChannel)n="document"in t&&"onreadystatechange"in t.document.createElement("script")?function(){var e=t.document.createElement("script");e.onreadystatechange=function(){s(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},t.document.documentElement.appendChild(e)}:function(){setTimeout(s,0)};else{var u=new t.MessageChannel;u.port1.onmessage=s,n=function(){u.port2.postMessage(0)}}var c=[];function s(){var e,t;r=!0;for(var n=c.length;n;){for(t=c,c=[],e=-1;++e<n;)t[e]();n=c.length}r=!1}f.exports=function(e){1!==c.push(e)||r||n()}}).call(this,void 0!==r?r:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){var o=e(1);function s(){}var f={},i=["REJECTED"],a=["FULFILLED"],u=["PENDING"];function r(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=u,this.queue=[],this.outcome=void 0,e!==s&&h(this,e)}function c(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function l(t,n,r){o(function(){var e;try{e=n(r)}catch(e){return f.reject(t,e)}e===t?f.reject(t,new TypeError("Cannot resolve promise with itself")):f.resolve(t,e)})}function d(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function h(t,e){var n=!1;function r(e){n||(n=!0,f.reject(t,e))}function o(e){n||(n=!0,f.resolve(t,e))}var i=v(function(){e(o,r)});"error"===i.status&&r(i.value)}function v(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}(t.exports=r).prototype.catch=function(e){return this.then(null,e)},r.prototype.then=function(e,t){if("function"!=typeof e&&this.state===a||"function"!=typeof t&&this.state===i)return this;var n=new this.constructor(s);if(this.state!==u){var r=this.state===a?e:t;l(n,r,this.outcome)}else this.queue.push(new c(n,e,t));return n},c.prototype.callFulfilled=function(e){f.resolve(this.promise,e)},c.prototype.otherCallFulfilled=function(e){l(this.promise,this.onFulfilled,e)},c.prototype.callRejected=function(e){f.reject(this.promise,e)},c.prototype.otherCallRejected=function(e){l(this.promise,this.onRejected,e)},f.resolve=function(e,t){var n=v(d,t);if("error"===n.status)return f.reject(e,n.value);var r=n.value;if(r)h(e,r);else{e.state=a,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},f.reject=function(e,t){e.state=i,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},r.resolve=function(e){return e instanceof this?e:f.resolve(new this(s),e)},r.reject=function(e){var t=new this(s);return f.reject(t,e)},r.all=function(e){var n=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var r=e.length,o=!1;if(!r)return this.resolve([]);for(var i=new Array(r),a=0,t=-1,u=new this(s);++t<r;)c(e[t],t);return u;function c(e,t){n.resolve(e).then(function(e){i[t]=e,++a!==r||o||(o=!0,f.resolve(u,i))},function(e){o||(o=!0,f.reject(u,e))})}},r.race=function(e){if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var t=e.length,n=!1;if(!t)return this.resolve([]);for(var r,o=-1,i=new this(s);++o<t;)r=e[o],this.resolve(r).then(function(e){n||(n=!0,f.resolve(i,e))},function(e){n||(n=!0,f.reject(i,e))});return i}},{1:1}],3:[function(t,e,n){(function(e){"function"!=typeof e.Promise&&(e.Promise=t(2))}).call(this,void 0!==r?r:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{2:2}],4:[function(e,t,n){var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=function(){try{if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof webkitIndexedDB)return webkitIndexedDB;if("undefined"!=typeof mozIndexedDB)return mozIndexedDB;if("undefined"!=typeof OIndexedDB)return OIndexedDB;if("undefined"!=typeof msIndexedDB)return msIndexedDB}catch(e){return}}();function s(t,n){t=t||[],n=n||{};try{return new Blob(t,n)}catch(e){if("TypeError"!==e.name)throw e;for(var r="undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder,o=new r,i=0;i<t.length;i+=1)o.append(t[i]);return o.getBlob(n.type)}}"undefined"==typeof Promise&&e(3);var l=Promise;function d(e,t){t&&e.then(function(e){t(null,e)},function(e){t(e)})}function h(e,t,n){"function"==typeof t&&e.then(t),"function"==typeof n&&e.catch(n)}function v(e){return"string"!=typeof e&&(console.warn(e+" used as a key, but it is not a string."),e=String(e)),e}function i(){if(arguments.length&&"function"==typeof arguments[arguments.length-1])return arguments[arguments.length-1]}var f="local-forage-detect-blob-support",o=void 0,p={},y=Object.prototype.toString,b="readonly",m="readwrite";function g(e){var t=p[e.name],n={};n.promise=new l(function(e,t){n.resolve=e,n.reject=t}),t.deferredOperations.push(n),t.dbReady?t.dbReady=t.dbReady.then(function(){return n.promise}):t.dbReady=n.promise}function w(e){var t=p[e.name],n=t.deferredOperations.pop();if(n)return n.resolve(),n.promise}function _(e,t){var n=p[e.name],r=n.deferredOperations.pop();if(r)return r.reject(t),r.promise}function a(o,i){return new l(function(e,t){if(p[o.name]=p[o.name]||{forages:[],db:null,dbReady:null,deferredOperations:[]},o.db){if(!i)return e(o.db);g(o),o.db.close()}var n=[o.name];i&&n.push(o.version);var r=c.open.apply(c,n);i&&(r.onupgradeneeded=function(e){var t=r.result;try{t.createObjectStore(o.storeName),e.oldVersion<=1&&t.createObjectStore(f)}catch(t){if("ConstraintError"!==t.name)throw t;console.warn('The database "'+o.name+'" has been upgraded from version '+e.oldVersion+" to version "+e.newVersion+', but the storage "'+o.storeName+'" already exists.')}}),r.onerror=function(e){e.preventDefault(),t(r.error)},r.onsuccess=function(){e(r.result),w(o)}})}function I(e){return a(e,!1)}function S(e){return a(e,!0)}function E(e,t){if(!e.db)return!0;var n=!e.db.objectStoreNames.contains(e.storeName),r=e.version<e.db.version,o=e.version>e.db.version;if(r&&(e.version!==t&&console.warn('The database "'+e.name+"\" can't be downgraded from version "+e.db.version+" to version "+e.version+"."),e.version=e.db.version),o||n){if(n){var i=e.db.version+1;i>e.version&&(e.version=i)}return!0}return!1}function x(e){var t=function(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=0;o<t;o++)r[o]=e.charCodeAt(o);return n}(atob(e.data));return s([t],{type:e.type})}function k(e){return e&&e.__local_forage_encoded_blob}function j(e){var t=this,n=t._initReady().then(function(){var e=p[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady});return h(n,e,e),n}function N(e,t,n,r){void 0===r&&(r=1);try{var o=e.db.transaction(e.storeName,t);n(null,o)}catch(o){if(0<r&&(!e.db||"InvalidStateError"===o.name||"NotFoundError"===o.name))return l.resolve().then(function(){if(!e.db||"NotFoundError"===o.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),S(e)}).then(function(){return function(n){g(n);for(var r=p[n.name],o=r.forages,e=0;e<o.length;e++){var t=o[e];t._dbInfo.db&&(t._dbInfo.db.close(),t._dbInfo.db=null)}return n.db=null,I(n).then(function(e){return n.db=e,E(n)?S(n):e}).then(function(e){n.db=r.db=e;for(var t=0;t<o.length;t++)o[t]._dbInfo.db=e}).catch(function(e){throw _(n,e),e})}(e).then(function(){N(e,t,n,r-1)})}).catch(n);n(o)}}var u={_driver:"asyncStorage",_initStorage:function(e){var r=this,o={db:null};if(e)for(var t in e)o[t]=e[t];var i=p[o.name];i||(i={forages:[],db:null,dbReady:null,deferredOperations:[]},p[o.name]=i),i.forages.push(r),r._initReady||(r._initReady=r.ready,r.ready=j);var n=[];function a(){return l.resolve()}for(var u=0;u<i.forages.length;u++){var c=i.forages[u];c!==r&&n.push(c._initReady().catch(a))}var s=i.forages.slice(0);return l.all(n).then(function(){return o.db=i.db,I(o)}).then(function(e){return o.db=e,E(o,r._defaultConfig.version)?S(o):e}).then(function(e){o.db=i.db=e,r._dbInfo=o;for(var t=0;t<s.length;t++){var n=s[t];n!==r&&(n._dbInfo.db=o.db,n._dbInfo.version=o.version)}})},_support:function(){try{if(!c)return!1;var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),t="function"==typeof fetch&&-1!==fetch.toString().indexOf("[native code");return(!e||t)&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}}(),iterate:function(u,e){var c=this,t=new l(function(i,a){c.ready().then(function(){N(c._dbInfo,b,function(e,t){if(e)return a(e);try{var n=t.objectStore(c._dbInfo.storeName),r=n.openCursor(),o=1;r.onsuccess=function(){var e=r.result;if(e){var t=e.value;k(t)&&(t=x(t));var n=u(t,e.key,o++);void 0!==n?i(n):e.continue()}else i()},r.onerror=function(){a(r.error)}}catch(e){a(e)}})}).catch(a)});return d(t,e),t},getItem:function(a,e){var u=this;a=v(a);var t=new l(function(o,i){u.ready().then(function(){N(u._dbInfo,b,function(e,t){if(e)return i(e);try{var n=t.objectStore(u._dbInfo.storeName),r=n.get(a);r.onsuccess=function(){var e=r.result;void 0===e&&(e=null),k(e)&&(e=x(e)),o(e)},r.onerror=function(){i(r.error)}}catch(e){i(e)}})}).catch(i)});return d(t,e),t},setItem:function(u,t,e){var c=this;u=v(u);var n=new l(function(i,a){var e;c.ready().then(function(){return e=c._dbInfo,"[object Blob]"===y.call(t)?function(e){return"boolean"==typeof o?l.resolve(o):function(r){return new l(function(n){var e=r.transaction(f,m),t=s([""]);e.objectStore(f).put(t,"key"),e.onabort=function(e){e.preventDefault(),e.stopPropagation(),n(!1)},e.oncomplete=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),t=navigator.userAgent.match(/Edge\//);n(t||!e||43<=parseInt(e[1],10))}}).catch(function(){return!1})}(e).then(function(e){return o=e})}(e.db).then(function(e){return e?t:(r=t,new l(function(n,e){var t=new FileReader;t.onerror=e,t.onloadend=function(e){var t=btoa(e.target.result||"");n({__local_forage_encoded_blob:!0,data:t,type:r.type})},t.readAsBinaryString(r)}));var r}):t}).then(function(o){N(c._dbInfo,m,function(e,t){if(e)return a(e);try{var n=t.objectStore(c._dbInfo.storeName);null===o&&(o=void 0);var r=n.put(o,u);t.oncomplete=function(){void 0===o&&(o=null),i(o)},t.onabort=t.onerror=function(){var e=r.error?r.error:r.transaction.error;a(e)}}catch(e){a(e)}})}).catch(a)});return d(n,e),n},removeItem:function(a,e){var u=this;a=v(a);var t=new l(function(o,i){u.ready().then(function(){N(u._dbInfo,m,function(e,t){if(e)return i(e);try{var n=t.objectStore(u._dbInfo.storeName),r=n.delete(a);t.oncomplete=function(){o()},t.onerror=function(){i(r.error)},t.onabort=function(){var e=r.error?r.error:r.transaction.error;i(e)}}catch(e){i(e)}})}).catch(i)});return d(t,e),t},clear:function(e){var a=this,t=new l(function(o,i){a.ready().then(function(){N(a._dbInfo,m,function(e,t){if(e)return i(e);try{var n=t.objectStore(a._dbInfo.storeName),r=n.clear();t.oncomplete=function(){o()},t.onabort=t.onerror=function(){var e=r.error?r.error:r.transaction.error;i(e)}}catch(e){i(e)}})}).catch(i)});return d(t,e),t},length:function(e){var a=this,t=new l(function(o,i){a.ready().then(function(){N(a._dbInfo,b,function(e,t){if(e)return i(e);try{var n=t.objectStore(a._dbInfo.storeName),r=n.count();r.onsuccess=function(){o(r.result)},r.onerror=function(){i(r.error)}}catch(e){i(e)}})}).catch(i)});return d(t,e),t},key:function(u,e){var c=this,t=new l(function(i,a){u<0?i(null):c.ready().then(function(){N(c._dbInfo,b,function(e,t){if(e)return a(e);try{var n=t.objectStore(c._dbInfo.storeName),r=!1,o=n.openCursor();o.onsuccess=function(){var e=o.result;e?0===u?i(e.key):r?i(e.key):(r=!0,e.advance(u)):i(null)},o.onerror=function(){a(o.error)}}catch(e){a(e)}})}).catch(a)});return d(t,e),t},keys:function(e){var u=this,t=new l(function(i,a){u.ready().then(function(){N(u._dbInfo,b,function(e,t){if(e)return a(e);try{var n=t.objectStore(u._dbInfo.storeName),r=n.openCursor(),o=[];r.onsuccess=function(){var e=r.result;e?(o.push(e.key),e.continue()):i(o)},r.onerror=function(){a(r.error)}}catch(e){a(e)}})}).catch(a)});return d(t,e),t},dropInstance:function(u,e){e=i.apply(this,arguments);var t,n=this.config();if((u="function"!=typeof u&&u||{}).name||(u.name=u.name||n.name,u.storeName=u.storeName||n.storeName),u.name){var r=u.name===n.name&&this._dbInfo.db,o=r?l.resolve(this._dbInfo.db):I(u).then(function(e){var t=p[u.name],n=t.forages;t.db=e;for(var r=0;r<n.length;r++)n[r]._dbInfo.db=e;return e});t=u.storeName?o.then(function(e){if(e.objectStoreNames.contains(u.storeName)){var o=e.version+1;g(u);var r=p[u.name],i=r.forages;e.close();for(var t=0;t<i.length;t++){var n=i[t];n._dbInfo.db=null,n._dbInfo.version=o}var a=new l(function(t,n){var r=c.open(u.name,o);r.onerror=function(e){var t=r.result;t.close(),n(e)},r.onupgradeneeded=function(){var e=r.result;e.deleteObjectStore(u.storeName)},r.onsuccess=function(){var e=r.result;e.close(),t(e)}});return a.then(function(e){r.db=e;for(var t=0;t<i.length;t++){var n=i[t];n._dbInfo.db=e,w(n._dbInfo)}}).catch(function(e){throw(_(u,e)||l.resolve()).catch(function(){}),e})}}):o.then(function(e){g(u);var r=p[u.name],o=r.forages;e.close();for(var t=0;t<o.length;t++){var n=o[t];n._dbInfo.db=null}var i=new l(function(t,n){var r=c.deleteDatabase(u.name);r.onerror=r.onblocked=function(e){var t=r.result;t&&t.close(),n(e)},r.onsuccess=function(){var e=r.result;e&&e.close(),t(e)}});return i.then(function(e){r.db=e;for(var t=0;t<o.length;t++){var n=o[t];w(n._dbInfo)}}).catch(function(e){throw(_(u,e)||l.resolve()).catch(function(){}),e})})}else t=l.reject("Invalid arguments");return d(t,e),t}},O="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",A=/^~~local_forage_type~([^~]+)~/,D="__lfsc__:",L=D.length,R="arbf",T="blob",C=L+R.length,B=Object.prototype.toString;function P(e){var t,n,r,o,i,a=.75*e.length,u=e.length,c=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var s=new ArrayBuffer(a),f=new Uint8Array(s);for(t=0;t<u;t+=4)n=O.indexOf(e[t]),r=O.indexOf(e[t+1]),o=O.indexOf(e[t+2]),i=O.indexOf(e[t+3]),f[c++]=n<<2|r>>4,f[c++]=(15&r)<<4|o>>2,f[c++]=(3&o)<<6|63&i;return s}function F(e){var t,n=new Uint8Array(e),r="";for(t=0;t<n.length;t+=3)r+=O[n[t]>>2],r+=O[(3&n[t])<<4|n[t+1]>>4],r+=O[(15&n[t+1])<<2|n[t+2]>>6],r+=O[63&n[t+2]];return n.length%3==2?r=r.substring(0,r.length-1)+"=":n.length%3==1&&(r=r.substring(0,r.length-2)+"=="),r}var z={serialize:function(t,n){var e="";if(t&&(e=B.call(t)),t&&("[object ArrayBuffer]"===e||t.buffer&&"[object ArrayBuffer]"===B.call(t.buffer))){var r,o=D;t instanceof ArrayBuffer?(r=t,o+=R):(r=t.buffer,"[object Int8Array]"===e?o+="si08":"[object Uint8Array]"===e?o+="ui08":"[object Uint8ClampedArray]"===e?o+="uic8":"[object Int16Array]"===e?o+="si16":"[object Uint16Array]"===e?o+="ur16":"[object Int32Array]"===e?o+="si32":"[object Uint32Array]"===e?o+="ui32":"[object Float32Array]"===e?o+="fl32":"[object Float64Array]"===e?o+="fl64":n(new Error("Failed to get type for BinaryArray"))),n(o+F(r))}else if("[object Blob]"===e){var i=new FileReader;i.onload=function(){var e="~~local_forage_type~"+t.type+"~"+F(this.result);n(D+T+e)},i.readAsArrayBuffer(t)}else try{n(JSON.stringify(t))}catch(e){console.error("Couldn't convert value into a JSON string: ",t),n(null,e)}},deserialize:function(e){if(e.substring(0,L)!==D)return JSON.parse(e);var t,n=e.substring(C),r=e.substring(L,C);if(r===T&&A.test(n)){var o=n.match(A);t=o[1],n=n.substring(o[0].length)}var i=P(n);switch(r){case R:return i;case T:return s([i],{type:t});case"si08":return new Int8Array(i);case"ui08":return new Uint8Array(i);case"uic8":return new Uint8ClampedArray(i);case"si16":return new Int16Array(i);case"ur16":return new Uint16Array(i);case"si32":return new Int32Array(i);case"ui32":return new Uint32Array(i);case"fl32":return new Float32Array(i);case"fl64":return new Float64Array(i);default:throw new Error("Unkown type: "+r)}},stringToBuffer:P,bufferToString:F};function M(e,t,n,r){e.executeSql("CREATE TABLE IF NOT EXISTS "+t.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],n,r)}function U(e,r,o,i,a,u){e.executeSql(o,i,a,function(e,n){n.code===n.SYNTAX_ERR?e.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[r.storeName],function(e,t){t.rows.length?u(e,n):M(e,r,function(){e.executeSql(o,i,a,u)},u)},u):u(e,n)},u)}var q={_driver:"webSQLStorage",_initStorage:function(e){var r=this,o={db:null};if(e)for(var t in e)o[t]="string"!=typeof e[t]?e[t].toString():e[t];var n=new l(function(t,n){try{o.db=openDatabase(o.name,String(o.version),o.description,o.size)}catch(e){return n(e)}o.db.transaction(function(e){M(e,o,function(){r._dbInfo=o,t()},function(e,t){n(t)})},n)});return o.serializer=z,n},_support:"function"==typeof openDatabase,iterate:function(s,e){var t=this,n=new l(function(c,n){t.ready().then(function(){var u=t._dbInfo;u.db.transaction(function(e){U(e,u,"SELECT * FROM "+u.storeName,[],function(e,t){for(var n=t.rows,r=n.length,o=0;o<r;o++){var i=n.item(o),a=i.value;if(a&&(a=u.serializer.deserialize(a)),void 0!==(a=s(a,i.key,o+1)))return void c(a)}c()},function(e,t){n(t)})})}).catch(n)});return d(n,e),n},getItem:function(t,e){var i=this;t=v(t);var n=new l(function(o,n){i.ready().then(function(){var r=i._dbInfo;r.db.transaction(function(e){U(e,r,"SELECT * FROM "+r.storeName+" WHERE key = ? LIMIT 1",[t],function(e,t){var n=t.rows.length?t.rows.item(0).value:null;n&&(n=r.serializer.deserialize(n)),o(n)},function(e,t){n(t)})})}).catch(n)});return d(n,e),n},setItem:function(e,t,n){return function a(u,e,c,s){var f=this;u=v(u);var t=new l(function(o,i){f.ready().then(function(){void 0===e&&(e=null);var n=e,r=f._dbInfo;r.serializer.serialize(e,function(t,e){e?i(e):r.db.transaction(function(e){U(e,r,"INSERT OR REPLACE INTO "+r.storeName+" (key, value) VALUES (?, ?)",[u,t],function(){o(n)},function(e,t){i(t)})},function(e){if(e.code===e.QUOTA_ERR){if(0<s)return void o(a.apply(f,[u,n,c,s-1]));i(e)}})})}).catch(i)});return d(t,c),t}.apply(this,[e,t,n,1])},removeItem:function(o,e){var i=this;o=v(o);var t=new l(function(n,r){i.ready().then(function(){var t=i._dbInfo;t.db.transaction(function(e){U(e,t,"DELETE FROM "+t.storeName+" WHERE key = ?",[o],function(){n()},function(e,t){r(t)})})}).catch(r)});return d(t,e),t},clear:function(e){var o=this,t=new l(function(n,r){o.ready().then(function(){var t=o._dbInfo;t.db.transaction(function(e){U(e,t,"DELETE FROM "+t.storeName,[],function(){n()},function(e,t){r(t)})})}).catch(r)});return d(t,e),t},length:function(e){var o=this,t=new l(function(r,n){o.ready().then(function(){var t=o._dbInfo;t.db.transaction(function(e){U(e,t,"SELECT COUNT(key) as c FROM "+t.storeName,[],function(e,t){var n=t.rows.item(0).c;r(n)},function(e,t){n(t)})})}).catch(n)});return d(t,e),t},key:function(o,e){var i=this,t=new l(function(r,n){i.ready().then(function(){var t=i._dbInfo;t.db.transaction(function(e){U(e,t,"SELECT key FROM "+t.storeName+" WHERE id = ? LIMIT 1",[o+1],function(e,t){var n=t.rows.length?t.rows.item(0).key:null;r(n)},function(e,t){n(t)})})}).catch(n)});return d(t,e),t},keys:function(e){var r=this,t=new l(function(o,n){r.ready().then(function(){var t=r._dbInfo;t.db.transaction(function(e){U(e,t,"SELECT key FROM "+t.storeName,[],function(e,t){for(var n=[],r=0;r<t.rows.length;r++)n.push(t.rows.item(r).key);o(n)},function(e,t){n(t)})})}).catch(n)});return d(t,e),t},dropInstance:function(n,e){e=i.apply(this,arguments);var r=this.config();(n="function"!=typeof n&&n||{}).name||(n.name=n.name||r.name,n.storeName=n.storeName||r.storeName);var t,o=this;return d(t=n.name?new l(function(e){var t,i;t=n.name===r.name?o._dbInfo.db:openDatabase(n.name,"","",0),n.storeName?e({db:t,storeNames:[n.storeName]}):e((i=t,new l(function(o,n){i.transaction(function(e){e.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'",[],function(e,t){for(var n=[],r=0;r<t.rows.length;r++)n.push(t.rows.item(r).name);o({db:i,storeNames:n})},function(e,t){n(t)})},function(e){n(e)})})))}).then(function(u){return new l(function(i,a){u.db.transaction(function(r){function e(t){return new l(function(e,n){r.executeSql("DROP TABLE IF EXISTS "+t,[],function(){e()},function(e,t){n(t)})})}for(var t=[],n=0,o=u.storeNames.length;n<o;n++)t.push(e(u.storeNames[n]));l.all(t).then(function(){i()}).catch(function(e){a(e)})},function(e){a(e)})})}):l.reject("Invalid arguments"),e),t}};function W(e,t){var n=e.name+"/";return e.storeName!==t.storeName&&(n+=e.storeName+"/"),n}var G={_driver:"localStorageWrapper",_initStorage:function(e){var t={};if(e)for(var n in e)t[n]=e[n];return t.keyPrefix=W(e,this._defaultConfig),!function(){var e="_localforage_support_test";try{return localStorage.setItem(e,!0),localStorage.removeItem(e),!1}catch(e){return!0}}()||0<localStorage.length?((this._dbInfo=t).serializer=z,l.resolve()):l.reject()},_support:function(){try{return"undefined"!=typeof localStorage&&"setItem"in localStorage&&!!localStorage.setItem}catch(e){return!1}}(),iterate:function(c,e){var s=this,t=s.ready().then(function(){for(var e=s._dbInfo,t=e.keyPrefix,n=t.length,r=localStorage.length,o=1,i=0;i<r;i++){var a=localStorage.key(i);if(0===a.indexOf(t)){var u=localStorage.getItem(a);if(u&&(u=e.serializer.deserialize(u)),void 0!==(u=c(u,a.substring(n),o++)))return u}}});return d(t,e),t},getItem:function(n,e){var r=this;n=v(n);var t=r.ready().then(function(){var e=r._dbInfo,t=localStorage.getItem(e.keyPrefix+n);return t&&(t=e.serializer.deserialize(t)),t});return d(t,e),t},setItem:function(a,e,t){var u=this;a=v(a);var n=u.ready().then(function(){void 0===e&&(e=null);var i=e;return new l(function(n,r){var o=u._dbInfo;o.serializer.serialize(e,function(e,t){if(t)r(t);else try{localStorage.setItem(o.keyPrefix+a,e),n(i)}catch(e){"QuotaExceededError"!==e.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==e.name||r(e),r(e)}})})});return d(n,t),n},removeItem:function(t,e){var n=this;t=v(t);var r=n.ready().then(function(){var e=n._dbInfo;localStorage.removeItem(e.keyPrefix+t)});return d(r,e),r},clear:function(e){var r=this,t=r.ready().then(function(){for(var e=r._dbInfo.keyPrefix,t=localStorage.length-1;0<=t;t--){var n=localStorage.key(t);0===n.indexOf(e)&&localStorage.removeItem(n)}});return d(t,e),t},length:function(e){var t=this.keys().then(function(e){return e.length});return d(t,e),t},key:function(n,e){var r=this,t=r.ready().then(function(){var e,t=r._dbInfo;try{e=localStorage.key(n)}catch(t){e=null}return e&&(e=e.substring(t.keyPrefix.length)),e});return d(t,e),t},keys:function(e){var i=this,t=i.ready().then(function(){for(var e=i._dbInfo,t=localStorage.length,n=[],r=0;r<t;r++){var o=localStorage.key(r);0===o.indexOf(e.keyPrefix)&&n.push(o.substring(e.keyPrefix.length))}return n});return d(t,e),t},dropInstance:function(t,e){if(e=i.apply(this,arguments),!(t="function"!=typeof t&&t||{}).name){var n=this.config();t.name=t.name||n.name,t.storeName=t.storeName||n.storeName}var r,o=this;return d(r=t.name?new l(function(e){t.storeName?e(W(t,o._defaultConfig)):e(t.name+"/")}).then(function(e){for(var t=localStorage.length-1;0<=t;t--){var n=localStorage.key(t);0===n.indexOf(e)&&localStorage.removeItem(n)}}):l.reject("Invalid arguments"),e),r}},Q=function(e,t){for(var n=e.length,r=0;r<n;){if((o=e[r])===(i=t)||"number"==typeof o&&"number"==typeof i&&isNaN(o)&&isNaN(i))return!0;r++}var o,i;return!1},J=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},X={},H={},K={INDEXEDDB:u,WEBSQL:q,LOCALSTORAGE:G},Y=[K.INDEXEDDB._driver,K.WEBSQL._driver,K.LOCALSTORAGE._driver],V=["dropInstance"],Z=["clear","getItem","iterate","key","keys","length","removeItem","setItem"].concat(V),$={description:"",driver:Y.slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1};function ee(t,n){t[n]=function(){var e=arguments;return t.ready().then(function(){return t[n].apply(t,e)})}}function te(){for(var e=1;e<arguments.length;e++){var t=arguments[e];if(t)for(var n in t)t.hasOwnProperty(n)&&(J(t[n])?arguments[0][n]=t[n].slice():arguments[0][n]=t[n])}return arguments[0]}var ne=function(){function o(e){for(var t in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),K)if(K.hasOwnProperty(t)){var n=K[t],r=n._driver;this[t]=r,X[r]||this.defineDriver(n)}this._defaultConfig=te({},$),this._config=te({},this._defaultConfig,e),this._driverSet=null,this._initDriver=null,this._ready=!1,this._dbInfo=null,this._wrapLibraryMethodsWithReady(),this.setDriver(this._config.driver).catch(function(){})}return o.prototype.config=function(e){if("object"!==(void 0===e?"undefined":r(e)))return"string"==typeof e?this._config[e]:this._config;if(this._ready)return new Error("Can't call config() after localforage has been used.");for(var t in e){if("storeName"===t&&(e[t]=e[t].replace(/\W/g,"_")),"version"===t&&"number"!=typeof e[t])return new Error("Database version must be a number.");this._config[t]=e[t]}return!("driver"in e&&e.driver)||this.setDriver(this._config.driver)},o.prototype.defineDriver=function(f,e,t){var n=new l(function(t,e){try{var n=f._driver,r=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!f._driver)return void e(r);for(var o=Z.concat("_initStorage"),i=0,a=o.length;i<a;i++){var u=o[i],c=!Q(V,u);if((c||f[u])&&"function"!=typeof f[u])return void e(r)}!function(){for(var e=function(n){return function(){var e=new Error("Method "+n+" is not implemented by the current driver"),t=l.reject(e);return d(t,arguments[arguments.length-1]),t}},t=0,n=V.length;t<n;t++){var r=V[t];f[r]||(f[r]=e(r))}}();var s=function(e){X[n]&&console.info("Redefining LocalForage driver: "+n),X[n]=f,H[n]=e,t()};"_support"in f?f._support&&"function"==typeof f._support?f._support().then(s,e):s(!!f._support):s(!0)}catch(r){e(r)}});return h(n,e,t),n},o.prototype.driver=function(){return this._driver||null},o.prototype.getDriver=function(e,t,n){var r=X[e]?l.resolve(X[e]):l.reject(new Error("Driver not found."));return h(r,t,n),r},o.prototype.getSerializer=function(e){var t=l.resolve(z);return h(t,e),t},o.prototype.ready=function(e){var t=this,n=t._driverSet.then(function(){return null===t._ready&&(t._ready=t._initDriver()),t._ready});return h(n,e,e),n},o.prototype.setDriver=function(e,t,n){var i=this;J(e)||(e=[e]);var r=this._getSupportedDrivers(e);function a(){i._config.driver=i.driver()}function u(e){return i._extend(e),a(),i._ready=i._initStorage(i._config),i._ready}var o=null!==this._driverSet?this._driverSet.catch(function(){return l.resolve()}):l.resolve();return this._driverSet=o.then(function(){var e=r[0];return i._dbInfo=null,i._ready=null,i.getDriver(e).then(function(e){i._driver=e._driver,a(),i._wrapLibraryMethodsWithReady(),i._initDriver=function(o){return function(){var r=0;return function e(){for(;r<o.length;){var t=o[r];return r++,i._dbInfo=null,i._ready=null,i.getDriver(t).then(u).catch(e)}a();var n=new Error("No available storage method found.");return i._driverSet=l.reject(n),i._driverSet}()}}(r)})}).catch(function(){a();var e=new Error("No available storage method found.");return i._driverSet=l.reject(e),i._driverSet}),h(this._driverSet,t,n),this._driverSet},o.prototype.supports=function(e){return!!H[e]},o.prototype._extend=function(e){te(this,e)},o.prototype._getSupportedDrivers=function(e){for(var t=[],n=0,r=e.length;n<r;n++){var o=e[n];this.supports(o)&&t.push(o)}return t},o.prototype._wrapLibraryMethodsWithReady=function(){for(var e=0,t=Z.length;e<t;e++)ee(this,Z[e])},o.prototype.createInstance=function(e){return new o(e)},o}(),re=new ne;t.exports=re},{3:3}]},{},[4])(4)});function p(t){return Object.keys(t).map(function(e){return"".concat(e,"=").concat(window.encodeURIComponent(t[e]||""))}).join("&")}function y(e,t,n){if(!e)throw n&&n(),new Error("Danmuku Error: ".concat(t))}return function(){function t(e){(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")})(this,t),this.options=Object.assign({},t.DEFAULT,e),this.db=v.createInstance({driver:[v.WEBSQL,v.INDEXEDDB,v.LOCALSTORAGE],name:"danmuku-db"}),this.limit=0,this.remaining=0,this.init()}var e,n,r,o,i,a;return function(e,t,n){t&&h(e.prototype,t),n&&h(e,n)}(t,[{key:"init",value:(a=d(s.mark(function e(){var t,n,r,o,i,a;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=(window.location.href.match(/([^?=&]+)(=([^&]*))/g)||[]).reduce(function(e,t){return e[t.slice(0,t.indexOf("="))]=t.slice(t.indexOf("=")+1),e},{}),n=t.code)return e.next=4,this.getToken(n);e.next=19;break;case 4:return y((r=e.sent).access_token,"Can not get token, Please login again!"),e.next=8,this.db.setItem("token",r.access_token);case 8:return e.next=10,this.getUserInfo(r.access_token);case 10:return y((o=e.sent).id,"Can not get user info, Please login again!"),e.next=14,this.db.setItem("userInfo",o);case 14:return e.next=16,this.db.getItem("redirect_uri");case 16:y(i=e.sent,"Can not get redirect url, Please login again!"),window.history.replaceState(null,"",i);case 19:return e.next=21,this.db.getItem("userInfo");case 21:return this.userInfo=e.sent,e.next=24,this.db.getItem("token");case 24:return this.token=e.sent,e.next=27,this.db.getItem("danmus");case 27:if(a=e.sent,this.isLogin=!!this.userInfo&&!!this.token,this.isLogin&&!a)return e.next=32,this.cache();e.next=32;break;case 32:case"end":return e.stop()}},e,this)})),function(){return a.apply(this,arguments)})},{key:"login",value:(i=d(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.db.clear();case 2:return e.next=4,this.db.setItem("redirect_uri",window.location.href);case 4:return e.next=6,this.db.setItem("login_time",Date.now());case 6:window.location.href="http://github.com/login/oauth/authorize?".concat(p({state:"issues-danmuku",client_id:this.options.clientID,redirect_uri:window.location.href,scope:"public_repo"}));case 7:case"end":return e.stop()}},e,this)})),function(){return i.apply(this,arguments)})},{key:"logout",value:(o=d(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.db.clear();case 2:window.location.reload();case 3:case"end":return e.stop()}},e,this)})),function(){return o.apply(this,arguments)})},{key:"request",value:(r=d(s.mark(function e(t,n,r){var o,i;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=t.toUpperCase(),r=r&&JSON.stringify(r),o={"Content-Type":"application/json",Accept:"application/json"},this.token&&(o.Authorization="token ".concat(this.token)),e.prev=4,e.next=7,fetch(n,{method:t,headers:o,body:r});case 7:if(404===(i=e.sent).status)return e.abrupt("return",Promise.reject("Unauthorized."));e.next=12;break;case 12:if(401===i.status)return e.next=15,this.db.clear();e.next=18;break;case 15:return e.abrupt("return",window.location.reload());case 18:return this.limit=Number(i.headers.get("X-RateLimit-Limit")),this.remaining=Number(i.headers.get("X-RateLimit-Remaining")),e.abrupt("return",i.json());case 21:e.next=26;break;case 23:e.prev=23,e.t0=e.catch(4),console.warn(e.t0,n);case 26:case"end":return e.stop()}},e,this,[[4,23]])})),function(e,t,n){return r.apply(this,arguments)})},{key:"urlQuery",value:function(e){return c({client_id:this.options.clientID,client_secret:this.options.clientSecret,t:Date.now()},e)}},{key:"getToken",value:function(e){var t=this.urlQuery({code:e,redirect_uri:location.href});return this.request("get","".concat(this.options.proxy,"?").concat(p(t)))}},{key:"getUserInfo",value:function(e){return this.request("get","https://api.github.com/user?access_token=".concat(e))}},{key:"cache",value:(n=d(s.mark(function e(){var t,n,r,o;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=[],n=1,e.next=4,this.db.setItem("cache_time",Date.now());case 4:return e.next=7,this.request("get","https://api.github.com/repos/".concat(this.options.api,"/comments?").concat(p(this.urlQuery({per_page:this.options.perPage,page:n++}))));case 7:if(r=e.sent,y(Array.isArray(r),"Can not get the danmuku, Please try again!"),t=[].concat(u(t),u(r)),r.length<this.options.perPage)return o=t.map(function(e){var t=JSON.parse(e.body);return c({id:e.id},t)}),e.abrupt("return",this.db.setItem("danmus",o));e.next=13;break;case 13:e.next=4;break;case 15:case"end":return e.stop()}},e,this)})),function(){return n.apply(this,arguments)})},{key:"send",value:(e=d(s.mark(function e(){var t,n,r,o=arguments;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=0<o.length&&void 0!==o[0]?o[0]:{},n=this.urlQuery({body:JSON.stringify(t)}),e.next=4,this.request("post","https://api.github.com/repos/".concat(this.options.api,"/comments"),n);case 4:return y((r=e.sent).id,"Can not send the danmu, Please try again!"),e.abrupt("return",JSON.parse(r.body));case 7:case"end":return e.stop()}},e,this)})),function(){return e.apply(this,arguments)})}],[{key:"DEFAULT",get:function(){return{api:"",clientID:"",clientSecret:"",perPage:100,proxy:"https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token"}}}]),t}()}()}(e={exports:{}},e.exports),e.exports);return window.ArtplayerToolGithub=t});
|