musescore-downloader/src/wrapper.js

44 lines
1.4 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(
'** 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
// get rid of `Disable Tampermonkey`
const observer = new MutationObserver((mutations) => {
mutations.forEach(x => [...x.addedNodes].forEach(e => {
if (!document.querySelector('.js-page')) {
e.replaceWith(...x.removedNodes)
}
}))
})
observer.observe(document, { childList: true, subtree: true })
2020-12-06 07:21:33 +00:00
// script loader
new Promise(resolve => {
const id = '' + Math.random();
w[id] = resolve;
2020-12-06 07:35:08 +00:00
setTimeout(`(function a(){window['${id}'](new Image());delete window['${id}'];})()//# sourceURL=${location.href}`)
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 */
}.toString() + ')()');document.body.prepend(d)})