From aff6cc1c2af632b7568df4a0393f014810b377af Mon Sep 17 00:00:00 2001 From: msojocs Date: Sun, 10 Sep 2023 13:51:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=BC=AB=E6=B8=B8=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E6=B2=A1=E6=9C=89=E5=8A=A0=E8=BD=BD=E5=87=BA?= =?UTF-8?q?=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.MD | 8 + extensions/area_unlimit/hook.js | 25 +- extensions/area_unlimit/hook/biliapp.js | 359 ++++++++++++++++++++++++ extensions/area_unlimit/hook/common.js | 6 +- extensions/area_unlimit/hook/index.js | 357 ----------------------- extensions/area_unlimit/hook/load.js | 28 -- extensions/area_unlimit/manifest.json | 24 +- 7 files changed, 406 insertions(+), 401 deletions(-) delete mode 100644 extensions/area_unlimit/hook/index.js diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 9fbed63..b486383 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,3 +1,11 @@ +# 🌈 v1.11.4-4 / 2023-09-10 + +## 🐞 修复 +- settings: 漫游设置页面有概率无法加载 + +## 🚧 其它 +- extension: 优化扩展加载 + # 🌈 v1.11.4-3 / 2023-09-03 ## 🐞 修复 diff --git a/extensions/area_unlimit/hook.js b/extensions/area_unlimit/hook.js index c03489b..ccd6146 100644 --- a/extensions/area_unlimit/hook.js +++ b/extensions/area_unlimit/hook.js @@ -18,6 +18,7 @@ const URLS = { // 首页搜索iframe window.onload = () => { + // const appIframe = document.getElementById('bili-app') // if (appIframe == null) { // console.warn('应用主界面元素未找到!') @@ -49,24 +50,24 @@ window.onload = () => { } -var loadJS = document.createElement('script'); -loadJS.src = URLS.load; -(document.head || document.documentElement).appendChild(loadJS); -loadJS.onload = function () { - loadJS.remove(); -}; +// var loadJS = document.createElement('script'); +// loadJS.src = URLS.load; +// (document.head || document.documentElement).appendChild(loadJS); +// loadJS.onload = function () { +// loadJS.remove(); +// }; var commonJS = document.createElement('script'); commonJS.src = URLS.commonJS; (document.head || document.documentElement).appendChild(commonJS); -commonJS.onload = function () { - commonJS.remove(); -}; +// commonJS.onload = function () { +// commonJS.remove(); +// }; var md5JS = document.createElement('script'); md5JS.src = URLS.md5; (document.head || document.documentElement).appendChild(md5JS); -md5JS.onload = function () { - md5JS.remove(); -}; +// md5JS.onload = function () { +// md5JS.remove(); +// }; // var s = document.createElement('script'); // s.src = chrome.extension.getURL(`hook/${fileName}.js`); diff --git a/extensions/area_unlimit/hook/biliapp.js b/extensions/area_unlimit/hook/biliapp.js index 5bd44a4..7e5ec7d 100644 --- a/extensions/area_unlimit/hook/biliapp.js +++ b/extensions/area_unlimit/hook/biliapp.js @@ -1,4 +1,363 @@ + +(() => { + console.log("[hook]: index.js"); + const HTTP_INDEX = { + get(url) { + return new Promise((resolve, reject) => { + const Http = new XMLHttpRequest() + Http.open('GET', url) + Http.send() + Http.onloadend = e => { + resolve(Http) + } + Http.onerror = e => reject + }) + } + } + function switchPage(hash, targetWindow = window) { + console.log('switch to:', hash) + // 菜单切换 + const menuDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper > div.header_slot.flex_start.drag").querySelector('.vui_tabs--nav-link') + for (let h3 of menuDiv.children) { + if (h3.dataset.hash === hash) + h3.style.setProperty('color', 'var(--el-text-color-primary)', 'important') + else + h3.style.setProperty('color', 'gray', 'important') + } + + // 界面切换 + const appSettingDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper") + + for (let page of appSettingDiv.children) { + page.dataset.hash && (page.style.display = page.dataset.hash === hash ? "" : "none") + } + } + + function addAreaLimit(targetWindow = window) { + console.log("addAreaLimit", targetWindow) + const url = new URL(targetWindow.location.href) + + // 菜单 + const menuDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper > div.header_slot.flex_start.drag").querySelector('.vui_tabs--nav-link') + if (menuDiv.children.length === 2) return; + menuDiv.children[0].dataset.hash = url.hash + const areaLimitH3 = targetWindow.document.createElement('h3'); + areaLimitH3.textContent = "漫游" + areaLimitH3.dataset.hash = "#/page/areaLimit" + areaLimitH3.style.setProperty('color', 'gray', 'important') + areaLimitH3.style.marginLeft = '5px' + areaLimitH3.classList.add(...menuDiv.children[0].classList) + menuDiv.appendChild(areaLimitH3) + for (let menu of menuDiv.children) { + menu.classList.add('area_limit') + menu.onclick = (e) => { + console.log('click: ', e) + switchPage(e.target.dataset.hash, targetWindow) + } + } + + // 界面 + const appSettingDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper") + appSettingDiv.children[1].dataset.hash = url.hash + const areaLimitPage = targetWindow.document.createElement('div') + areaLimitPage.style.display = 'none' + areaLimitPage.dataset.hash = "#/page/areaLimit" + areaLimitPage.classList.add(...appSettingDiv.children[1].classList) + appSettingDiv.appendChild(areaLimitPage); + const loadStatus = targetWindow.document.createElement('span') + loadStatus.style.color = "red" + loadStatus.style.fontSize = "xxx-large" + areaLimitPage.appendChild(loadStatus) + + function createVueJS() { + let e = targetWindow.document.createElement('script'); + e.src = "https://lib.baomitu.com/vue/3.2.31/vue.global.prod.min.js"; + return e + } + + function createElementPlusJS() { + let e = targetWindow.document.createElement('script'); + e.src = "https://lib.baomitu.com/element-plus/2.2.0/index.full.min.js"; + return e + } + let vue = createVueJS() + loadStatus.textContent = "[1/2]加载vue" + vue.onerror = (e) => { + console.error('vue加载失败', e) + const reload = targetWindow.document.createElement('button') + reload.textContent = "重载vue" + reload.className = "vui_button about-button mr_sm" + reload.onclick = () => { + vue.remove() + let vueNew = createVueJS() + vueNew.onload = vue.onload + vueNew.onerror = vue.onerror + appSettingDiv.prepend(vueNew) + reload.remove() + } + loadStatus.append(reload) + } + appSettingDiv.prepend(vue) + + let ele = createElementPlusJS() + ele.onerror = (e) => { + const reload = targetWindow.document.createElement('button') + reload.textContent = "重载ele" + reload.className = "vui_button about-button mr_sm" + reload.onclick = function () { + ele.remove() + let eleNew = createElementPlusJS() + eleNew.onload = ele.onload + eleNew.onerror = ele.onerror + reload.remove() + appSettingDiv.prepend(eleNew) + } + + loadStatus.append(reload) + } + vue.onload = (e) => { + console.log('vue.onload', e) + loadStatus.textContent = "[2/2]加载element-plus" + loadStatus.children.length === 1 && loadStatus.children[0].remove() + ele.onerror() + appSettingDiv.prepend(ele) + } + + document.addEventListener('ROAMING_sendURL', async function (e) { + // e.detail contains the transferred data (can be anything, ranging + // from JavaScript objects to strings). + // Do something, for example: + console.log('index ROAMING_sendURL:', e.detail); + if(e.detail.includes("RoamingPage")){ + // 判断HTML为漫游页面 + const roamingHTML = await HTTP_INDEX.get(e.detail) + const container = targetWindow.document.createElement('div') + + container.innerHTML = roamingHTML.responseText + areaLimitPage.appendChild(container) + + ele.onload = () => { + loadStatus.textContent = "" + createRoamingPage(targetWindow) + } + } + }); + // 获取漫游HTML + console.log('获取漫游HTML') + document.dispatchEvent(new CustomEvent('ROAMING_getURL', { + detail: 'RoamingPage' // Some variable from Gmail. + })); + } + + // vue + function createRoamingPage(targetWindow = window) { + console.log('RoamingPage HTML') + const App = { + data() { + return { + message: "Hello Element Plus", + uposList: [{ + value: 'none', + label: '不替换' + }, + { + value: 'ks3', + label: 'ks3(金山)' + }, + { + value: 'kodo', + label: 'kodo(七牛)' + }, + { + value: 'cos', + label: 'cos(腾讯)' + }, + { + value: 'bos', + label: 'bos(百度)' + }, + { + value: 'wcs', + label: 'wcs(网宿)' + }, + { + value: 'hw', + label: 'hw(251)' + }, + ], + uposKey: localStorage.upos || 'none', + replaceAkamai: localStorage.replaceAkamai === "true", + pacLink: localStorage.pacLink || "", + serverList: { + default: '', + mainLand: '', + hk: '', + tw: '', + th: '' + }, + serverRule: { + default: [{ + validator: this.checkDomain, + trigger: 'blur', + }, ], + mainLand: [{ + validator: this.checkDomain, + }, ], + hk: [{ + validator: this.checkDomain, + trigger: 'blur', + }, ], + tw: [{ + validator: this.checkDomain, + trigger: 'blur', + }, ], + th: [{ + validator: this.checkDomain, + trigger: 'blur', + }, ] + } + }; + }, + created() { + console.log('vue created') + const serverList = JSON.parse(localStorage.serverList || "{}") + for (let area in serverList) { + this.serverList[area] = serverList[area] + } + }, + methods: { + changeUPOS: function (upos) { + // console.log('upos change: ', upos) + localStorage.upos = upos + this.$notify({ + title: 'Success', + message: "成功", + type: 'success' + }) + }, + changeReplaceAkamai: function () { + this.$notify({ + title: 'Success', + message: "成功", + type: 'success' + }) + localStorage.replaceAkamai = this.replaceAkamai ? 'true' : 'false' + }, + changePACLink: function () { + localStorage.pacLink = this.pacLink + if (this.pacLink && this.pacLink.length > 0) { + let result = biliBridgePc.callNativeSync('config/roamingPAC', this.pacLink) + if (result === 'error') + this.$notify({ + title: 'Success', + message: "失败", + type: 'error' + }) + else + this.$notify({ + title: 'Success', + message: "成功", + type: 'success' + }) + } else + this.$notify({ + title: 'Success', + message: "成功", + type: 'success' + }) + }, + saveServer: function (formEl) { + if (!formEl) return + console.log('saveServer: ', formEl, this.$refs) + this.$refs.serverFormRef.validate((valid) => { + if (valid) { + // console.log(this.serverList) + this.$notify({ + title: 'Success', + message: "成功", + type: 'success' + }) + localStorage.serverList = JSON.stringify(this.serverList) + } else { + console.log('error submit!') + return false + } + }) + }, + checkDomain: (rule, value, callback) => { + // console.log(rule, value) + if ((value || "") === "") + callback() + else if (!/^(?=^.{3,255}$)[a-zA-Z0-9\u4e00-\u9fa5][-a-zA-Z0-9\u4e00-\u9fa5]{0,62}(\.[a-zA-Z0-9\u4e00-\u9fa5][-a-zA-Z0-9\u4e00-\u9fa5]{0,62})+$/.test(value)) { + callback(new Error("域名校验失败")) + } + callback() + }, + resetForm: function (formEl) { + // console.log('resetForm: ', formEl) + if (!formEl) return + formEl.resetFields() + } + } + }; + const app = targetWindow.Vue.createApp(App); + app.use(targetWindow.ElementPlus); + app.mount("#roamingApp"); + } + // window.addEventListener('replaceState', function (e) { + // // console.log('change replaceState', e); + // if(e.arguments[0].current === "/page/settings"){ + // addAreaLimit() + // } + // }); + const targetOnload = (targetWindow = window)=>{ + const url = new URL(targetWindow.location.href) + + // 监听hash值变动 + const _historyWrap = function (type) { + const orig = targetWindow.history[type]; + const e = new Event(type); + return function () { + const rv = orig.apply(this, arguments); + e.arguments = arguments; + targetWindow.dispatchEvent(e); + return rv; + }; + }; + targetWindow.history.pushState = _historyWrap('pushState'); + targetWindow.history.replaceState = _historyWrap('replaceState'); + + /** + * 前提:默认页面为「推荐」 + * 操作:切换到设置 + * pushState: 有响应,但太快,需要延时处理 + * replaceState:无响应,但之后的切换都有响应且能直接取到元素 + */ + targetWindow.addEventListener('pushState', function (e) { + console.log('change pushState', e); + if (e.arguments[0].current === "/page/settings") { + // 延时,太快取不到页面元素 + setTimeout(addAreaLimit, 500, targetWindow) + } + }); + + if (url.hash === "#/page/settings") { + setTimeout(addAreaLimit, 500, targetWindow) + } + } + + console.log('hook state change') + if (document.readyState === 'complete' || document.readyState === 'interactive') { + targetOnload(window) + } + else { + console.error('页面似乎没有加载完成') + window.onload = targetOnload + } +})(); + try { + window.hex_md5 = parent?.hex_md5 window.getHookXMLHttpRequest = parent?.getHookXMLHttpRequest if (window.getHookXMLHttpRequest && undefined === window.XMLHttpRequest.isHooked) { diff --git a/extensions/area_unlimit/hook/common.js b/extensions/area_unlimit/hook/common.js index 4eefc2c..4dfa5b3 100644 --- a/extensions/area_unlimit/hook/common.js +++ b/extensions/area_unlimit/hook/common.js @@ -716,7 +716,7 @@ window.getHookXMLHttpRequest = (win) => { return win.XMLHttpRequest } return class HttpRequest extends win.XMLHttpRequest { - get isHooked () { + static get isHooked () { return true } constructor() { @@ -729,13 +729,17 @@ window.getHookXMLHttpRequest = (win) => { this._onreadystatechange = null; this._onloadend = null; + this._onload = null; super.onloadend = async () => { if (this._onloadend) { if (URL_HOOK[this._url]) await URL_HOOK[this._url](this) this._onloadend(); } }; + let test = 0 super.onload = async () => { + test++ + if (test > 10)debugger if (this._onload) { console.log('onload', this._url) if (URL_HOOK[this._url]) await URL_HOOK[this._url](this) diff --git a/extensions/area_unlimit/hook/index.js b/extensions/area_unlimit/hook/index.js deleted file mode 100644 index bc32889..0000000 --- a/extensions/area_unlimit/hook/index.js +++ /dev/null @@ -1,357 +0,0 @@ - -(() => { - console.log("[hook]: index.js"); - const HTTP_INDEX = { - get(url) { - return new Promise((resolve, reject) => { - const Http = new XMLHttpRequest() - Http.open('GET', url) - Http.send() - Http.onloadend = e => { - resolve(Http) - } - Http.onerror = e => reject - }) - } - } - function switchPage(hash, targetWindow = window) { - console.log('switch to:', hash) - // 菜单切换 - const menuDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper > div.header_slot.flex_start.drag").querySelector('.vui_tabs--nav-link') - for (let h3 of menuDiv.children) { - if (h3.dataset.hash === hash) - h3.style.setProperty('color', 'var(--el-text-color-primary)', 'important') - else - h3.style.setProperty('color', 'gray', 'important') - } - - // 界面切换 - const appSettingDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper") - - for (let page of appSettingDiv.children) { - page.dataset.hash && (page.style.display = page.dataset.hash === hash ? "" : "none") - } - } - - function addAreaLimit(targetWindow = window) { - console.log("addAreaLimit", targetWindow) - const url = new URL(targetWindow.location.href) - - // 菜单 - const menuDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper > div.header_slot.flex_start.drag").querySelector('.vui_tabs--nav-link') - if (menuDiv.children.length === 2) return; - menuDiv.children[0].dataset.hash = url.hash - const areaLimitH3 = targetWindow.document.createElement('h3'); - areaLimitH3.textContent = "漫游" - areaLimitH3.dataset.hash = "#/page/areaLimit" - areaLimitH3.style.setProperty('color', 'gray', 'important') - areaLimitH3.style.marginLeft = '5px' - areaLimitH3.classList.add(...menuDiv.children[0].classList) - menuDiv.appendChild(areaLimitH3) - for (let menu of menuDiv.children) { - menu.classList.add('area_limit') - menu.onclick = (e) => { - console.log('click: ', e) - switchPage(e.target.dataset.hash, targetWindow) - } - } - - // 界面 - const appSettingDiv = targetWindow.document.querySelector("#app > div > div > div.app_layout--content.flex_col > div > div.app_settings.i_page_wrapper") - appSettingDiv.children[1].dataset.hash = url.hash - const areaLimitPage = targetWindow.document.createElement('div') - areaLimitPage.style.display = 'none' - areaLimitPage.dataset.hash = "#/page/areaLimit" - areaLimitPage.classList.add(...appSettingDiv.children[1].classList) - appSettingDiv.appendChild(areaLimitPage); - const loadStatus = targetWindow.document.createElement('span') - loadStatus.style.color = "red" - loadStatus.style.fontSize = "xxx-large" - areaLimitPage.appendChild(loadStatus) - - function createVueJS() { - let e = targetWindow.document.createElement('script'); - e.src = "https://lib.baomitu.com/vue/3.2.31/vue.global.prod.min.js"; - return e - } - - function createElementPlusJS() { - let e = targetWindow.document.createElement('script'); - e.src = "https://lib.baomitu.com/element-plus/2.2.0/index.full.min.js"; - return e - } - let vue = createVueJS() - loadStatus.textContent = "[1/2]加载vue" - vue.onerror = (e) => { - console.error('vue加载失败', e) - const reload = targetWindow.document.createElement('button') - reload.textContent = "重载vue" - reload.className = "vui_button about-button mr_sm" - reload.onclick = () => { - vue.remove() - let vueNew = createVueJS() - vueNew.onload = vue.onload - vueNew.onerror = vue.onerror - appSettingDiv.prepend(vueNew) - reload.remove() - } - loadStatus.append(reload) - } - appSettingDiv.prepend(vue) - - let ele = createElementPlusJS() - ele.onerror = (e) => { - const reload = targetWindow.document.createElement('button') - reload.textContent = "重载ele" - reload.className = "vui_button about-button mr_sm" - reload.onclick = function () { - ele.remove() - let eleNew = createElementPlusJS() - eleNew.onload = ele.onload - eleNew.onerror = ele.onerror - reload.remove() - appSettingDiv.prepend(eleNew) - } - - loadStatus.append(reload) - } - vue.onload = (e) => { - console.log('vue.onload', e) - loadStatus.textContent = "[2/2]加载element-plus" - loadStatus.children.length === 1 && loadStatus.children[0].remove() - ele.onerror() - appSettingDiv.prepend(ele) - } - - document.addEventListener('ROAMING_sendURL', async function (e) { - // e.detail contains the transferred data (can be anything, ranging - // from JavaScript objects to strings). - // Do something, for example: - console.log('index ROAMING_sendURL:', e.detail); - if(e.detail.includes("RoamingPage")){ - // 判断HTML为漫游页面 - const roamingHTML = await HTTP_INDEX.get(e.detail) - const container = targetWindow.document.createElement('div') - - container.innerHTML = roamingHTML.responseText - areaLimitPage.appendChild(container) - - ele.onload = () => { - loadStatus.textContent = "" - createRoamingPage(targetWindow) - } - } - }); - // 获取漫游HTML - console.log('获取漫游HTML') - document.dispatchEvent(new CustomEvent('ROAMING_getURL', { - detail: 'RoamingPage' // Some variable from Gmail. - })); - } - - // vue - function createRoamingPage(targetWindow = window) { - console.log('RoamingPage HTML') - const App = { - data() { - return { - message: "Hello Element Plus", - uposList: [{ - value: 'none', - label: '不替换' - }, - { - value: 'ks3', - label: 'ks3(金山)' - }, - { - value: 'kodo', - label: 'kodo(七牛)' - }, - { - value: 'cos', - label: 'cos(腾讯)' - }, - { - value: 'bos', - label: 'bos(百度)' - }, - { - value: 'wcs', - label: 'wcs(网宿)' - }, - { - value: 'hw', - label: 'hw(251)' - }, - ], - uposKey: localStorage.upos || 'none', - replaceAkamai: localStorage.replaceAkamai === "true", - pacLink: localStorage.pacLink || "", - serverList: { - default: '', - mainLand: '', - hk: '', - tw: '', - th: '' - }, - serverRule: { - default: [{ - validator: this.checkDomain, - trigger: 'blur', - }, ], - mainLand: [{ - validator: this.checkDomain, - }, ], - hk: [{ - validator: this.checkDomain, - trigger: 'blur', - }, ], - tw: [{ - validator: this.checkDomain, - trigger: 'blur', - }, ], - th: [{ - validator: this.checkDomain, - trigger: 'blur', - }, ] - } - }; - }, - created() { - console.log('vue created') - const serverList = JSON.parse(localStorage.serverList || "{}") - for (let area in serverList) { - this.serverList[area] = serverList[area] - } - }, - methods: { - changeUPOS: function (upos) { - // console.log('upos change: ', upos) - localStorage.upos = upos - this.$notify({ - title: 'Success', - message: "成功", - type: 'success' - }) - }, - changeReplaceAkamai: function () { - this.$notify({ - title: 'Success', - message: "成功", - type: 'success' - }) - localStorage.replaceAkamai = this.replaceAkamai ? 'true' : 'false' - }, - changePACLink: function () { - localStorage.pacLink = this.pacLink - if (this.pacLink && this.pacLink.length > 0) { - let result = biliBridgePc.callNativeSync('config/roamingPAC', this.pacLink) - if (result === 'error') - this.$notify({ - title: 'Success', - message: "失败", - type: 'error' - }) - else - this.$notify({ - title: 'Success', - message: "成功", - type: 'success' - }) - } else - this.$notify({ - title: 'Success', - message: "成功", - type: 'success' - }) - }, - saveServer: function (formEl) { - if (!formEl) return - console.log('saveServer: ', formEl, this.$refs) - this.$refs.serverFormRef.validate((valid) => { - if (valid) { - // console.log(this.serverList) - this.$notify({ - title: 'Success', - message: "成功", - type: 'success' - }) - localStorage.serverList = JSON.stringify(this.serverList) - } else { - console.log('error submit!') - return false - } - }) - }, - checkDomain: (rule, value, callback) => { - // console.log(rule, value) - if ((value || "") === "") - callback() - else if (!/^(?=^.{3,255}$)[a-zA-Z0-9\u4e00-\u9fa5][-a-zA-Z0-9\u4e00-\u9fa5]{0,62}(\.[a-zA-Z0-9\u4e00-\u9fa5][-a-zA-Z0-9\u4e00-\u9fa5]{0,62})+$/.test(value)) { - callback(new Error("域名校验失败")) - } - callback() - }, - resetForm: function (formEl) { - // console.log('resetForm: ', formEl) - if (!formEl) return - formEl.resetFields() - } - } - }; - const app = targetWindow.Vue.createApp(App); - app.use(targetWindow.ElementPlus); - app.mount("#roamingApp"); - } - // window.addEventListener('replaceState', function (e) { - // // console.log('change replaceState', e); - // if(e.arguments[0].current === "/page/settings"){ - // addAreaLimit() - // } - // }); - const targetOnload = (targetWindow = window)=>{ - const url = new URL(targetWindow.location.href) - - // 监听hash值变动 - const _historyWrap = function (type) { - const orig = targetWindow.history[type]; - const e = new Event(type); - return function () { - const rv = orig.apply(this, arguments); - e.arguments = arguments; - targetWindow.dispatchEvent(e); - return rv; - }; - }; - targetWindow.history.pushState = _historyWrap('pushState'); - targetWindow.history.replaceState = _historyWrap('replaceState'); - - /** - * 前提:默认页面为「推荐」 - * 操作:切换到设置 - * pushState: 有响应,但太快,需要延时处理 - * replaceState:无响应,但之后的切换都有响应且能直接取到元素 - */ - targetWindow.addEventListener('pushState', function (e) { - console.log('change pushState', e); - if (e.arguments[0].current === "/page/settings") { - // 延时,太快取不到页面元素 - setTimeout(addAreaLimit, 500, targetWindow) - } - }); - - if (url.hash === "#/page/settings") { - setTimeout(addAreaLimit, 500, targetWindow) - } - } - // 获取App的Iframe - const appFrame = document.getElementById('bili-app') - const appWindow = appFrame.contentWindow - if (appWindow.document.readyState === 'complete' || appWindow.document.readyState === 'interactive') { - targetOnload(appWindow) - } - else { - console.error('页面似乎没有加载完成') - } -})(); diff --git a/extensions/area_unlimit/hook/load.js b/extensions/area_unlimit/hook/load.js index ae43d92..90b1f25 100644 --- a/extensions/area_unlimit/hook/load.js +++ b/extensions/area_unlimit/hook/load.js @@ -57,34 +57,6 @@ console.warn('[hook]: 未找到脚本', fileName) } } - { - const list = document.querySelectorAll('iframe') - console.log(window) - console.log('[hook]:', `${fileName} 下的iframe数量:${list.length}`, document) - for (const item of list) { - console.log('[hook]: 给元素添加load脚本', item.id, `link->${item.src}<-`, item) - const w = item.contentWindow - const insertLoad = () => { - console.log('插入load脚本') - const loadJS = w.document.createElement('script'); - loadJS.src = win.URLS.load; - (w.document.head || w.document.documentElement).appendChild(loadJS); - loadJS.onload = () => { - console.log(w.document.querySelectorAll('iframe')) - } - item.removeEventListener('load', insertLoad) - } - if (w.document.readyState === 'complete' || w.document.readyState === 'interactive') { - console.log('iframe已经加载完成') - insertLoad() - } - else { - console.log('iframe未加载完', w.document.readyState) - item.addEventListener('load', insertLoad) - } - } - } - } let interval = setInterval(() => { if (document.readyState === 'complete' || document.readyState === 'interactive') { diff --git a/extensions/area_unlimit/manifest.json b/extensions/area_unlimit/manifest.json index 09ae2b0..05a51dd 100644 --- a/extensions/area_unlimit/manifest.json +++ b/extensions/area_unlimit/manifest.json @@ -9,13 +9,31 @@ "matches": [ "" ], - "js": [ - "hook.js" - ], "css": [ "hook/common.css" ], "run_at": "document_start" + }, + { + "matches": [ + "" + ], + "js": [ + "hook.js", + "hook/load.js" + ], + "run_at": "document_start", + "all_frames": true + }, + { + "matches": [ + "" + ], + "js": [ + "hook/common.js" + ], + "run_at": "document_start", + "all_frames": true } ], "web_accessible_resources": [