-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
245 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,102 @@ | ||
console.log("=====HOOK=====") | ||
|
||
const url = new URL(location.href) | ||
const fileName = url.pathname.substring(1).split('.')[0] | ||
|
||
console.log("[hook]: hook.js", fileName) | ||
const ext = chrome.extension | ||
const URLS = { | ||
md5: chrome.extension.getURL(`utils/md5.js`), | ||
load: chrome.extension.getURL(`hook/load.js`), | ||
index: chrome.extension.getURL(`hook/index.js`), | ||
search: chrome.extension.getURL(`hook/search.js`), | ||
player: chrome.extension.getURL(`hook/player.js`), | ||
biliapp: chrome.extension.getURL(`hook/biliapp.js`), | ||
commonJS: chrome.extension.getURL(`hook/common.js`), | ||
commonCSS: chrome.extension.getURL(`hook/common.css`), | ||
RoamingPage: chrome.extension.getURL(`hook/RoamingPage.html`), | ||
PlayerEnhance: chrome.extension.getURL(`hook/PlayerEnhance.html`), | ||
} | ||
const commonJSURL = chrome.extension.getURL(`hook/common.js`); | ||
var s = document.createElement('script'); | ||
s.src = chrome.extension.getURL(`hook/${fileName}.js`); | ||
(document.head || document.documentElement).appendChild(s); | ||
s.onload = function () { | ||
s.remove(); | ||
}; | ||
|
||
// 首页搜索iframe | ||
window.onload = () => { | ||
console.log('search:', 'hook prepare') | ||
const appIframe = document.getElementById('bili-app') | ||
if (appIframe == null) { | ||
console.warn('搜索框元素未找到!') | ||
return | ||
} | ||
const appWindow = appIframe.contentWindow | ||
console.log('search:', 'appIframe.onload') | ||
let t = setInterval(() => { | ||
|
||
const searchIframe = appWindow.document.querySelector(".app_search").querySelector('iframe') | ||
if (searchIframe) { | ||
console.log('search:', 'searchIframe') | ||
const win = searchIframe.contentWindow | ||
console.log(win.location.href) | ||
const searchDocument = win.document | ||
var commonJS = searchDocument.createElement('script'); | ||
commonJS.src = URLS.commonJS; | ||
if (searchDocument.head || searchDocument.documentElement) { | ||
(searchDocument.head || searchDocument.documentElement).appendChild(commonJS); | ||
commonJS.onload = function () { | ||
commonJS.remove(); | ||
}; | ||
clearInterval(t) | ||
} | ||
} else { | ||
console.warn('search iframe not found') | ||
} | ||
}, 500) | ||
// const appIframe = document.getElementById('bili-app') | ||
// if (appIframe == null) { | ||
// console.warn('应用主界面元素未找到!') | ||
// return | ||
// } | ||
// const appWindow = appIframe.contentWindow | ||
// console.log('search:', 'appIframe.onload') | ||
// let t = setInterval(() => { | ||
// console.log('try to find app_search iframe') | ||
// const searchIframe = appWindow.document.querySelector(".app_search")?.querySelector('iframe') | ||
// if (searchIframe) { | ||
// console.log('search:', 'searchIframe') | ||
// const win = searchIframe.contentWindow | ||
// console.log(win.location.href) | ||
// const searchDocument = win.document | ||
// var commonJS = searchDocument.createElement('script'); | ||
// commonJS.src = URLS.commonJS; | ||
// if (searchDocument.head || searchDocument.documentElement) { | ||
// (searchDocument.head || searchDocument.documentElement).appendChild(commonJS); | ||
// commonJS.onload = function () { | ||
// commonJS.remove(); | ||
// }; | ||
// clearInterval(t) | ||
// } | ||
// } else { | ||
// console.warn('search iframe not found') | ||
// } | ||
// }, 500) | ||
|
||
} | ||
|
||
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 = commonJSURL; | ||
commonJS.src = URLS.commonJS; | ||
(document.head || document.documentElement).appendChild(commonJS); | ||
commonJS.onload = function () { | ||
commonJS.remove(); | ||
}; | ||
var md5JS = document.createElement('script'); | ||
md5JS.src = chrome.extension.getURL(`utils/md5.js`); | ||
md5JS.src = URLS.md5; | ||
(document.head || document.documentElement).appendChild(md5JS); | ||
md5JS.onload = function () { | ||
md5JS.remove(); | ||
}; | ||
|
||
var css = document.createElement('link'); | ||
css.rel = "stylesheet" | ||
css.href = chrome.extension.getURL(`/hook/common.css`); | ||
(document.head || document.documentElement).appendChild(css); | ||
// var s = document.createElement('script'); | ||
// s.src = chrome.extension.getURL(`hook/${fileName}.js`); | ||
// (document.head || document.documentElement).appendChild(s); | ||
// s.onload = function () { | ||
// s.remove(); | ||
// }; | ||
|
||
// var css = document.createElement('link'); | ||
// css.rel = "stylesheet" | ||
// css.href = URLS.commonCSS; | ||
// (document.head || document.documentElement).appendChild(css); | ||
|
||
// Event listener | ||
document.addEventListener('ROAMING_getURL', function (e) { | ||
// e.detail contains the transferred data (can be anything, ranging | ||
// from JavaScript objects to strings). | ||
// Do something, for example: | ||
console.log('hook ROAMING_getURL:', e.detail); | ||
const roamingPageURL = URLS[e.detail]; | ||
let data = null | ||
switch (e.detail) { | ||
case 'URLS': | ||
data = URLS | ||
break; | ||
default: | ||
data = URLS[e.detail]; | ||
break | ||
} | ||
document.dispatchEvent(new CustomEvent('ROAMING_sendURL', { | ||
detail: roamingPageURL // Some variable from Gmail. | ||
detail: data // Some variable from Gmail. | ||
})); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
try { | ||
window.hex_md5 = parent?.hex_md5 | ||
window.getHookXMLHttpRequest = parent?.getHookXMLHttpRequest | ||
if (window.getHookXMLHttpRequest && undefined === window.XMLHttpRequest.isHooked) { | ||
window.XMLHttpRequest = window.getHookXMLHttpRequest(window) | ||
} | ||
// debugger | ||
} | ||
catch (e) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
(() => { | ||
|
||
const url = new URL(location.href) | ||
const fileName = url.pathname.substring(1).split('.')[0] | ||
console.log("[hook]: load.js", fileName) | ||
|
||
const getData = (name) => { | ||
return new Promise((resolve, reject) => { | ||
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('player ROAMING_sendURL: ', e.detail); | ||
document.removeEventListener('ROAMING_sendURL', this) | ||
if (e.detail) | ||
resolve(e.detail) | ||
else | ||
reject(e) | ||
}); | ||
document.dispatchEvent(new CustomEvent('ROAMING_getURL', { | ||
detail: name // Some variable from Gmail. | ||
})); | ||
}) | ||
} | ||
|
||
// const loadFunc = { | ||
// index: () => { | ||
// getFileLink('index').then(r => { | ||
// | ||
// }) | ||
// } | ||
// } | ||
// if (loadFunc[fileName]) loadFunc[fileName]() | ||
|
||
const loadAction = async () => { | ||
console.log('[hook]: loadAction') | ||
const win = parent || window | ||
if (!win.URLS) { | ||
win.URLS = await getData('URLS') | ||
} | ||
console.log(fileName, 'onload', win.URLS) | ||
|
||
if (!window.URLS) | ||
window.URLS = win.URLS | ||
|
||
{ | ||
if (win.URLS[fileName]) { | ||
console.log('try to load script:', win.URLS[fileName]) | ||
const loadJS = document.createElement('script'); | ||
loadJS.src = win.URLS[fileName]; | ||
(document.head || document.documentElement).appendChild(loadJS); | ||
loadJS.onload = function () { | ||
loadJS.remove(); | ||
}; | ||
} | ||
else { | ||
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') { | ||
// 渲染完成 | ||
console.log('[hook]: 渲染完成,直接执行') | ||
// loadAction().then(_ => {}) | ||
loadAction().then(_ => {}) | ||
clearInterval(interval) | ||
} | ||
else { | ||
console.log('[hook]: 渲染未完成,监听执行', performance, performance.now(), performance.timing.domComplete, new Date(performance.timing.domComplete)) | ||
} | ||
}, 500) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
try { | ||
window.hex_md5 = parent?.hex_md5 | ||
window.getHookXMLHttpRequest = parent?.getHookXMLHttpRequest | ||
if (window.getHookXMLHttpRequest && undefined === window.XMLHttpRequest.isHooked) { | ||
window.XMLHttpRequest = window.getHookXMLHttpRequest(window) | ||
} | ||
// debugger | ||
} | ||
catch (e) { | ||
|
||
} |
Oops, something went wrong.