diff --git a/ede.js b/ede.js index b60d03e..adc6bbe 100644 --- a/ede.js +++ b/ede.js @@ -24,9 +24,11 @@ return; } // ------ configs start------ - let isInTampermonkey = true; + const isInTampermonkey = !(typeof GM_xmlhttpRequest === 'undefined'); const corsProxy = 'https://ddplay-api.930524.xyz/cors/'; - let apiPrefix = ''; + const apiPrefix = isInTampermonkey ? 'https://api.dandanplay.net' : corsProxy + 'https://api.dandanplay.net'; + // const apiPrefix = 'https://api.930524.xyz'; + const authPrefix = corsProxy + 'https://api.dandanplay.net'; // 在Worker上计算Hash let ddplayStatus = JSON.parse(localStorage.getItem('ddplayStatus')) || { isLogin: false, token: '', tokenExpire: 0 }; const check_interval = 200; // 0:当前状态关闭 1:当前状态打开 @@ -422,11 +424,6 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Danmaku=e()}(this,(function(){"use strict";var t=function(){if("undefined"==typeof document)return"transform";for(var t=["oTransform","msTransform","mozTransform","webkitTransform","transform"],e=document.createElement("div").style,i=0;i0&&a!==1/0?Math.ceil(a):1*!!o.strokeStyle,h.font=o.font,t.width=t.width||Math.max(1,Math.ceil(h.measureText(t.text).width)+2*a),t.height=t.height||Math.ceil(function(t,e){if(s[t])return s[t];var i=12,n=t.match(/(\d+(?:\.\d+)?)(px|%|em|rem)(?:\s*\/\s*(\d+(?:\.\d+)?)(px|%|em|rem)?)?/);if(n){var r=1*n[1]||10,h=n[2],o=1*n[3]||1.2,a=n[4];"%"===h&&(r*=e.container/100),"em"===h&&(r*=e.container),"rem"===h&&(r*=e.root),"px"===a&&(i=o),"%"===a&&(i=r*o/100),"em"===a&&(i=r*o),"rem"===a&&(i=e.root*o),void 0===a&&(i=r*o)}return s[t]=i,i}(o.font,e))+2*a,r.width=t.width*n,r.height=t.height*n,h.scale(n,n),o)h[d]=o[d];var u=0;switch(o.textBaseline){case"top":case"hanging":u=a;break;case"middle":u=t.height>>1;break;default:u=t.height-a}return o.strokeStyle&&h.strokeText(t.text,a,u),h.fillText(t.text,a,u),r}function h(t){return 1*window.getComputedStyle(t,null).getPropertyValue("font-size").match(/(.+)px/)[1]}var o={name:"canvas",init:function(t){var e=document.createElement("canvas");return e.context=e.getContext("2d"),e._fontSize={root:h(document.getElementsByTagName("html")[0]),container:h(t)},e},clear:function(t,e){t.context.clearRect(0,0,t.width,t.height);for(var i=0;ir)return!0;var h=e._.duration+t.time-i,o=e._.width+s.width,a=e.media?s.time:s._utc,d=o*(i-a)*n/e._.duration,u=e._.width-d;return h>e._.duration*u/(e._.width+s.width)}for(var r=this._.space[t.mode],h=0,o=0,a=1;a=u){o=a;break}s(d,t)&&(h=a)}var m=r[h].range,c={range:m+t.height,time:this.media?t.time:t._utc,width:t.width,height:t.height};return r.splice(h+1,o-h-1,c),"bottom"===t.mode?this._.height-t.height-m%this._.height:m%(this._.height-t.height)}var d="undefined"!=typeof window&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame)||function(t){return setTimeout(t,50/3)},u="undefined"!=typeof window&&(window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame)||clearTimeout;function m(t,e,i){for(var n=0,s=0,r=t.length;s=t[n=s+r>>1][e]?s=n:r=n;return t[s]&&i=0;u--)o=this._.runningList[u],r-(d=this.media?o.time:o._utc)>this._.duration&&(n(this._.stage,o),this._.runningList.splice(u,1));for(var m=[];this._.position=r));)r-d>this._.duration||(this.media&&(o._utc=s-(this.media.currentTime-o.time)),m.push(o)),++this._.position;for(e(this._.stage,m),u=0;u>1),i(this._.stage,o)}}}(this._.engine.framing.bind(this),this._.engine.setup.bind(this),this._.engine.render.bind(this),this._.engine.remove.bind(this));return this._.requestID=d((function t(){n.call(i),i._.requestID=d(t)})),this}function g(){return!this._.visible||this._.paused||(this._.paused=!0,u(this._.requestID),this._.requestID=0),this}function _(){if(!this.media)return this;this.clear(),f(this._.space);var t=m(this.comments,"time",this.media.currentTime);return this._.position=Math.max(0,t-1),this}function v(t){t.play=p.bind(this),t.pause=g.bind(this),t.seeking=_.bind(this),this.media.addEventListener("play",t.play),this.media.addEventListener("pause",t.pause),this.media.addEventListener("playing",t.play),this.media.addEventListener("waiting",t.pause),this.media.addEventListener("seeking",t.seeking)}function w(t){this.media.removeEventListener("play",t.play),this.media.removeEventListener("pause",t.pause),this.media.removeEventListener("playing",t.play),this.media.removeEventListener("waiting",t.pause),this.media.removeEventListener("seeking",t.seeking),t.play=null,t.pause=null,t.seeking=null}function y(t){this._={},this.container=t.container||document.createElement("div"),this.media=t.media,this._.visible=!0,this.engine=(t.engine||"DOM").toLowerCase(),this._.engine="canvas"===this.engine?o:i,this._.requestID=0,this._.speed=Math.max(0,t.speed)||144,this._.duration=4,this.comments=t.comments||[],this.comments.sort((function(t,e){return t.time-e.time}));for(var e=0;e 259200) { // Token expires in more than 3 days, no need to refresh return; } else { // Refresh token before 3 days - const refreshUrl = corsProxy + 'https://api.dandanplay.net/api/v2/login/renew'; + const refreshUrl = apiPrefix + '/api/v2/login/renew'; try { const resp = await fetch(refreshUrl, { method: 'GET', @@ -671,7 +668,7 @@ alert('请先获取弹幕信息'); return; } - const danmakuUrl = corsProxy + 'https://api.dandanplay.net/api/v2/comment/' + window.ede.episode_info.episodeId; + const danmakuUrl = apiPrefix + '/api/v2/comment/' + window.ede.episode_info.episodeId; const params = { 'time': time, 'mode': mode, @@ -725,7 +722,7 @@ } async function postRelatedSource(relatedUrl) { - const url = corsProxy + 'https://api.dandanplay.net/api/v2/related/' + window.ede.episode_info.episodeId; + const url = apiPrefix + '/api/v2/related/' + window.ede.episode_info.episodeId; const params = { 'episodeId': window.ede.episode_info.episodeId, 'url': relatedUrl, @@ -879,7 +876,7 @@ } window.ede.curEpOffset = window.localStorage.getItem(_episode_key_offset) || 0; - let searchUrl = apiPrefix + 'https://api.dandanplay.net/api/v2/search/episodes?anime=' + animeName + '&withRelated=true'; + let searchUrl = apiPrefix + '/api/v2/search/episodes?anime=' + animeName + '&withRelated=true'; let animaInfo = await makeGetRequest(searchUrl) .then((response) => isInTampermonkey ? JSON.parse(response) : response.json()) .catch((error) => { @@ -890,7 +887,7 @@ const seriesInfo = await ApiClient.getItem(ApiClient.getCurrentUserId(), item.SeriesId || item.Id); animeName = seriesInfo.OriginalTitle; if (animeName.length > 0) { - searchUrl = apiPrefix + 'https://api.dandanplay.net/api/v2/search/episodes?anime=' + animeName + '&withRelated=true'; + searchUrl = apiPrefix + '/api/v2/search/episodes?anime=' + animeName + '&withRelated=true'; animaInfo = await makeGetRequest(searchUrl) .then((response) => isInTampermonkey ? JSON.parse(response) : response.json()) .catch((error) => { @@ -951,9 +948,9 @@ async function getComments(episodeId) { const { danmakuFilter } = window.ede; - const url_all = apiPrefix + 'https://api.dandanplay.net/api/v2/comment/' + episodeId + '?withRelated=true&chConvert=' + window.ede.chConvert; - const url_related = apiPrefix + 'https://api.dandanplay.net/api/v2/related/' + episodeId; - const url_ext = apiPrefix + 'https://api.dandanplay.net/api/v2/extcomment?url='; + const url_all = apiPrefix + '/api/v2/comment/' + episodeId + '?withRelated=true&chConvert=' + window.ede.chConvert; + const url_related = apiPrefix + '/api/v2/related/' + episodeId; + const url_ext = apiPrefix + '/api/v2/extcomment?url='; try { let response = await makeGetRequest(url_all); let data = isInTampermonkey ? JSON.parse(response) : await response.json(); @@ -1007,7 +1004,7 @@ async function getCommentsByUrl(src) { const url_encoded = encodeURIComponent(src); - const url = apiPrefix + 'https://api.dandanplay.net/api/v2/extcomment?url=' + url_encoded; + const url = apiPrefix + '/api/v2/extcomment?url=' + url_encoded; for (let i = 0; i < 2; i++) { try { const response = await makeGetRequest(url);