Refactor settings

This commit is contained in:
the1812 2019-05-10 22:44:01 +08:00
parent 1bb4759268
commit a63c870f98
11 changed files with 33 additions and 33 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
(()=>{return(e,t)=>{class s{setCookie(e,t){document.cookie=`${e}=${t};path=/;domain=.bilibili.com;max-age=31536000`}clearCookie(e){document.cookie=`${e}=;path=/;domain=.bilibili.com;max-age=0`}getValue(e){return document.cookie.replace(new RegExp(`(?:(?:^|.*;\\s*)${e}\\s*\\=\\s*([^;]*).*$)|^.*$`),"$1")}checkSettings(){return e.useDefaultPlayerLayout}checkCookies(){if(!this.checkSettings()){return}}useNewLayout(){if(!this.checkSettings()){return}}useOldLayout(){if(!this.checkSettings()){return}}setLayout(e){if(e){this.useNewLayout()}else{this.useOldLayout()}}}class o extends s{checkCookies(){super.checkCookies();const t=this.getValue(this.cookieKey);if(t===""||parseInt(t)<0&&e.defaultPlayerLayout!=="旧版"){this.useNewLayout()}else if(e.defaultPlayerLayout!=="新版"){this.useOldLayout()}}constructor(){super();this.cookieKey="stardustvideo";this.checkCookies()}useNewLayout(){super.useNewLayout();this.setCookie(this.cookieKey,1)}useOldLayout(){super.useOldLayout();this.setCookie(this.cookieKey,-1)}}class i extends s{checkCookies(){super.checkCookies();const t=this.getValue(this.cookieKey);if(t===""||parseInt(t)<=0&&e.defaultBangumiLayout!=="旧版"){this.useNewLayout()}else if(e.defaultBangumiLayout!=="新版"){this.useOldLayout()}}constructor(){super();this.cookieKey="stardustpgcv";this.checkCookies()}useNewLayout(){super.useNewLayout();this.setCookie(this.cookieKey,"0606")}useOldLayout(){super.useOldLayout();this.setCookie(this.cookieKey,0)}}const u=new o;addSettingsListener("defaultPlayerLayout",e=>{console.log("layout change detected");u.setLayout(e==="新版")});const a=new i;addSettingsListener("defaultBangumiLayout",e=>{a.setLayout(e==="新版")})}})();
(()=>{return(e,t)=>{class s{setCookie(e,t){document.cookie=`${e}=${t};path=/;domain=.bilibili.com;max-age=31536000`}clearCookie(e){document.cookie=`${e}=;path=/;domain=.bilibili.com;max-age=0`}getValue(e){return document.cookie.replace(new RegExp(`(?:(?:^|.*;\\s*)${e}\\s*\\=\\s*([^;]*).*$)|^.*$`),"$1")}checkSettings(){return e.useDefaultPlayerLayout}checkCookies(){if(!this.checkSettings()){return}}useNewLayout(){if(!this.checkSettings()){return}}useOldLayout(){if(!this.checkSettings()){return}}setLayout(e){if(e){this.useNewLayout()}else{this.useOldLayout()}}}class o extends s{checkCookies(){super.checkCookies();const t=this.getValue(this.cookieKey);if(t===""||parseInt(t)<0&&e.defaultPlayerLayout!=="旧版"){this.useNewLayout()}else if(e.defaultPlayerLayout!=="新版"){this.useOldLayout()}}constructor(){super();this.cookieKey="stardustvideo";this.checkCookies()}useNewLayout(){super.useNewLayout();this.setCookie(this.cookieKey,1)}useOldLayout(){super.useOldLayout();this.setCookie(this.cookieKey,-1)}}class i extends s{checkCookies(){super.checkCookies();const t=this.getValue(this.cookieKey);if(t===""||parseInt(t)<=0&&e.defaultBangumiLayout!=="旧版"){this.useNewLayout()}else if(e.defaultBangumiLayout!=="新版"){this.useOldLayout()}}constructor(){super();this.cookieKey="stardustpgcv";this.checkCookies()}useNewLayout(){super.useNewLayout();this.setCookie(this.cookieKey,"0606")}useOldLayout(){super.useOldLayout();this.setCookie(this.cookieKey,0)}}const u=new o;addSettingsListener("defaultPlayerLayout",e=>{u.setLayout(e==="新版")});const a=new i;addSettingsListener("defaultBangumiLayout",e=>{a.setLayout(e==="新版")})}})();

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
(()=>{return(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 r=[];let c=[];function a(e){let t=e.nextElementSibling;const n=[];while(t!==null&&!t.classList.contains("category")){n.push(t);t=t.nextElementSibling}return n}function l(){c.forEach(t=>t.value=e[t.getAttribute("key")]);r.forEach(t=>t.checked=e[t.getAttribute("key")])}function u(){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"))});c.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");a(e.currentTarget).forEach(e=>e.classList.toggle("folded"))})});document.querySelectorAll(".gui-settings-dropdown>input").forEach(e=>{e.addEventListener("click",e=>{e.currentTarget.parentElement.classList.toggle("opened")})})}function d(){const t=e=>{};r.forEach(n=>{n.addEventListener("change",()=>{const i=n.getAttribute("key");const s=n.checked;e[i]=s;t(i);saveSettings(e)})});c.forEach(n=>{n.addEventListener("change",()=>{const i=n.getAttribute("key");const o=s.getValidator(i).validate(n.value);e[i]=o;n.value=o;t(i);saveSettings(e)})})}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 f(){if(typeof offlineData!=="undefined"){document.querySelector(".gui-settings-checkbox-container>input[key=useCache]").parentElement.parentElement.classList.add("disabled");document.querySelector("input[key=useCache]").disabled=true}}function b(){document.querySelectorAll(".gui-settings-content ul li.category").forEach(e=>{e.click()})}function m(){if(!CSS.supports("backdrop-filter","blur(24px)")&&!CSS.supports("-webkit-backdrop-filter","blur(24px)")){o.find(e=>e.getAttribute("key")==="blurVideoControl").disabled=true;e.blurVideoControl=false;saveSettings(e)}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;saveSettings(e)}if(e.defaultPlayerLayout==="旧版"){const t=o.find(e=>e.getAttribute("key")==="overrideNavBar");t.disabled=true;raiseEvent(t,"change");if(e.overrideNavBar){t.checked=false;raiseEvent(t,"change");e.overrideNavBar=false;saveSettings(e)}}}function y(){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");document.body.insertAdjacentHTML("afterbegin",`<link rel="stylesheet" href="//cdn.materialdesignicons.com/3.5.95/css/materialdesignicons.min.css">`);const e=document.body&&unsafeWindow.parent.window!==unsafeWindow;if(e){document.querySelector(".gui-settings-icon-panel").style.display="none"}const s=(t.data.guiSettingsDom||t.data.guiSettingsHtml).text;document.body.insertAdjacentHTML("beforeend",s);const a=document.querySelector(".widgets-container");const p=a.querySelector(".empty-tip");Observer.childList(a,()=>{if(a.childElementCount<=1){p.classList.add("show")}else{p.classList.remove("show")}});o=[...document.querySelectorAll("input[key]")];r=o.filter(e=>e.type==="checkbox");c=o.filter(e=>e.type==="text");u();f();l();g();d();b();m();y();(new n).setupDom();new i;const h=document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");document.querySelector(".gui-settings-icon-panel").addEventListener("mouseover",()=>{h.forEach(e=>e.classList.add("loaded"))},{once:true})})()}})();
(()=>{return(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 r=[];let c=[];function a(e){let t=e.nextElementSibling;const n=[];while(t!==null&&!t.classList.contains("category")){n.push(t);t=t.nextElementSibling}return n}function l(){c.forEach(t=>t.value=e[t.getAttribute("key")]);r.forEach(t=>t.checked=e[t.getAttribute("key")])}function u(){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"))});c.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");a(e.currentTarget).forEach(e=>e.classList.toggle("folded"))})});document.querySelectorAll(".gui-settings-dropdown>input").forEach(e=>{e.addEventListener("click",e=>{e.currentTarget.parentElement.classList.toggle("opened")})})}function d(){const t=e=>{};r.forEach(n=>{n.addEventListener("change",()=>{const i=n.getAttribute("key");const s=n.checked;e[i]=s;t(i);saveSettings(e)})});c.forEach(n=>{n.addEventListener("change",()=>{const i=n.getAttribute("key");const o=s.getValidator(i).validate(n.value);e[i]=o;n.value=o;t(i);saveSettings(e)})})}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 f(){if(typeof offlineData!=="undefined"){document.querySelector(".gui-settings-checkbox-container>input[key=useCache]").parentElement.parentElement.classList.add("disabled");document.querySelector("input[key=useCache]").disabled=true}}function b(){document.querySelectorAll(".gui-settings-content ul li.category").forEach(e=>{e.click()})}function m(){if(!CSS.supports("backdrop-filter","blur(24px)")&&!CSS.supports("-webkit-backdrop-filter","blur(24px)")){o.find(e=>e.getAttribute("key")==="blurVideoControl").disabled=true;e.blurVideoControl=false;saveSettings(e)}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;saveSettings(e)}if(e.defaultPlayerLayout==="旧版"){const t=o.find(e=>e.getAttribute("key")==="overrideNavBar");t.disabled=true;raiseEvent(t,"change");if(e.overrideNavBar){t.checked=false;raiseEvent(t,"change");e.overrideNavBar=false;saveSettings(e)}}}function y(){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");document.body.insertAdjacentHTML("afterbegin",`<link rel="stylesheet" href="//cdn.materialdesignicons.com/3.5.95/css/materialdesignicons.min.css">`);const e=document.body&&unsafeWindow.parent.window!==unsafeWindow;if(e){document.querySelector(".gui-settings-icon-panel").style.display="none"}const s=t.data.guiSettingsHtml.text;document.body.insertAdjacentHTML("beforeend",s);const a=document.querySelector(".widgets-container");const p=a.querySelector(".empty-tip");Observer.childList(a,()=>{if(a.childElementCount<=1){p.classList.add("show")}else{p.classList.remove("show")}});(new n).setupDom();const h=document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");document.querySelector(".gui-settings-icon-panel").addEventListener("mouseover",()=>{h.forEach(e=>e.classList.add("loaded"));o=[...document.querySelectorAll("input[key]")];r=o.filter(e=>e.type==="checkbox");c=o.filter(e=>e.type==="text");u();f();l();g();d();b();m();y();new i},{once:true})})()}})();

View File

@ -1 +1 @@
(()=>{return(e,t)=>{class i{constructor(e,t){this.isActive=e;this.id=t}static parseJson(e,{successAction:t,errorMessage:i,errorAction:a}){const s=JSON.parse(e);if(s.code!==0){logError(`${i} 错误码:${s.code} ${s.message||""}`);return a(s)}return t(s)}}class a extends i{constructor({medal_id:e,status:t,level:i,medalName:a,uname:s}){super(t===1,e);this.level=i;this.name=a;this.upName=s}static async getList(){return i.parseJson(await Ajax.getTextWithCredentials("https://api.live.bilibili.com/i/api/medal?page=1&pageSize=256"),{successAction:e=>e.data.fansMedalList.map(e=>new a(e)),errorAction:()=>[],errorMessage:"无法获取勋章列表."})}static getContainer(){return document.querySelector("#medal-helper .medal-popup ul")}static getItemTemplate(e){return`<li data-id='${e.id}' ${e.isActive?"class='active'":""}>\n <label title='${e.upName}'>\n <input name='medal' type='radio' ${e.isActive?"checked":""}>\n <div class='fans-medal-item level-${e.level}'>\n <span class='label'>${e.name}</span>\n <span class='level'>${e.level}</span>\n </div>\n </label>\n </li>`}async activate(){return i.parseJson(await Ajax.getTextWithCredentials(`https://api.live.bilibili.com/i/ajaxWearFansMedal?medal_id=${this.id}`),{successAction:()=>{this.isActive=true;return true},errorAction:()=>false,errorMessage:"佩戴勋章失败."})}async deactivate(){return i.parseJson(await Ajax.getTextWithCredentials(`https://api.live.bilibili.com/i/ajaxCancelWear`),{successAction:()=>{this.isActive=false;return true},errorAction:()=>false,errorMessage:"卸下勋章失败."})}}class s extends i{constructor({id:e,cid:t,wear:i,css:a,name:r,source:c}){super(i,a);this.tid=e;this.cid=t;this.name=r;this.source=c;s.getImageMap().then(e=>{this.imageUrl=e[this.id]})}static async getImageMap(){if(s.imageMap===undefined){return i.parseJson(await Ajax.getTextWithCredentials("https://api.live.bilibili.com/rc/v1/Title/webTitles"),{successAction(e){s.imageMap={};e.data.forEach(e=>{s.imageMap[e.identification]=e.web_pic_url});return s.imageMap},errorAction:()=>{return{}},errorMessage:"获取头衔图片失败."})}else{return s.imageMap}}static async getList(){return i.parseJson(await Ajax.getTextWithCredentials("https://api.live.bilibili.com/i/api/ajaxTitleInfo?page=1&pageSize=256&had=1"),{successAction:e=>e.data.list.map(e=>new s(e)),errorAction:()=>[],errorMessage:"无法获取头衔列表."})}static getContainer(){return document.querySelector("#title-helper .medal-popup ul")}static getItemTemplate(e){return`<li data-id='${e.id}' ${e.isActive?"class='active'":""}>\n <label title='${e.name}'>\n <input name='medal' type='radio' ${e.isActive?"checked":""}>\n <img src='${e.imageUrl}' class="title-image">\n </label>\n </li>`}async activate(){return i.parseJson(await Ajax.postTextWithCredentials(`https://api.live.bilibili.com/i/ajaxWearTitle`,`id=${this.tid}&cid=${this.cid}`),{successAction:()=>{this.isActive=true;return true},errorAction:()=>false,errorMessage:"佩戴头衔失败."})}async deactivate(){return i.parseJson(await Ajax.postTextWithCredentials(`https://api.live.bilibili.com/i/ajaxCancelWearTitle`,""),{successAction:()=>{this.isActive=false;return true},errorAction:()=>false,errorMessage:"卸下头衔失败."})}}async function r(e){const t=e.getContainer();const i=await e.getList();const a=async()=>{const i=await e.getList();i.forEach(e=>{const i=t.querySelector(`li[data-id='${e.id}']`);if(e.isActive){i.classList.add("active")}else{i.classList.remove("active")}i.querySelector(`input`).checked=e.isActive})};i.forEach(s=>{const r=e.getItemTemplate(s);t.insertAdjacentHTML("beforeend",r);const c=t.querySelector(`li[data-id='${s.id}']`);const n=c.querySelector(`input`);c.addEventListener("click",e=>{if(e.target===n){return}if(s.isActive){s.deactivate().then(a)}else{const e=i.find(e=>e.isActive);if(e){e.isActive=false}s.activate().then(a)}})})}return{export:{Badge:i,Medal:a,Title:s},widget:{condition:()=>document.domain==="live.bilibili.com",content:(t.data.medalHelperDom||t.data.medalHelperHtml).text,success:()=>{document.querySelectorAll(".medal-helper").forEach(e=>{const t=e.querySelector(".medal-popup");e.addEventListener("click",e=>{if(!t.contains(e.target)){t.classList.toggle("opened")}})});r(a);s.getImageMap().then(()=>r(s))}}}}})();
(()=>{return(e,t)=>{class i{constructor(e,t){this.isActive=e;this.id=t}static parseJson(e,{successAction:t,errorMessage:i,errorAction:a}){const s=JSON.parse(e);if(s.code!==0){logError(`${i} 错误码:${s.code} ${s.message||""}`);return a(s)}return t(s)}}class a extends i{constructor({medal_id:e,status:t,level:i,medalName:a,uname:s}){super(t===1,e);this.level=i;this.name=a;this.upName=s}static async getList(){return i.parseJson(await Ajax.getTextWithCredentials("https://api.live.bilibili.com/i/api/medal?page=1&pageSize=256"),{successAction:e=>e.data.fansMedalList.map(e=>new a(e)),errorAction:()=>[],errorMessage:"无法获取勋章列表."})}static getContainer(){return document.querySelector("#medal-helper .medal-popup ul")}static getItemTemplate(e){return`<li data-id='${e.id}' ${e.isActive?"class='active'":""}>\n <label title='${e.upName}'>\n <input name='medal' type='radio' ${e.isActive?"checked":""}>\n <div class='fans-medal-item level-${e.level}'>\n <span class='label'>${e.name}</span>\n <span class='level'>${e.level}</span>\n </div>\n </label>\n </li>`}async activate(){return i.parseJson(await Ajax.getTextWithCredentials(`https://api.live.bilibili.com/i/ajaxWearFansMedal?medal_id=${this.id}`),{successAction:()=>{this.isActive=true;return true},errorAction:()=>false,errorMessage:"佩戴勋章失败."})}async deactivate(){return i.parseJson(await Ajax.getTextWithCredentials(`https://api.live.bilibili.com/i/ajaxCancelWear`),{successAction:()=>{this.isActive=false;return true},errorAction:()=>false,errorMessage:"卸下勋章失败."})}}class s extends i{constructor({id:e,cid:t,wear:i,css:a,name:r,source:c}){super(i,a);this.tid=e;this.cid=t;this.name=r;this.source=c;s.getImageMap().then(e=>{this.imageUrl=e[this.id]})}static async getImageMap(){if(s.imageMap===undefined){return i.parseJson(await Ajax.getTextWithCredentials("https://api.live.bilibili.com/rc/v1/Title/webTitles"),{successAction(e){s.imageMap={};e.data.forEach(e=>{s.imageMap[e.identification]=e.web_pic_url});return s.imageMap},errorAction:()=>{return{}},errorMessage:"获取头衔图片失败."})}else{return s.imageMap}}static async getList(){return i.parseJson(await Ajax.getTextWithCredentials("https://api.live.bilibili.com/i/api/ajaxTitleInfo?page=1&pageSize=256&had=1"),{successAction:e=>e.data.list.map(e=>new s(e)),errorAction:()=>[],errorMessage:"无法获取头衔列表."})}static getContainer(){return document.querySelector("#title-helper .medal-popup ul")}static getItemTemplate(e){return`<li data-id='${e.id}' ${e.isActive?"class='active'":""}>\n <label title='${e.name}'>\n <input name='medal' type='radio' ${e.isActive?"checked":""}>\n <img src='${e.imageUrl}' class="title-image">\n </label>\n </li>`}async activate(){return i.parseJson(await Ajax.postTextWithCredentials(`https://api.live.bilibili.com/i/ajaxWearTitle`,`id=${this.tid}&cid=${this.cid}`),{successAction:()=>{this.isActive=true;return true},errorAction:()=>false,errorMessage:"佩戴头衔失败."})}async deactivate(){return i.parseJson(await Ajax.postTextWithCredentials(`https://api.live.bilibili.com/i/ajaxCancelWearTitle`,""),{successAction:()=>{this.isActive=false;return true},errorAction:()=>false,errorMessage:"卸下头衔失败."})}}async function r(e){const t=e.getContainer();const i=await e.getList();const a=async()=>{const i=await e.getList();i.forEach(e=>{const i=t.querySelector(`li[data-id='${e.id}']`);if(e.isActive){i.classList.add("active")}else{i.classList.remove("active")}i.querySelector(`input`).checked=e.isActive})};i.forEach(s=>{const r=e.getItemTemplate(s);t.insertAdjacentHTML("beforeend",r);const c=t.querySelector(`li[data-id='${s.id}']`);const n=c.querySelector(`input`);c.addEventListener("click",e=>{if(e.target===n){return}if(s.isActive){s.deactivate().then(a)}else{const e=i.find(e=>e.isActive);if(e){e.isActive=false}s.activate().then(a)}})})}return{export:{Badge:i,Medal:a,Title:s},widget:{condition:()=>document.domain==="live.bilibili.com",content:t.data.medalHelperHtml.text,success:()=>{document.querySelectorAll(".medal-helper").forEach(e=>{const t=e.querySelector(".medal-popup");e.addEventListener("click",e=>{if(!t.contains(e.target)){t.classList.toggle("opened")}})});r(a);s.getImageMap().then(()=>r(s))}}}}})();

View File

@ -1 +1 @@
(()=>{return(e,t)=>{const{VideoInfo:i}=t.import("video-info");const{getFriendlyTitle:n}=t.import("title");class o{constructor(e){this.url=e;if($(".image-viewer").length===0){this.createContainer()}this.viewer=$(".image-viewer-container");this.downloadImage()}createContainer(){$("body").append((t.data.imageViewerDom||t.data.imageViewerHtml).text);$(".image-viewer-container .close").on("click",()=>this.hide());t.applyStyle("imageViewerStyle")}downloadImage(){const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=n();const i=URL.createObjectURL(e.response);if(this.imageData){URL.revokeObjectURL(this.imageData)}this.imageData=i;this.viewer.find(".download").attr("href",i).attr("download",t+this.url.substring(this.url.lastIndexOf(".")));this.viewer.find(".copy-link").on("click",()=>GM_setClipboard(this.url));this.viewer.find(".new-tab").attr("href",this.url);this.viewer.find(".image").prop("src",i)});e.send()}show(){this.viewer.addClass("opened")}hide(){this.viewer.removeClass("opened")}}return(()=>{if($("meta[itemprop='image'],meta[property='og:image']").length>0){return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);return Boolean(e)},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new i(e);await t.fetchInfo();return t.coverUrl}let t=new o(await e());$("#view-cover").on("click",()=>{t.show()});const n=async()=>{t=new o(await e())};if(Observer.videoChange){Observer.videoChange(n)}else{Observer.childList("#bofqi",n)}}}}}else{return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>document.querySelector(".header-info-ctnr .room-cover"));return Boolean(e)},success:async()=>{const e=$(".header-info-ctnr .room-cover");const t=e.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const i=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const n=await Ajax.getText(i);const s=JSON.parse(n).data.cover;const a=new o(s);$("#view-cover").on("click",()=>{a.show()})}}}}}})()}})();
(()=>{return(e,t)=>{const{VideoInfo:i}=t.import("video-info");const{getFriendlyTitle:n}=t.import("title");class o{constructor(e){this.url=e;if($(".image-viewer").length===0){this.createContainer()}this.viewer=$(".image-viewer-container");this.downloadImage()}createContainer(){$("body").append(t.data.imageViewerHtml.text);$(".image-viewer-container .close").on("click",()=>this.hide());t.applyStyle("imageViewerStyle")}downloadImage(){const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=n();const i=URL.createObjectURL(e.response);if(this.imageData){URL.revokeObjectURL(this.imageData)}this.imageData=i;this.viewer.find(".download").attr("href",i).attr("download",t+this.url.substring(this.url.lastIndexOf(".")));this.viewer.find(".copy-link").on("click",()=>GM_setClipboard(this.url));this.viewer.find(".new-tab").attr("href",this.url);this.viewer.find(".image").prop("src",i)});e.send()}show(){this.viewer.addClass("opened")}hide(){this.viewer.removeClass("opened")}}return(()=>{if($("meta[itemprop='image'],meta[property='og:image']").length>0){return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);return Boolean(e)},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new i(e);await t.fetchInfo();return t.coverUrl}let t=new o(await e());$("#view-cover").on("click",()=>{t.show()});const n=async()=>{t=new o(await e())};if(Observer.videoChange){Observer.videoChange(n)}else{Observer.childList("#bofqi",n)}}}}}else{return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>document.querySelector(".header-info-ctnr .room-cover"));return Boolean(e)},success:async()=>{const e=$(".header-info-ctnr .room-cover");const t=e.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const i=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const n=await Ajax.getText(i);const s=JSON.parse(n).data.cover;const a=new o(s);$("#view-cover").on("click",()=>{a.show()})}}}}}})()}})();

