refactor: script wrapper

This commit is contained in:
Xmader 2020-12-06 02:49:55 -05:00
parent 05e147a03c
commit f6b8ab4413
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
2 changed files with 9 additions and 4 deletions

View File

@ -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,
}, },

View File

@ -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)})