v0.14.3
This commit is contained in:
parent
dbcda27be4
commit
edde0d0d75
|
@ -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.14.2
|
// @version 0.14.3
|
||||||
// @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/*/*
|
||||||
|
@ -26740,30 +26740,31 @@ Please pipe the document into a Node stream.\
|
||||||
return locale[key];
|
return locale[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
var btnListCss = "div {\n flex-wrap: wrap;\n display: flex;\n align-items: center;\n font-family: 'Open Sans', 'Roboto', 'Helvetica neue', Helvetica, sans-serif;\n}\n\nbutton {\n width: 205px !important;\n height: 38px;\n\n color: #fff;\n background: #1f74bd;\n\n cursor: pointer;\n\n margin-bottom: 4px;\n margin-right: 4px;\n padding: 4px 12px;\n\n justify-content: start;\n align-self: center;\n\n font-size: 16px;\n border-radius: 2px;\n border: 0;\n\n display: inline-flex;\n position: relative;\n\n font-family: inherit;\n}\n\nsvg {\n display: inline-block;\n margin-right: 5px;\n width: 20px;\n height: 20px;\n margin-top: auto;\n margin-bottom: auto;\n}\n\nspan {\n margin-top: auto;\n margin-bottom: auto;\n}";
|
||||||
* Select the original Download Button
|
|
||||||
*/
|
const getBtnContainer = () => {
|
||||||
const getDownloadBtn = () => {
|
|
||||||
const container = document.querySelectorAll('aside>section>section')[0];
|
const container = document.querySelectorAll('aside>section>section')[0];
|
||||||
const btnsDiv = [...container.children].find((div) => {
|
return [...container.children].find((div) => {
|
||||||
const b = div.querySelector('button, .button');
|
const b = div.querySelector('button, .button');
|
||||||
return b && b.outerHTML.replace(/\s/g, '').includes('Download');
|
return b && b.outerHTML.replace(/\s/g, '').includes('Download');
|
||||||
});
|
});
|
||||||
const btn = btnsDiv.querySelector('button, .button');
|
};
|
||||||
btn.onclick = null;
|
const buildDownloadBtn = () => {
|
||||||
// fix the icon of the download btn
|
const btn = document.createElement('button');
|
||||||
// if the `btn` seleted was a `Print` btn, replace the `print` icon with the `download` icon
|
btn.type = 'button';
|
||||||
const svgPath = btn.querySelector('svg > path');
|
// build icon svg element
|
||||||
if (svgPath) {
|
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||||
svgPath.setAttribute('d', 'M9.6 2.4h4.8V12h2.784l-5.18 5.18L6.823 12H9.6V2.4zM19.2 19.2H4.8v2.4h14.4v-2.4z');
|
svg.setAttribute('viewBox', '0 0 24 24');
|
||||||
}
|
const svgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
||||||
if (btn.nodeName.toLowerCase() === 'button') {
|
svgPath.setAttribute('d', 'M9.6 2.4h4.8V12h2.784l-5.18 5.18L6.823 12H9.6V2.4zM19.2 19.2H4.8v2.4h14.4v-2.4z');
|
||||||
btn.setAttribute('style', 'width: 205px !important');
|
svgPath.setAttribute('fill', '#fff');
|
||||||
}
|
svg.append(svgPath);
|
||||||
else {
|
const textNode = document.createElement('span');
|
||||||
btn.dataset.target = '';
|
btn.append(svg, textNode);
|
||||||
}
|
return {
|
||||||
return btn;
|
btn,
|
||||||
|
textNode,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
var BtnListMode;
|
var BtnListMode;
|
||||||
(function (BtnListMode) {
|
(function (BtnListMode) {
|
||||||
|
@ -26771,13 +26772,12 @@ Please pipe the document into a Node stream.\
|
||||||
BtnListMode[BtnListMode["ExtWindow"] = 1] = "ExtWindow";
|
BtnListMode[BtnListMode["ExtWindow"] = 1] = "ExtWindow";
|
||||||
})(BtnListMode || (BtnListMode = {}));
|
})(BtnListMode || (BtnListMode = {}));
|
||||||
class BtnList {
|
class BtnList {
|
||||||
constructor(getTemplateBtn) {
|
constructor(getBtnParent = getBtnContainer) {
|
||||||
this.getTemplateBtn = getTemplateBtn;
|
this.getBtnParent = getBtnParent;
|
||||||
this.list = [];
|
this.list = [];
|
||||||
}
|
}
|
||||||
add(options) {
|
add(options) {
|
||||||
const btn = this.getTemplateBtn().cloneNode(true);
|
const { btn, textNode } = buildDownloadBtn();
|
||||||
const textNode = [...btn.children].find(x => x.nodeName === 'SPAN');
|
|
||||||
const setText = (str) => {
|
const setText = (str) => {
|
||||||
textNode.textContent = str;
|
textNode.textContent = str;
|
||||||
};
|
};
|
||||||
|
@ -26794,21 +26794,24 @@ Please pipe the document into a Node stream.\
|
||||||
}
|
}
|
||||||
return btn;
|
return btn;
|
||||||
}
|
}
|
||||||
_commit(mode) {
|
_commit() {
|
||||||
const btnParent = this.getTemplateBtn().parentElement;
|
let btnParent = document.createElement('div');
|
||||||
const parent = mode === BtnListMode.InPage
|
try {
|
||||||
? btnParent
|
btnParent = this.getBtnParent();
|
||||||
: document.createElement('div');
|
}
|
||||||
const shadow = parent.attachShadow({ mode: 'closed' });
|
catch (err) {
|
||||||
// style the shadow DOM from outside css
|
console.error(err);
|
||||||
document.head.querySelectorAll('style').forEach(s => {
|
}
|
||||||
shadow.append(s.cloneNode(true));
|
const shadow = btnParent.attachShadow({ mode: 'closed' });
|
||||||
});
|
// style the shadow DOM
|
||||||
|
const style = document.createElement('style');
|
||||||
|
style.innerText = btnListCss;
|
||||||
|
shadow.append(style);
|
||||||
// hide buttons using the shadow DOM
|
// hide buttons using the shadow DOM
|
||||||
const newParent = btnParent.cloneNode(false);
|
const newParent = btnParent.cloneNode(false);
|
||||||
newParent.append(...this.list);
|
newParent.append(...this.list);
|
||||||
shadow.append(newParent);
|
shadow.append(newParent);
|
||||||
return parent;
|
return btnParent;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* replace the template button with the list of new buttons
|
* replace the template button with the list of new buttons
|
||||||
|
@ -26816,20 +26819,27 @@ Please pipe the document into a Node stream.\
|
||||||
commit(mode = BtnListMode.InPage) {
|
commit(mode = BtnListMode.InPage) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BtnListMode.InPage: {
|
case BtnListMode.InPage: {
|
||||||
let el = this._commit(mode);
|
// fallback to BtnListMode.ExtWindow
|
||||||
|
try {
|
||||||
|
this.getBtnParent();
|
||||||
|
}
|
||||||
|
catch (_a) {
|
||||||
|
return this.commit(BtnListMode.ExtWindow);
|
||||||
|
}
|
||||||
|
let el = this._commit();
|
||||||
const observer = new MutationObserver(() => {
|
const observer = new MutationObserver(() => {
|
||||||
// check if the buttons are still in document when dom updates
|
// check if the buttons are still in document when dom updates
|
||||||
if (!document.contains(el)) {
|
if (!document.contains(el)) {
|
||||||
// re-commit
|
// re-commit
|
||||||
// performance issue?
|
// performance issue?
|
||||||
el = this._commit(mode);
|
el = this._commit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
observer.observe(document, { childList: true, subtree: true });
|
observer.observe(document, { childList: true, subtree: true });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BtnListMode.ExtWindow: {
|
case BtnListMode.ExtWindow: {
|
||||||
const div = this._commit(mode);
|
const div = this._commit();
|
||||||
const w = window.open('', undefined, 'resizable,width=230,height=270');
|
const w = window.open('', undefined, 'resizable,width=230,height=270');
|
||||||
// eslint-disable-next-line no-unused-expressions
|
// eslint-disable-next-line no-unused-expressions
|
||||||
w === null || w === void 0 ? void 0 : w.document.body.append(div);
|
w === null || w === void 0 ? void 0 : w.document.body.append(div);
|
||||||
|
@ -26915,7 +26925,7 @@ Please pipe the document into a Node stream.\
|
||||||
})(BtnAction || (BtnAction = {}));
|
})(BtnAction || (BtnAction = {}));
|
||||||
|
|
||||||
const main = () => {
|
const main = () => {
|
||||||
const btnList = new BtnList(getDownloadBtn);
|
const btnList = new BtnList();
|
||||||
const filename = scoreinfo.fileName;
|
const filename = scoreinfo.fileName;
|
||||||
btnList.add({
|
btnList.add({
|
||||||
name: i18n('DOWNLOAD')('MSCZ'),
|
name: i18n('DOWNLOAD')('MSCZ'),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "musescore-downloader",
|
"name": "musescore-downloader",
|
||||||
"version": "0.14.2",
|
"version": "0.14.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "musescore-downloader",
|
"name": "musescore-downloader",
|
||||||
"version": "0.14.2",
|
"version": "0.14.3",
|
||||||
"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": {
|
||||||
|
|
Loading…
Reference in New Issue