This commit is contained in:
Xmader 2020-11-10 14:33:20 -05:00
parent a5de589b6b
commit 5b4cb76f59
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
3 changed files with 40 additions and 18 deletions

54
dist/main.js vendored
View File

@ -5,7 +5,7 @@
// @supportURL https://github.com/Xmader/musescore-downloader/issues // @supportURL https://github.com/Xmader/musescore-downloader/issues
// @updateURL https://msdl.librescore.org/install.user.js // @updateURL https://msdl.librescore.org/install.user.js
// @downloadURL https://msdl.librescore.org/install.user.js // @downloadURL https://msdl.librescore.org/install.user.js
// @version 0.12.5 // @version 0.13.0
// @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱 // @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱
// @author Xmader // @author Xmader
// @match https://musescore.com/*/* // @match https://musescore.com/*/*
@ -26803,11 +26803,15 @@ Please pipe the document into a Node stream.\
} }
return btn; return btn;
}; };
var BtnListMode;
(function (BtnListMode) {
BtnListMode[BtnListMode["InPage"] = 0] = "InPage";
BtnListMode[BtnListMode["ExtWindow"] = 1] = "ExtWindow";
})(BtnListMode || (BtnListMode = {}));
class BtnList { class BtnList {
constructor(getTemplateBtn) { constructor(getTemplateBtn) {
this.getTemplateBtn = getTemplateBtn; this.getTemplateBtn = getTemplateBtn;
this.list = []; this.list = [];
this.antiDetectionText = 'Download';
} }
add(options) { add(options) {
const btn = this.getTemplateBtn().cloneNode(true); const btn = this.getTemplateBtn().cloneNode(true);
@ -26831,15 +26835,18 @@ Please pipe the document into a Node stream.\
} }
return btn; return btn;
} }
_commit() { _commit(mode) {
const parent = this.getTemplateBtn().parentElement; const btnParent = this.getTemplateBtn().parentElement;
const parent = mode === BtnListMode.InPage
? btnParent
: document.createElement('div');
const shadow = parent.attachShadow({ mode: 'closed' }); const shadow = parent.attachShadow({ mode: 'closed' });
// style the shadow DOM from outside css // style the shadow DOM from outside css
document.head.querySelectorAll('style').forEach(s => { document.head.querySelectorAll('style').forEach(s => {
shadow.append(s.cloneNode(true)); shadow.append(s.cloneNode(true));
}); });
// hide buttons using the shadow DOM // hide buttons using the shadow DOM
const newParent = parent.cloneNode(false); const newParent = btnParent.cloneNode(false);
newParent.append(...this.list); newParent.append(...this.list);
shadow.append(newParent); shadow.append(newParent);
return parent; return parent;
@ -26847,17 +26854,32 @@ Please pipe the document into a Node stream.\
/** /**
* replace the template button with the list of new buttons * replace the template button with the list of new buttons
*/ */
commit() { commit(mode = BtnListMode.InPage) {
let el = this._commit(); switch (mode) {
const observer = new MutationObserver(() => { case BtnListMode.InPage: {
// check if the buttons are still in document when dom updates let el = this._commit(mode);
if (!document.contains(el)) { const observer = new MutationObserver(() => {
// re-commit // check if the buttons are still in document when dom updates
// performance issue? if (!document.contains(el)) {
el = this._commit(); // re-commit
// performance issue?
el = this._commit(mode);
}
});
observer.observe(document, { childList: true, subtree: true });
break;
} }
}); case BtnListMode.ExtWindow: {
observer.observe(document, { childList: true, subtree: true }); const div = this._commit(mode);
const w = window.open('', undefined, 'resizable,width=230,height=270');
// eslint-disable-next-line no-unused-expressions
w === null || w === void 0 ? void 0 : w.document.body.append(div);
window.addEventListener('unload', () => w === null || w === void 0 ? void 0 : w.close());
break;
}
default:
throw new Error('unknown BtnListMode');
}
} }
} }
// eslint-disable-next-line @typescript-eslint/no-namespace // eslint-disable-next-line @typescript-eslint/no-namespace
@ -27054,7 +27076,7 @@ Please pipe the document into a Node stream.\
} }
})), })),
}); });
btnList.commit(); btnList.commit(BtnListMode.InPage);
}; };
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
waitForDocumentLoaded().then(main); waitForDocumentLoaded().then(main);

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "musescore-downloader", "name": "musescore-downloader",
"version": "0.12.5", "version": "0.13.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "musescore-downloader", "name": "musescore-downloader",
"version": "0.12.5", "version": "0.13.0",
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱", "description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱",
"main": "dist/main.js", "main": "dist/main.js",
"repository": { "repository": {