diff --git a/min/gui-settings.min.js b/min/gui-settings.min.js index b009eab594..7b57fb242b 100644 --- a/min/gui-settings.min.js +++ b/min/gui-settings.min.js @@ -1 +1 @@ -(()=>(e,t)=>{const{ThemeColors:n}=t.import("theme-colors");const{SettingsSearch:i}=t.import("settings-search");const{Validator:s}=t.import("text-validate");let o=[];let c=[];let a=[];function r(e){let t=e.nextElementSibling;const n=[];while(t!==null&&!t.classList.contains("category")){n.push(t);t=t.nextElementSibling}return n}function l(){a.forEach((t=>t.value=e[t.getAttribute("key")]));c.forEach((t=>t.checked=e[t.getAttribute("key")]))}function d(){document.querySelector(".gui-settings-mask").addEventListener("click",(()=>{document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box,.gui-settings-mask,.bilibili-evolved-about").forEach((e=>e.classList.remove("opened")))}));a.forEach((t=>{t.setAttribute("placeholder",e[t.getAttribute("key")])}));document.querySelectorAll(".gui-settings-content ul li.category").forEach((e=>{e.addEventListener("click",(e=>{const t=document.querySelector(".gui-settings-search");if(t.value!==""){t.value="";raiseEvent(t,"input")}e.currentTarget.classList.toggle("folded");r(e.currentTarget).forEach((e=>e.classList.toggle("folded")))}))}));document.querySelectorAll(".gui-settings-dropdown>input").forEach((e=>{e.addEventListener("click",(t=>{t.target.parentElement.classList.toggle("opened");const n=i=>{const s=i.target;const o=dq(`li[data-key=${e.getAttribute("key")}]`);console.log(o,e.getAttribute("key"),s);if(o.contains(s)&&o!==s){return}t.target.parentElement.classList.remove("opened");document.body.removeEventListener("click",n)};document.body.addEventListener("click",n)}))}));dqa(".gui-settings-header .operation").forEach((t=>{t.addEventListener("click",(t=>{if(t.target.classList.contains("export")){const t=document.createElement("a");t.style.display="none";const n=URL.createObjectURL(new Blob([JSON.stringify(_.omit(e,"cache"))]));t.href=n;t.download="bilibili-evolved-settings.json";document.body.insertAdjacentElement("beforeend",t);t.click();URL.revokeObjectURL(n);t.remove()}else if(t.target.classList.contains("import")){const t=document.createElement("input");t.style.display="none";t.type="file";t.accept=".json,text/json";document.body.insertAdjacentElement("beforeend",t);t.addEventListener("change",(async()=>{try{const n=t.files[0];const i=JSON.parse(await new Response(n).text());for(const[t,n]of Object.entries(i)){if(t in e&&t!=="cache"){e[t]=n}}Toast.success("已成功导入设置, 部分设置需要刷新后生效.","导入设置",3e3)}catch(e){Toast.error("选择的设置文件无效.","导入设置",3e3)}finally{t.remove()}}),{once:true});t.click()}}))}))}function u(){c.forEach((t=>{t.addEventListener("change",(()=>{const n=t.getAttribute("key");const i=t.checked;e[n]=i}))}));a.forEach((t=>{t.addEventListener("change",(()=>{const n=t.getAttribute("key");const i=s.getValidator(n).validate(t.value);e[n]=i;t.value=i}))}))}function g(){const e=o.map((e=>[e.getAttribute("dependencies").split(" ").map((e=>o.find((t=>t.getAttribute("key")===e)))),e]));const t=e=>e.nodeName.toUpperCase()==="LI"?e:t(e.parentElement);e.forEach((([e,n])=>{if(e[0]===undefined){return}const i=()=>{if(e.every((e=>e.checked))){t(n).classList.remove("disabled")}else{t(n).classList.add("disabled")}};e.forEach((e=>e.addEventListener("change",i)));i()}))}function m(){if(typeof offlineData!=="undefined"){}}const f=["playerFocus","outerWatchlater","quickFavorite"];const p=()=>{if(f.some((t=>e[t]))){f.forEach((t=>{e[t]=false}));Toast.info(`\n
为避免b站播放器改版导致网站无法正常使用, 以下功能已自动关闭并禁用:\n自动定位到播放器 外置稍后再看 启用快速收藏\n\n详情见讨论区, 这些功能将在恢复后再解除禁用.\n若当前页面是视频页面且出现问题, 刷新即可恢复正常.
\n`.trim(),"通知")}};function y(){if(window.devicePixelRatio===1){o.find((e=>e.getAttribute("key")==="harunaScale")).disabled=true;o.find((e=>e.getAttribute("key")==="imageResolution")).disabled=true;e.harunaScale=false;e.imageResolution=false}c.filter((e=>f.includes(e.getAttribute("key")))).forEach((e=>e.disabled=true))}function b(){for(const[e,t]of Object.entries(Resource.displayNames)){const n=o.find((t=>t.getAttribute("key")===e));if(!n){continue}switch(n.type){case"checkbox":n.nextElementSibling.nextElementSibling.innerHTML=t;break;case"text":const e=n.parentElement;if(e.classList.contains("gui-settings-textbox-container")){n.previousElementSibling.innerHTML=t}else if(e.classList.contains("gui-settings-dropdown")){e.previousElementSibling.innerHTML=t}break;default:break}}}(async()=>{t.applyStyle("guiSettingsStyle");t.applyImportantStyle("iconsStyle");document.body.classList.add("round-corner");const s=document.body&&unsafeWindow.parent.window!==unsafeWindow;if(s){document.querySelector(".gui-settings-icon-panel").style.display="none"}document.documentElement.classList.toggle("iframe",s);addSettingsListener("guiSettingsDockSide",(e=>{document.body.classList.toggle("gui-settings-dock-right",e==="右侧")}),true);addSettingsListener("autoHideSideBar",(e=>{document.body.classList.toggle("gui-settings-auto-hide-side-bar",e)}),true);addSettingsListener("elegantScrollbar",(e=>{document.documentElement.classList.toggle("elegant-scrollbar",e)}),true);const r=t.data.guiSettingsHtml.text;document.body.insertAdjacentHTML("beforeend",r);const{style:f}=await t.importAsync("mdi");if(!f){document.body.insertAdjacentHTML("afterbegin",``)}const h=document.querySelector(".widgets-container");const v=h.querySelector(".empty-tip");Observer.childList(h,(()=>{if(h.childElementCount<=1){v.classList.add("show")}else{v.classList.remove("show")}}));const E=document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");const L=document.querySelector(".gui-settings-icon-panel");p();L.addEventListener("mouseover",(async()=>{const{loadTooltip:s}=await t.importAsync("settings-tooltip.loader");await s();await t.applyDropdownOptions();t.applyWidgets();raiseEvent(L,"be:load");const r=dq(".bilibili-evolved-about");if(r){raiseEvent(r,"be:about-load")}(new n).setupDom();E.forEach((e=>e.classList.add("loaded")));o=[...document.querySelectorAll("input[key]")];c=o.filter((e=>e.type==="checkbox"));a=o.filter((e=>e.type==="text"&&!e.parentElement.classList.contains("gui-settings-dropdown")));d();m();l();g();u();y();b();dq(".script-info .version").textContent=scriptVersion+" v"+GM.info.script.version;(async()=>{const t=dq(".script-info .content-hash");if(Object.keys(e.cache).length===0){t.remove();return}const n=async e=>{const t=(new TextEncoder).encode(e);const n=await crypto.subtle.digest("SHA-256",t);const i=Array.from(new Uint8Array(n));const s=i.map((e=>e.toString(16).padStart(2,"0"))).join("");return s};const i=await n(JSON.stringify(e.cache));t.textContent=`内容包: ${i.substring(0,7)}`})();new i}),{once:true})})()})(); \ No newline at end of file +(()=>(e,t)=>{const{ThemeColors:n}=t.import("theme-colors");const{SettingsSearch:i}=t.import("settings-search");const{Validator:s}=t.import("text-validate");let o=[];let c=[];let a=[];function r(e){let t=e.nextElementSibling;const n=[];while(t!==null&&!t.classList.contains("category")){n.push(t);t=t.nextElementSibling}return n}function l(){a.forEach((t=>t.value=e[t.getAttribute("key")]));c.forEach((t=>t.checked=e[t.getAttribute("key")]))}function d(){document.querySelector(".gui-settings-mask").addEventListener("click",(()=>{document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box,.gui-settings-mask,.bilibili-evolved-about").forEach((e=>e.classList.remove("opened")))}));a.forEach((t=>{t.setAttribute("placeholder",e[t.getAttribute("key")])}));document.querySelectorAll(".gui-settings-content ul li.category").forEach((e=>{e.addEventListener("click",(e=>{const t=document.querySelector(".gui-settings-search");if(t.value!==""){t.value="";raiseEvent(t,"input")}e.currentTarget.classList.toggle("folded");r(e.currentTarget).forEach((e=>e.classList.toggle("folded")))}))}));document.querySelectorAll(".gui-settings-dropdown>input").forEach((e=>{e.addEventListener("click",(t=>{t.target.parentElement.classList.toggle("opened");const n=i=>{const s=i.target;const o=dq(`li[data-key=${e.getAttribute("key")}]`);console.log(o,e.getAttribute("key"),s);if(o.contains(s)&&o!==s){return}t.target.parentElement.classList.remove("opened");document.body.removeEventListener("click",n)};document.body.addEventListener("click",n)}))}));dqa(".gui-settings-header .operation").forEach((t=>{t.addEventListener("click",(t=>{if(t.target.classList.contains("export")){const t=document.createElement("a");t.style.display="none";const n=URL.createObjectURL(new Blob([JSON.stringify(_.omit(e,"cache"))]));t.href=n;t.download="bilibili-evolved-settings.json";document.body.insertAdjacentElement("beforeend",t);t.click();URL.revokeObjectURL(n);t.remove()}else if(t.target.classList.contains("import")){const t=document.createElement("input");t.style.display="none";t.type="file";t.accept=".json,text/json";document.body.insertAdjacentElement("beforeend",t);t.addEventListener("change",(async()=>{try{const n=t.files[0];const i=JSON.parse(await new Response(n).text());for(const[t,n]of Object.entries(i)){if(t in e&&t!=="cache"){e[t]=n}}Toast.success("已成功导入设置, 部分设置需要刷新后生效.","导入设置",3e3)}catch(e){Toast.error("选择的设置文件无效.","导入设置",3e3)}finally{t.remove()}}),{once:true});t.click()}}))}))}function u(){c.forEach((t=>{t.addEventListener("change",(()=>{const n=t.getAttribute("key");const i=t.checked;e[n]=i}))}));a.forEach((t=>{t.addEventListener("change",(()=>{const n=t.getAttribute("key");const i=s.getValidator(n).validate(t.value);e[n]=i;t.value=i}))}))}function g(){const e=o.map((e=>[e.getAttribute("dependencies").split(" ").map((e=>o.find((t=>t.getAttribute("key")===e)))),e]));const t=e=>e.nodeName.toUpperCase()==="LI"?e:t(e.parentElement);e.forEach((([e,n])=>{if(e[0]===undefined){return}const i=()=>{if(e.every((e=>e.checked))){t(n).classList.remove("disabled")}else{t(n).classList.add("disabled")}};e.forEach((e=>e.addEventListener("change",i)));i()}))}function m(){if(typeof offlineData!=="undefined"){}}const f=()=>{};function y(){if(window.devicePixelRatio===1){o.find((e=>e.getAttribute("key")==="harunaScale")).disabled=true;o.find((e=>e.getAttribute("key")==="imageResolution")).disabled=true;e.harunaScale=false;e.imageResolution=false}}function p(){for(const[e,t]of Object.entries(Resource.displayNames)){const n=o.find((t=>t.getAttribute("key")===e));if(!n){continue}switch(n.type){case"checkbox":n.nextElementSibling.nextElementSibling.innerHTML=t;break;case"text":const e=n.parentElement;if(e.classList.contains("gui-settings-textbox-container")){n.previousElementSibling.innerHTML=t}else if(e.classList.contains("gui-settings-dropdown")){e.previousElementSibling.innerHTML=t}break;default:break}}}(async()=>{t.applyStyle("guiSettingsStyle");t.applyImportantStyle("iconsStyle");document.body.classList.add("round-corner");const s=document.body&&unsafeWindow.parent.window!==unsafeWindow;if(s){document.querySelector(".gui-settings-icon-panel").style.display="none"}document.documentElement.classList.toggle("iframe",s);addSettingsListener("guiSettingsDockSide",(e=>{document.body.classList.toggle("gui-settings-dock-right",e==="右侧")}),true);addSettingsListener("autoHideSideBar",(e=>{document.body.classList.toggle("gui-settings-auto-hide-side-bar",e)}),true);addSettingsListener("elegantScrollbar",(e=>{document.documentElement.classList.toggle("elegant-scrollbar",e)}),true);const r=t.data.guiSettingsHtml.text;document.body.insertAdjacentHTML("beforeend",r);const{style:b}=await t.importAsync("mdi");if(!b){document.body.insertAdjacentHTML("afterbegin",``)}const h=document.querySelector(".widgets-container");const E=h.querySelector(".empty-tip");Observer.childList(h,(()=>{if(h.childElementCount<=1){E.classList.add("show")}else{E.classList.remove("show")}}));const L=document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");const v=document.querySelector(".gui-settings-icon-panel");f();v.addEventListener("mouseover",(async()=>{const{loadTooltip:s}=await t.importAsync("settings-tooltip.loader");await s();await t.applyDropdownOptions();t.applyWidgets();raiseEvent(v,"be:load");const r=dq(".bilibili-evolved-about");if(r){raiseEvent(r,"be:about-load")}(new n).setupDom();L.forEach((e=>e.classList.add("loaded")));o=[...document.querySelectorAll("input[key]")];c=o.filter((e=>e.type==="checkbox"));a=o.filter((e=>e.type==="text"&&!e.parentElement.classList.contains("gui-settings-dropdown")));d();m();l();g();u();y();p();dq(".script-info .version").textContent=scriptVersion+" v"+GM.info.script.version;(async()=>{const t=dq(".script-info .content-hash");if(Object.keys(e.cache).length===0){t.remove();return}const n=async e=>{const t=(new TextEncoder).encode(e);const n=await crypto.subtle.digest("SHA-256",t);const i=Array.from(new Uint8Array(n));const s=i.map((e=>e.toString(16).padStart(2,"0"))).join("");return s};const i=await n(JSON.stringify(e.cache));t.textContent=`内容包: ${i.substring(0,7)}`})();new i}),{once:true})})()})(); \ No newline at end of file diff --git a/min/outer-watchlater.min.js b/min/outer-watchlater.min.js index f40746b67d..d996b54450 100644 --- a/min/outer-watchlater.min.js +++ b/min/outer-watchlater.min.js @@ -1 +1 @@ -(()=>(t,e)=>{(async()=>{if(!document.URL.startsWith("https://www.bilibili.com/video/")||!getUID()){return}await playerReady();const t=dq(".video-toolbar .ops .collect");if(!t){return}e.applyStyle("outerWatchlaterStyle");t.insertAdjacentHTML("afterend",`\n\n\n 稍后再看\n
{{tipText}}
\n
\n`.trim());const i=dq(".ops .watchlater");if(!i){return}const a=new Vue({el:i,store:store,data:{aid:unsafeWindow.aid,tipText:"",tipShowing:false,tipHandle:0},computed:{...Vuex.mapState(["watchlaterList"]),isInWatchlater(){return this.watchlaterList.includes(parseInt(this.aid))}},methods:{...Vuex.mapActions(["toggleWatchlater"]),showTip(t){this.tipText=t;this.tipShowing=true;if(this.tipHandle){clearTimeout(this.tipHandle)}this.tipHandle=setTimeout((()=>{this.tipShowing=false}),2e3)},async toggle(){await this.toggleWatchlater(this.aid);this.showTip(this.isInWatchlater?"已添加至稍后再看":"已从稍后再看移除")}}});Observer.videoChange((()=>{a.aid=unsafeWindow.aid}))})();return{unload:()=>{dqa(".ops .watchlater").forEach((t=>t.style.display="none"))},reload:()=>{dqa(".ops .watchlater").forEach((t=>t.style.display="inline-block"))}}})(); \ No newline at end of file +(()=>(t,a)=>{(async()=>{if(!document.URL.startsWith("https://www.bilibili.com/video/")||!getUID()){return}const{playerReady:t}=await a.importAsync("player-ready");await t();const e=dq(".video-toolbar .ops .collect");if(!e){return}a.applyStyle("outerWatchlaterStyle");e.insertAdjacentHTML("afterend",`\n\n\n 稍后再看\n
{{tipText}}
\n
\n`.trim());const i=dq(".ops .watchlater");if(!i){return}const s=new Vue({el:i,store:store,data:{aid:unsafeWindow.aid,tipText:"",tipShowing:false,tipHandle:0},computed:{...Vuex.mapState(["watchlaterList"]),isInWatchlater(){return this.watchlaterList.includes(parseInt(this.aid))}},methods:{...Vuex.mapActions(["toggleWatchlater"]),showTip(t){this.tipText=t;this.tipShowing=true;if(this.tipHandle){clearTimeout(this.tipHandle)}this.tipHandle=setTimeout((()=>{this.tipShowing=false}),2e3)},async toggle(){await this.toggleWatchlater(this.aid);this.showTip(this.isInWatchlater?"已添加至稍后再看":"已从稍后再看移除")}}});Observer.videoChange((()=>{s.aid=unsafeWindow.aid}))})();return{unload:()=>{dqa(".ops .watchlater").forEach((t=>t.style.display="none"))},reload:()=>{dqa(".ops .watchlater").forEach((t=>t.style.display="inline-block"))}}})(); \ No newline at end of file diff --git a/min/player-focus.min.js b/min/player-focus.min.js index 29048dd08a..aaacf53251 100644 --- a/min/player-focus.min.js +++ b/min/player-focus.min.js @@ -1 +1 @@ -(()=>(e,l)=>{const o=document.URL.includes("bangumi")?"#bilibili-player":".video-info .video-title .tit";SpinQuery.select(o).then((async l=>{await playerReady();console.log(l);if(l===null){return}l.scrollIntoView();if(e.playerFocusOffset!==0){window.scrollBy(0,e.playerFocusOffset)}console.log(l.offsetTop,e.playerFocusOffset,window.scrollY)}))})(); \ No newline at end of file +(()=>(e,o)=>{const l=document.URL.includes("bangumi")?"#bilibili-player":".video-info .video-title .tit";SpinQuery.select(l).then((async l=>{const{playerReady:i}=await o.importAsync("player-ready");await i();console.log(l);if(l===null){return}l.scrollIntoView();if(e.playerFocusOffset!==0){window.scrollBy(0,e.playerFocusOffset)}console.log(l.offsetTop,e.playerFocusOffset,window.scrollY)}))})(); \ No newline at end of file diff --git a/min/player-ready.min.js b/min/player-ready.min.js new file mode 100644 index 0000000000..fd0b1a726f --- /dev/null +++ b/min/player-ready.min.js @@ -0,0 +1 @@ +(()=>(o,n)=>{const e=()=>new Promise((async(o,n)=>{await SpinQuery.condition((()=>unsafeWindow),(()=>unsafeWindow.onLoginInfoLoaded!==undefined));if(unsafeWindow.onLoginInfoLoaded){unsafeWindow.onLoginInfoLoaded(o)}else{logError(new Error("utils.playerReady 失败"));console.error(`typeof onLoginInfoLoaded === ${typeof unsafeWindow.onLoginInfoLoaded}`);n()}}));return{export:{playerReady:e}}})(); \ No newline at end of file diff --git a/min/quick-favorite.min.js b/min/quick-favorite.min.js index 2f91dac0bd..13171387db 100644 --- a/min/quick-favorite.min.js +++ b/min/quick-favorite.min.js @@ -1 +1 @@ -(()=>(i,t)=>{(async()=>{if(!document.URL.startsWith("https://www.bilibili.com/video/")||!getUID()){return}await playerReady();const e=dq(".video-toolbar .ops .collect");if(!e){return}t.applyStyle("quickFavoriteStyle");const s=`\n\n\n
快速收藏
\n\n
\n 选择快速收藏夹:\n
\n\n
\n
加载中...
\n
\n
右键点击快速收藏可再次打开
\n
{{tipText}}
\n
\n`.trim();if(i.outerWatchlater){const i=await SpinQuery.select(".ops .watchlater");if(i!==null){i.insertAdjacentHTML("beforebegin",s)}else{e.insertAdjacentHTML("afterend",s)}}else{e.insertAdjacentHTML("afterend",s)}const a=dq(".ops .quick-favorite");if(!a){return}const o=new Vue({el:a,store:store,components:{VDropdown:()=>t.importAsync("v-dropdown.vue")},data:{aid:unsafeWindow.aid,favoriteTitle:"",isFavorite:false,tipText:"",tipShowing:false,tipHandle:0,lists:[],selectedFavorite:"",listShowing:false},async created(){this.syncFavoriteState()},watch:{selectedFavorite(t){if(this.lists.length===0){return}const e=this.lists;const s=e.find((i=>i.title===t));if(s){i.quickFavoriteID=s.id;this.syncFavoriteState()}else{console.error("list not found in selectedFavorite(value)")}},async listShowing(i){if(i){document.addEventListener("click",(i=>{const t=this.$el;const e=i.target;if(e!==t&&!t.contains(e)){this.listShowing=false}}));if(this.lists.length===0){try{const i=await Ajax.getJsonWithCredentials(`https://api.bilibili.com/medialist/gateway/base/created?pn=1&ps=100&up_mid=${getUID()}&is_space=0`);if(i.code!==0){throw new Error(`获取收藏夹列表失败: ${i.message}`)}this.lists=_.get(i,"data.list",[])}catch(i){logError(i)}}}}},methods:{async syncFavoriteState(){if(i.quickFavoriteID===0){return}try{const t=await Ajax.getJsonWithCredentials(`https://api.bilibili.com/x/v3/fav/folder/created/list-all?type=2&rid=${this.aid}&up_mid=${getUID()}`);if(t.code!==0){throw new Error(`获取收藏状态失败: ${t.message}`)}const e=_.get(t,"data.list",[]);const s=e.find((t=>t.id===i.quickFavoriteID));if(s===undefined){i.quickFavoriteID=0;return}this.isFavorite=Boolean(s.fav_state);this.selectedFavorite=this.favoriteTitle=s.title}catch(i){logError(i)}},showTip(i){this.tipText=i;this.tipShowing=true;if(this.tipHandle){clearTimeout(this.tipHandle)}this.tipHandle=setTimeout((()=>{this.tipShowing=false}),2e3)},async toggle(){if(i.quickFavoriteID===0){this.listShowing=true;return}const t={rid:this.aid,type:2,add_media_ids:"",del_media_ids:"",csrf:getCsrf()};t[this.isFavorite?"del_media_ids":"add_media_ids"]=i.quickFavoriteID.toString();try{await Ajax.postTextWithCredentials(`https://api.bilibili.com/x/v3/fav/resource/deal`,Object.entries(t).map((([i,t])=>`${i}=${t}`)).join("&"));this.isFavorite=!this.isFavorite;this.showTip(this.isFavorite?`已添加至收藏夹: ${this.favoriteTitle}`:`已移出收藏夹: ${this.favoriteTitle}`)}catch(i){Toast.error(`快速收藏失败: ${i.message}`,"快速收藏");console.error(i)}}}});Observer.videoChange((()=>{o.aid=unsafeWindow.aid;o.syncFavoriteState()}))})();return{unload:()=>{dqa(".ops .quick-favorite").forEach((i=>i.style.display="none"))},reload:()=>{dqa(".ops .quick-favorite").forEach((i=>i.style.display="inline-block"))}}})(); \ No newline at end of file +(()=>(i,t)=>{(async()=>{if(!document.URL.startsWith("https://www.bilibili.com/video/")||!getUID()){return}const{playerReady:e}=await t.importAsync("player-ready");await e();const s=dq(".video-toolbar .ops .collect");if(!s){return}t.applyStyle("quickFavoriteStyle");const a=`\n\n\n
快速收藏
\n\n
\n 选择快速收藏夹:\n
\n\n
\n
加载中...
\n
\n
右键点击快速收藏可再次打开
\n
{{tipText}}
\n
\n`.trim();if(i.outerWatchlater){const i=await SpinQuery.select(".ops .watchlater");if(i!==null){i.insertAdjacentHTML("beforebegin",a)}else{s.insertAdjacentHTML("afterend",a)}}else{s.insertAdjacentHTML("afterend",a)}const o=dq(".ops .quick-favorite");if(!o){return}const l=new Vue({el:o,store:store,components:{VDropdown:()=>t.importAsync("v-dropdown.vue")},data:{aid:unsafeWindow.aid,favoriteTitle:"",isFavorite:false,tipText:"",tipShowing:false,tipHandle:0,lists:[],selectedFavorite:"",listShowing:false},async created(){this.syncFavoriteState()},watch:{selectedFavorite(t){if(this.lists.length===0){return}const e=this.lists;const s=e.find((i=>i.title===t));if(s){i.quickFavoriteID=s.id;this.syncFavoriteState()}else{console.error("list not found in selectedFavorite(value)")}},async listShowing(i){if(i){document.addEventListener("click",(i=>{const t=this.$el;const e=i.target;if(e!==t&&!t.contains(e)){this.listShowing=false}}));if(this.lists.length===0){try{const i=await Ajax.getJsonWithCredentials(`https://api.bilibili.com/medialist/gateway/base/created?pn=1&ps=100&up_mid=${getUID()}&is_space=0`);if(i.code!==0){throw new Error(`获取收藏夹列表失败: ${i.message}`)}this.lists=_.get(i,"data.list",[])}catch(i){logError(i)}}}}},methods:{async syncFavoriteState(){if(i.quickFavoriteID===0){return}try{const t=await Ajax.getJsonWithCredentials(`https://api.bilibili.com/x/v3/fav/folder/created/list-all?type=2&rid=${this.aid}&up_mid=${getUID()}`);if(t.code!==0){throw new Error(`获取收藏状态失败: ${t.message}`)}const e=_.get(t,"data.list",[]);const s=e.find((t=>t.id===i.quickFavoriteID));if(s===undefined){i.quickFavoriteID=0;return}this.isFavorite=Boolean(s.fav_state);this.selectedFavorite=this.favoriteTitle=s.title}catch(i){logError(i)}},showTip(i){this.tipText=i;this.tipShowing=true;if(this.tipHandle){clearTimeout(this.tipHandle)}this.tipHandle=setTimeout((()=>{this.tipShowing=false}),2e3)},async toggle(){if(i.quickFavoriteID===0){this.listShowing=true;return}const t={rid:this.aid,type:2,add_media_ids:"",del_media_ids:"",csrf:getCsrf()};t[this.isFavorite?"del_media_ids":"add_media_ids"]=i.quickFavoriteID.toString();try{await Ajax.postTextWithCredentials(`https://api.bilibili.com/x/v3/fav/resource/deal`,Object.entries(t).map((([i,t])=>`${i}=${t}`)).join("&"));this.isFavorite=!this.isFavorite;this.showTip(this.isFavorite?`已添加至收藏夹: ${this.favoriteTitle}`:`已移出收藏夹: ${this.favoriteTitle}`)}catch(i){Toast.error(`快速收藏失败: ${i.message}`,"快速收藏");console.error(i)}}}});Observer.videoChange((()=>{l.aid=unsafeWindow.aid;l.syncFavoriteState()}))})();return{unload:()=>{dqa(".ops .quick-favorite").forEach((i=>i.style.display="none"))},reload:()=>{dqa(".ops .quick-favorite").forEach((i=>i.style.display="inline-block"))}}})(); \ No newline at end of file diff --git a/src/client/utils.js b/src/client/utils.js index 91449cb9fe..b1bd29d76a 100644 --- a/src/client/utils.js +++ b/src/client/utils.js @@ -191,16 +191,7 @@ export const matchPattern = (str, pattern) => { return pattern.test(str) } export const playerReady = () => { - return SpinQuery.condition( - () => { - const danmakuInfo = dq('.video-data .dm') - if (danmakuInfo) { - return parseInt(danmakuInfo.textContent) - } - return NaN - }, - it => !Number.isNaN(it), - ) + return Promise.reject('此函数已弃用, 请使用 src/utils/player-ready.ts') } export const formData = (obj) => Object.entries(obj).map(([k, v]) => `${k}=${v}`).join('&') export const retrieveImageUrl = (element) => { diff --git a/src/global.d.ts b/src/global.d.ts index 7d17269999..c9eb117f84 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -572,7 +572,7 @@ declare global { const matchPattern: (str: string, pattern: string | RegExp) => boolean type ScriptVersion = 'Stable' | 'Preview' | 'Offline' | 'Preview Offline' | 'Local' | 'Local preview' | 'Local stable' | 'Local offline' | 'Local preview offline' const getScriptVersion: () => ScriptVersion - const playerReady: () => Promise + // const playerReady: () => Promise const formData: (obj: any) => string const retrieveImageUrl: (element: Element) => { url: string; extension: string } | null } diff --git a/src/utils/gui-settings/gui-settings.js b/src/utils/gui-settings/gui-settings.js index 7aaab34b40..779636f598 100644 --- a/src/utils/gui-settings/gui-settings.js +++ b/src/utils/gui-settings/gui-settings.js @@ -135,20 +135,20 @@ function checkOfflineData () { } // https://github.com/the1812/Bilibili-Evolved/issues/1076 -const issue1076 = ['playerFocus', 'outerWatchlater', 'quickFavorite'] +// const issue1076 = ['playerFocus', 'outerWatchlater', 'quickFavorite'] const preCheckCompatibility = () => { - if (issue1076.some(key => settings[key])) { - issue1076.forEach(key => { - settings[key] = false - }) - Toast.info(/* html */` -
为避免b站播放器改版导致网站无法正常使用, 以下功能已自动关闭并禁用: -自动定位到播放器 外置稍后再看 启用快速收藏 +// if (issue1076.some(key => settings[key])) { +// issue1076.forEach(key => { +// settings[key] = false +// }) +// Toast.info(/* html */` +//
为避免b站播放器改版导致网站无法正常使用, 以下功能已自动关闭并禁用: +// 自动定位到播放器 外置稍后再看 启用快速收藏 -详情见讨论区, 这些功能将在恢复后再解除禁用. -若当前页面是视频页面且出现问题, 刷新即可恢复正常.
- `.trim(), '通知') - } +// 详情见讨论区, 这些功能将在恢复后再解除禁用. +// 若当前页面是视频页面且出现问题, 刷新即可恢复正常.
+// `.trim(), '通知') +// } } function checkCompatibility () { if (window.devicePixelRatio === 1) { @@ -157,9 +157,9 @@ function checkCompatibility () { settings.harunaScale = false settings.imageResolution = false } - checkBoxes - .filter(it => issue1076.includes(it.getAttribute('key'))) - .forEach(checkBox => (checkBox.disabled = true)) + // checkBoxes + // .filter(it => issue1076.includes(it.getAttribute('key'))) + // .forEach(checkBox => (checkBox.disabled = true)) } function setDisplayNames () { for (const [key, name] of Object.entries(Resource.displayNames)) { diff --git a/src/video/outer-watchlater/outer-watchlater.ts b/src/video/outer-watchlater/outer-watchlater.ts index 8ddc172895..9515ce964b 100644 --- a/src/video/outer-watchlater/outer-watchlater.ts +++ b/src/video/outer-watchlater/outer-watchlater.ts @@ -2,6 +2,7 @@ if (!document.URL.startsWith('https://www.bilibili.com/video/') || !getUID()) { return } + const { playerReady } = await import('../player-ready') await playerReady() const favoriteButton = dq('.video-toolbar .ops .collect') if (!favoriteButton) { diff --git a/src/video/player-focus.js b/src/video/player-focus.js index 222df20c3e..8c3d82f26b 100644 --- a/src/video/player-focus.js +++ b/src/video/player-focus.js @@ -1,5 +1,6 @@ const target = document.URL.includes('bangumi') ? '#bilibili-player' : '.video-info .video-title .tit' SpinQuery.select(target).then(async element => { + const { playerReady } = await import('../player-ready') await playerReady() console.log(element) if (element === null) { diff --git a/src/video/player-ready.ts b/src/video/player-ready.ts new file mode 100644 index 0000000000..fba5288eca --- /dev/null +++ b/src/video/player-ready.ts @@ -0,0 +1,23 @@ +/** 等待播放器准备好, 如果过早注入 DOM 元素可能会导致爆炸 + * + * https://github.com/the1812/Bilibili-Evolved/issues/1076 + * https://github.com/the1812/Bilibili-Evolved/issues/770 + */ +export const playerReady = () => { + return new Promise(async (resolve, reject) => { + await SpinQuery.condition( + () => unsafeWindow, + () => unsafeWindow.onLoginInfoLoaded !== undefined, + ) + if (unsafeWindow.onLoginInfoLoaded) { + unsafeWindow.onLoginInfoLoaded(resolve) + } else { + logError(new Error('utils.playerReady 失败')) + console.error(`typeof onLoginInfoLoaded === ${typeof unsafeWindow.onLoginInfoLoaded}`) + reject() + } + }) +} +export default { + export: { playerReady }, +} diff --git a/src/video/quick-favorite/quick-favorite.ts b/src/video/quick-favorite/quick-favorite.ts index ea2e8bba47..84250116ed 100644 --- a/src/video/quick-favorite/quick-favorite.ts +++ b/src/video/quick-favorite/quick-favorite.ts @@ -2,6 +2,7 @@ if (!document.URL.startsWith('https://www.bilibili.com/video/') || !getUID()) { return } + const { playerReady } = await import('../player-ready') await playerReady() const favoriteButton = dq('.video-toolbar .ops .collect') if (!favoriteButton) {