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
|
||||
}
|
||||
|
||||
const getIntro = () => {
|
||||
return fs.readFileSync("./src/intro.js", "utf-8")
|
||||
const getWrapper = (startL, endL) => {
|
||||
const js = fs.readFileSync("./src/wrapper.js", "utf-8")
|
||||
return js.split(/\n/g).slice(startL, endL).join("\n")
|
||||
}
|
||||
|
||||
const basePlugins = [
|
||||
|
@ -87,8 +88,8 @@ export default [
|
|||
format: "iife",
|
||||
sourcemap: false,
|
||||
banner: getBannerText,
|
||||
intro: getIntro,
|
||||
outro: "}.toString() + ')()');document.body.prepend(d)})"
|
||||
intro: () => getWrapper(0, -1),
|
||||
outro: () => getWrapper(-1)
|
||||
},
|
||||
plugins,
|
||||
},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable */
|
||||
const w = typeof unsafeWindow == 'object' ? unsafeWindow : window;
|
||||
|
||||
// GM APIs glue
|
||||
|
@ -38,3 +39,6 @@ new Promise(resolve => {
|
|||
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}'];delete window['${gmId}'];(` + function a () {
|
||||
/** script code here */
|
||||
|
||||
}.toString() + ')()');document.body.prepend(d)})
|
Loading…
Reference in a new issue