refactor: script load

This commit is contained in:
Xmader 2020-12-06 02:21:33 -05:00
parent 1831ffa7c8
commit 63bf02046a
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
2 changed files with 23 additions and 1 deletions

View File

@ -15,6 +15,10 @@ const getBannerText = () => {
return bannerText
}
const getIntro = () => {
return fs.readFileSync("./src/intro.js", "utf-8")
}
const basePlugins = [
typescript({
target: "ES6",
@ -83,7 +87,7 @@ export default [
format: "iife",
sourcemap: false,
banner: getBannerText,
intro: "const w=typeof unsafeWindow=='object'?unsafeWindow:window;const gmId=''+Math.random();w[gmId]=typeof GM=='object'?GM:undefined;new Promise(resolve=>{const id=''+Math.random();w[id]=resolve;setTimeout(`(function a(){window['${id}'](new Image())})()//# sourceURL=${location.href}`)}).then(d=>{d.style.display='none';d.src='data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';d.once=false;d.setAttribute('onload',`if(this.once)return;this.once=true;this.remove();const GM=window['${gmId}'];(` + function a () {",
intro: getIntro,
outro: "}.toString() + ')()');document.body.prepend(d)})"
},
plugins,

18
src/intro.js Normal file
View File

@ -0,0 +1,18 @@
const w = typeof unsafeWindow == 'object' ? unsafeWindow : window;
// GM APIs glue
const _GM = typeof GM == 'object' ? GM : undefined;
const gmId = '' + Math.random();
w[gmId] = _GM;
// script loader
new Promise(resolve => {
const id = '' + Math.random();
w[id] = resolve;
setTimeout(`(function a(){window['${id}'](new Image())})()//# sourceURL=${location.href}`)
}).then(d => {
d.style.display = 'none';
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
d.once = false;
d.setAttribute('onload', `if(this.once)return;this.once=true;this.remove();const GM=window['${gmId}'];(` + function a () {