1.0
This commit is contained in:
40
tampermonkey-emulator.js
Normal file
40
tampermonkey-emulator.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// tampermonkey-emulator.js
|
||||
|
||||
// 模拟 GM_addStyle
|
||||
window.GM_addStyle = function(css) {
|
||||
const style = document.createElement('style');
|
||||
style.textContent = css;
|
||||
document.head.appendChild(style);
|
||||
};
|
||||
|
||||
// 模拟 GM_xmlhttpRequest
|
||||
window.GM_xmlhttpRequest = function(opts) {
|
||||
fetch(opts.url, {
|
||||
method: opts.method || 'GET',
|
||||
headers: opts.headers || {},
|
||||
body: opts.data || null,
|
||||
mode: 'cors',
|
||||
credentials: 'include'
|
||||
}).then(res => res.text()).then(text => {
|
||||
if (opts.onload) opts.onload({ status: 200, responseText: text });
|
||||
}).catch(err => {
|
||||
if (opts.onerror) opts.onerror(err);
|
||||
});
|
||||
};
|
||||
|
||||
// 模拟 unsafeWindow(直接指向 window)
|
||||
window.unsafeWindow = window;
|
||||
|
||||
// 模拟 @run-at document-end
|
||||
function runUserScript1() {
|
||||
// 这里动态加载原始脚本
|
||||
const script = document.createElement('script');
|
||||
script.src = '/auto.js'; // 原始脚本,不改
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', runUserScript1);
|
||||
} else {
|
||||
runUserScript1();
|
||||
}
|
||||
Reference in New Issue
Block a user