musescore-downloader/src/wrapper.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-12-06 07:49:55 +00:00
/* eslint-disable */
2020-12-06 07:21:33 +00:00
const w = typeof unsafeWindow == 'object' ? unsafeWindow : window;
// GM APIs glue
const _GM = typeof GM == 'object' ? GM : undefined;
const gmId = '' + Math.random();
w[gmId] = _GM;
2020-12-06 07:22:54 +00:00
if (_GM && _GM.registerMenuCommand && _GM.openInTab) {
// add buttons to the userscript manager menu
_GM.registerMenuCommand(
`** Version: ${_GM.info.script.version} **`,
() => _GM.openInTab("https://github.com/Xmader/musescore-downloader/releases", { active: true })
)
_GM.registerMenuCommand(
2020-12-06 07:22:54 +00:00
'** Source Code **',
() => _GM.openInTab(_GM.info.script.homepage, { active: true })
)
2020-12-06 07:25:26 +00:00
_GM.registerMenuCommand(
'** Discord **',
() => _GM.openInTab("https://discord.gg/DKu7cUZ4XQ", { active: true })
)
2020-12-06 07:22:54 +00:00
}
2020-12-06 07:21:33 +00:00
2020-12-09 16:22:09 +00:00
function getRandL () {
return String.fromCharCode(97 + Math.floor(Math.random() * 26))
}
2020-12-06 07:21:33 +00:00
// script loader
new Promise(resolve => {
const id = '' + Math.random();
w[id] = resolve;
2020-12-08 19:36:31 +00:00
const stackN = 9
2020-12-09 16:22:09 +00:00
let loaderIntro = ''
for (let i = 0; i < stackN; i++) {
loaderIntro += `(function ${getRandL()}(){`
}
2020-12-08 19:36:31 +00:00
const loaderOutro = '})()'.repeat(stackN)
const mockUrl = "https://c.amazon-adsystem.com/aax2/apstag.js"
setTimeout(`${loaderIntro}const d=new Image();window['${id}'](d);delete window['${id}'];document.body.prepend(d)${loaderOutro}//# sourceURL=${mockUrl}`)
2020-12-06 07:21:33 +00:00
}).then(d => {
d.style.display = 'none';
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
d.once = false;
2020-12-06 07:35:08 +00:00
d.setAttribute('onload', `if(this.once)return;this.once=true;this.remove();const GM=window['${gmId}'];delete window['${gmId}'];(` + function a () {
2020-12-06 07:49:55 +00:00
/** script code here */
2020-12-08 19:36:31 +00:00
}.toString() + ')()')})