View File

@ -282,7 +282,7 @@ function setDisplayNames()
// return;
}
const settingsBox = (resources.data.guiSettingsDom || resources.data.guiSettingsHtml).text;
const settingsBox = resources.data.guiSettingsHtml.text;
document.body.insertAdjacentHTML("beforeend", settingsBox);
const widgetsContainer = document.querySelector(".widgets-container");
@ -299,23 +299,23 @@ function setDisplayNames()
}
});
inputs = [...document.querySelectorAll("input[key]")];
checkBoxes = inputs.filter(it => it.type === "checkbox");
textBoxes = inputs.filter(it => it.type === "text");
setupEvents();
checkOfflineData();
syncGui();
listenDependencies();
listenSettingsChange();
foldAllCategories();
checkCompatibility();
setDisplayNames();
new ThemeColors().setupDom();
new SettingsSearch();
const boxes = document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");
document.querySelector(".gui-settings-icon-panel").addEventListener("mouseover", () =>
{
boxes.forEach(it => it.classList.add("loaded"));
inputs = [...document.querySelectorAll("input[key]")];
checkBoxes = inputs.filter(it => it.type === "checkbox");
textBoxes = inputs.filter(it => it.type === "text");
setupEvents();
checkOfflineData();
syncGui();
listenDependencies();
listenSettingsChange();
foldAllCategories();
checkCompatibility();
setDisplayNames();
new SettingsSearch();
}, { once: true });
})();

View File

@ -228,7 +228,7 @@ export default {
},
widget: {
condition: () => document.domain === "live.bilibili.com",
content: (resources.data.medalHelperDom || resources.data.medalHelperHtml).text,
content: resources.data.medalHelperHtml.text,
success: () =>
{
document.querySelectorAll(".medal-helper").forEach(it =>

View File

@ -554,7 +554,7 @@ async function loadWidget()
export default {
widget:
{
content: (resources.data.downloadVideoDom || resources.data.downloadVideoHtml).text,
content: resources.data.downloadVideoHtml.text,
condition: loadPageData,
success: loadWidget,
},

View File

@ -14,7 +14,7 @@ class ImageViewer
}
createContainer()
{
$("body").append((resources.data.imageViewerDom || resources.data.imageViewerHtml).text);
$("body").append(resources.data.imageViewerHtml.text);
$(".image-viewer-container .close").on("click", () => this.hide());
resources.applyStyle("imageViewerStyle");
}