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

View file

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