refactor: script wrapper
This commit is contained in:
parent
05e147a03c
commit
f6b8ab4413
2 changed files with 9 additions and 4 deletions
|
@ -15,8 +15,9 @@ const getBannerText = () => {
|
||||||
return bannerText
|
return bannerText
|
||||||
}
|
}
|
||||||
|
|
||||||
const getIntro = () => {
|
const getWrapper = (startL, endL) => {
|
||||||
return fs.readFileSync("./src/intro.js", "utf-8")
|
const js = fs.readFileSync("./src/wrapper.js", "utf-8")
|
||||||
|
return js.split(/\n/g).slice(startL, endL).join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
const basePlugins = [
|
const basePlugins = [
|
||||||
|
@ -87,8 +88,8 @@ export default [
|
||||||
format: "iife",
|
format: "iife",
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
banner: getBannerText,
|
banner: getBannerText,
|
||||||
intro: getIntro,
|
intro: () => getWrapper(0, -1),
|
||||||
outro: "}.toString() + ')()');document.body.prepend(d)})"
|
outro: () => getWrapper(-1)
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable */
|
||||||
const w = typeof unsafeWindow == 'object' ? unsafeWindow : window;
|
const w = typeof unsafeWindow == 'object' ? unsafeWindow : window;
|
||||||
|
|
||||||
// GM APIs glue
|
// GM APIs glue
|
||||||
|
@ -38,3 +39,6 @@ new Promise(resolve => {
|
||||||
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
||||||
d.once = false;
|
d.once = false;
|
||||||
d.setAttribute('onload', `if(this.once)return;this.once=true;this.remove();const GM=window['${gmId}'];delete window['${gmId}'];(` + function a () {
|
d.setAttribute('onload', `if(this.once)return;this.once=true;this.remove();const GM=window['${gmId}'];delete window['${gmId}'];(` + function a () {
|
||||||
|
/** script code here */
|
||||||
|
|
||||||
|
}.toString() + ')()');document.body.prepend(d)})
|
Loading…
Reference in a new issue