mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Lazy load widgets, idle check updates
This commit is contained in:
parent
56bdf2b158
commit
ffbff7132b
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -58,7 +58,7 @@
|
||||
"full-tweets-title.min.js": "DD57BB732ABEF7739CA84AEFF97E86F8984FCC4A8A75B957213622350B2A7C37",
|
||||
"gui-settings.min.css": "9C7CABF974C76DCFAD6DBECAD8CCA7C1EFA1EAEA9977DF5F0013B3F4FA664FCD",
|
||||
"gui-settings.min.html": "AA990C3CE45A68755AA9BED58AC4B13CAFC88C81FEF7C080DFB40A248D269F46",
|
||||
"gui-settings.min.js": "152B54BC01E20F55EF27A379823488F06C58154A078F097EC38F45501188BEAA",
|
||||
"gui-settings.min.js": "BE5C8F6D75F1AAF9DEBC1FA4D3F4CC3834F0EF647BDBECFC3C8A44E72CE177BF",
|
||||
"haruna-scale.min.js": "7B0F89A664B6A3D0BE21F7501660058DE3DC0881A81FCDA44B9F3C31BBD73D30",
|
||||
"hide-bangumi-reviews.min.js": "CC3CE6B3F1606F8AB0A4ADAD3B16E6DA9245D0676ACF74B97FB143FBFF0C7223",
|
||||
"hide-banner.min.css": "FF157AF84741AF0564FE2930CC49F524F99A41739DB4C44DC944EC6F4F620A0F",
|
||||
|
||||
BIN
min/bundle.zip
BIN
min/bundle.zip
Binary file not shown.
2
min/gui-settings.min.js
vendored
2
min/gui-settings.min.js
vendored
@ -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 c=[];let r=[];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(){r.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"))});r.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 u(){c.forEach(t=>{t.addEventListener("change",()=>{const n=t.getAttribute("key");const i=t.checked;e[n]=i})});r.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 f(){if(typeof offlineData!=="undefined"){}}function p(){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}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 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 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{style:a}=await t.importAsync("mdi");if(!a){document.body.insertAdjacentHTML("afterbegin",`<link rel="stylesheet" href="//cdn.materialdesignicons.com/3.6.95/css/materialdesignicons.min.css">`)}const m=document.querySelector(".widgets-container");const y=m.querySelector(".empty-tip");Observer.childList(m,()=>{if(m.childElementCount<=1){y.classList.add("show")}else{y.classList.remove("show")}});const h=document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");const E=document.querySelector(".gui-settings-icon-panel");E.addEventListener("mouseover",async()=>{const{loadTooltip:e}=await t.importAsync("settings-tooltip.loader");await e();await t.applyDropdownOptions();raiseEvent(E,"be:load");raiseEvent(dq(".bilibili-evolved-about"),"be:about-load");(new n).setupDom();h.forEach(e=>e.classList.add("loaded"));o=[...document.querySelectorAll("input[key]")];c=o.filter(e=>e.type==="checkbox");r=o.filter(e=>e.type==="text"&&!e.parentElement.classList.contains("gui-settings-dropdown"));d();f();l();g();u();p();b();new i},{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 c=[];let r=[];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(){r.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"))});r.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 u(){c.forEach(t=>{t.addEventListener("change",()=>{const n=t.getAttribute("key");const i=t.checked;e[n]=i})});r.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 p(){if(typeof offlineData!=="undefined"){}}function f(){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}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 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 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{style:a}=await t.importAsync("mdi");if(!a){document.body.insertAdjacentHTML("afterbegin",`<link rel="stylesheet" href="//cdn.materialdesignicons.com/3.6.95/css/materialdesignicons.min.css">`)}const m=document.querySelector(".widgets-container");const y=m.querySelector(".empty-tip");Observer.childList(m,()=>{if(m.childElementCount<=1){y.classList.add("show")}else{y.classList.remove("show")}});const h=document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");const E=document.querySelector(".gui-settings-icon-panel");E.addEventListener("mouseover",async()=>{const{loadTooltip:e}=await t.importAsync("settings-tooltip.loader");await e();await t.applyDropdownOptions();t.applyWidgets();raiseEvent(E,"be:load");raiseEvent(dq(".bilibili-evolved-about"),"be:about-load");(new n).setupDom();h.forEach(e=>e.classList.add("loaded"));o=[...document.querySelectorAll("input[key]")];c=o.filter(e=>e.type==="checkbox");r=o.filter(e=>e.type==="text"&&!e.parentElement.classList.contains("gui-settings-dropdown"));d();p();l();g();u();f();b();new i},{once:true})})()}})();
|
||||
@ -152,8 +152,15 @@ export class ResourceManager {
|
||||
// }
|
||||
this.applyReloadables() // reloadables run sync
|
||||
// await this.applyDropdownOptions();
|
||||
this.applyWidgets() // No need to wait the widgets
|
||||
this.checkUpdates(!isCacheValid)
|
||||
// this.applyWidgets() // No need to wait the widgets
|
||||
if (!isOffline()) {
|
||||
const checkUpdates = () => this.checkUpdates(!isCacheValid)
|
||||
if ('requestIdleCallback' in window) {
|
||||
window.requestIdleCallback(checkUpdates)
|
||||
} else {
|
||||
fullyLoaded(checkUpdates)
|
||||
}
|
||||
}
|
||||
}
|
||||
applyReloadables () {
|
||||
const checkAttribute = (key, attributes) => {
|
||||
@ -218,66 +225,67 @@ export class ResourceManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
async checkUpdates (fullDownload) {
|
||||
async checkUpdates () {
|
||||
if (isOffline()) {
|
||||
return
|
||||
}
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
|
||||
const getHash = async (message) => {
|
||||
const msgUint8 = new TextEncoder().encode(message)
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8)
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('')
|
||||
return hashHex
|
||||
}
|
||||
if (fullDownload) {
|
||||
const url = Resource.root + 'min/bundle.zip'
|
||||
const zip = new JSZip()
|
||||
await zip.loadAsync(await Ajax.monkey({
|
||||
url,
|
||||
responseType: 'blob',
|
||||
}))
|
||||
zip.forEach((filename, file) => {
|
||||
const url = Resource.root + 'min/' + filename
|
||||
const resource = Object.values(Resource.all).find(it => it.rawUrl === url)
|
||||
if (resource) {
|
||||
file.async('text').then(text => {
|
||||
settings.cache = Object.assign(settings.cache, {
|
||||
[resource.key]: text
|
||||
})
|
||||
getHash(text).then(hash => console.log(`full download: saved ${resource.key} (${hash})`))
|
||||
// const getHash = async (message) => {
|
||||
// const msgUint8 = new TextEncoder().encode(message)
|
||||
// const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8)
|
||||
// const hashArray = Array.from(new Uint8Array(hashBuffer))
|
||||
// const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('')
|
||||
// return hashHex
|
||||
// }
|
||||
// if (fullDownload) {
|
||||
const url = Resource.root + 'min/bundle.zip'
|
||||
const zip = new JSZip()
|
||||
await zip.loadAsync(await Ajax.monkey({
|
||||
url,
|
||||
responseType: 'blob',
|
||||
}))
|
||||
zip.forEach((filename, file) => {
|
||||
const url = Resource.root + 'min/' + filename
|
||||
const resource = Object.values(Resource.all).find(it => it.rawUrl === url)
|
||||
if (resource) {
|
||||
file.async('text').then(text => {
|
||||
settings.cache = Object.assign(settings.cache, {
|
||||
[resource.key]: text
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const hashJson = await Ajax.monkey({
|
||||
url: Resource.root + 'min/bundle.json',
|
||||
responseType: 'json',
|
||||
})
|
||||
const scriptHashWrap = h => `(()=>{return${h}})();`
|
||||
await Promise.all(Object.entries(hashJson).map(async ([name, hash]) => {
|
||||
const url = Resource.root + 'min/' + name
|
||||
const resource = Object.values(Resource.all).find(it => it.rawUrl === url)
|
||||
if (!resource) {
|
||||
return
|
||||
}
|
||||
const cache = settings.cache[resource.key]
|
||||
if (cache) {
|
||||
const cacheHash = await getHash(cache)
|
||||
if (cacheHash.toLowerCase() !== hash.toLowerCase() &&
|
||||
scriptHashWrap(cacheHash).toLowerCase() !== hash.toLowerCase()) {
|
||||
console.log(`hash not match: ${resource.key} (${cacheHash.toLowerCase()}) !== (${hash.toLowerCase()})`)
|
||||
await resource.download()
|
||||
settings.cache = Object.assign(settings.cache, {
|
||||
[resource.key]: resource.text
|
||||
})
|
||||
console.log(`downloaded ${resource.key}`)
|
||||
} else {
|
||||
console.log(`checked hash: ${resource.key}`)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
// getHash(text).then(hash => console.log(`full download: saved ${resource.key} (${hash})`))
|
||||
console.log(`bundle update: saved ${resource.key}`)
|
||||
})
|
||||
}
|
||||
})
|
||||
// } else {
|
||||
// const hashJson = await Ajax.monkey({
|
||||
// url: Resource.root + 'min/bundle.json',
|
||||
// responseType: 'json',
|
||||
// })
|
||||
// const scriptHashWrap = h => `(()=>{return${h}})();`
|
||||
// await Promise.all(Object.entries(hashJson).map(async ([name, hash]) => {
|
||||
// const url = Resource.root + 'min/' + name
|
||||
// const resource = Object.values(Resource.all).find(it => it.rawUrl === url)
|
||||
// if (!resource) {
|
||||
// return
|
||||
// }
|
||||
// const cache = settings.cache[resource.key]
|
||||
// if (cache) {
|
||||
// const cacheHash = await getHash(cache)
|
||||
// if (cacheHash.toLowerCase() !== hash.toLowerCase() &&
|
||||
// scriptHashWrap(cacheHash).toLowerCase() !== hash.toLowerCase()) {
|
||||
// console.log(`hash not match: ${resource.key} (${cacheHash.toLowerCase()}) !== (${hash.toLowerCase()})`)
|
||||
// await resource.download()
|
||||
// settings.cache = Object.assign(settings.cache, {
|
||||
// [resource.key]: resource.text
|
||||
// })
|
||||
// console.log(`downloaded ${resource.key}`)
|
||||
// } else {
|
||||
// console.log(`checked hash: ${resource.key}`)
|
||||
// }
|
||||
// }
|
||||
// }))
|
||||
// }
|
||||
|
||||
}
|
||||
async applyWidget (info) {
|
||||
|
||||
@ -155,6 +155,7 @@ function setDisplayNames () {
|
||||
const { loadTooltip } = await import('./tooltip/settings-tooltip.loader')
|
||||
await loadTooltip()
|
||||
await resources.applyDropdownOptions()
|
||||
resources.applyWidgets()
|
||||
raiseEvent(iconPanel, 'be:load')
|
||||
raiseEvent(dq('.bilibili-evolved-about'), 'be:about-load')
|
||||
new ThemeColors().setupDom()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user