Compare commits
No commits in common. "master" and "v0.23.1" have entirely different histories.
21 changed files with 121 additions and 345 deletions
|
@ -20,8 +20,6 @@
|
|||
"no-useless-constructor": "off",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"no-dupe-class-members": "off",
|
||||
"no-void": "off",
|
||||
"no-use-before-define": "off",
|
||||
"@typescript-eslint/no-dupe-class-members": "error",
|
||||
"@typescript-eslint/no-floating-promises": "warn",
|
||||
"@typescript-eslint/member-delimiter-style": "warn",
|
||||
|
|
11
.github/workflows/release.yml
vendored
11
.github/workflows/release.yml
vendored
|
@ -53,15 +53,6 @@ jobs:
|
|||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 0301...
|
||||
|
||||
- name: NPM Publish msdl
|
||||
run: |
|
||||
cd ./src/msdl
|
||||
sed -i "s/%VERSION%/$VERSION/" package.json
|
||||
npm publish --tag $NPM_TAG
|
||||
cd -
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Publish Firefox Extension
|
||||
id: web-ext-build
|
||||
uses: kewisch/action-web-ext@v1
|
||||
|
@ -78,7 +69,6 @@ jobs:
|
|||
cp dist/main.js $ARTIFACTS_DIR/musescore-downloader.user.js
|
||||
cp dist/ext.zip $ARTIFACTS_DIR/musescore-downloader.webextension.zip
|
||||
wget -q $CHROME_EXT_URL -P $ARTIFACTS_DIR/
|
||||
wget -q https://github.com/Xmader/musescore-downloader/archive/$REF.tar.gz -O $ARTIFACTS_DIR/source.tar.gz
|
||||
- run: bash ./.github/workflows/get-signed-ext.sh
|
||||
env:
|
||||
EXT_ID: musescore-downloader
|
||||
|
@ -98,7 +88,6 @@ jobs:
|
|||
IPFS_HASH: ${{ steps.ipfs.outputs.hash }}
|
||||
run: |
|
||||
cd $ARTIFACTS_DIR
|
||||
rm *.tar.gz
|
||||
|
||||
files=$(ls .)
|
||||
assets=()
|
||||
|
|
147
dist/main.js
vendored
147
dist/main.js
vendored
|
@ -5,7 +5,7 @@
|
|||
// @supportURL https://github.com/Xmader/musescore-downloader/issues
|
||||
// @updateURL https://msdl.librescore.org/install.user.js
|
||||
// @downloadURL https://msdl.librescore.org/install.user.js
|
||||
// @version 0.24.1
|
||||
// @version 0.23.1
|
||||
// @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱
|
||||
// @author Xmader
|
||||
// @match https://musescore.com/*/*
|
||||
|
@ -65,7 +65,7 @@
|
|||
const loaderOutro = '})()'.repeat(stackN)
|
||||
const mockUrl = "https://c.amazon-adsystem.com/aax2/apstag.js"
|
||||
|
||||
Function(`${loaderIntro}const d=new Image();window['${id}'](d);delete window['${id}'];document.body.prepend(d)${loaderOutro}//# sourceURL=${mockUrl}`)()
|
||||
setTimeout(`${loaderIntro}const d=new Image();window['${id}'](d);delete window['${id}'];document.body.prepend(d)${loaderOutro}//# sourceURL=${mockUrl}`)
|
||||
}).then(d => {
|
||||
d.style.display = 'none';
|
||||
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
||||
|
@ -331,7 +331,6 @@
|
|||
typeof GM[requiredMethod] !== 'undefined';
|
||||
};
|
||||
|
||||
const DISCORD_URL = 'https://discord.gg/gSsTUvJmD8';
|
||||
const escapeFilename = (s) => {
|
||||
return s.replace(/[\s<>:{}"/\\|?*~.\0\cA-\cZ]+/g, '_');
|
||||
};
|
||||
|
@ -26440,7 +26439,7 @@ Please pipe the document into a Node stream.\
|
|||
});
|
||||
|
||||
/// <reference lib="webworker" />
|
||||
const readData = (blob, type) => {
|
||||
const getDataURL = (blob) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
|
@ -26448,21 +26447,19 @@ Please pipe the document into a Node stream.\
|
|||
resolve(result);
|
||||
};
|
||||
reader.onerror = reject;
|
||||
if (type === 'dataUrl') {
|
||||
reader.readAsDataURL(blob);
|
||||
}
|
||||
else {
|
||||
reader.readAsText(blob);
|
||||
}
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
};
|
||||
const fetchBlob = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const r = yield fetch(imgUrl, {
|
||||
cache: 'no-cache',
|
||||
});
|
||||
return r.blob();
|
||||
const fetchDataURL = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const r = yield fetch(imgUrl);
|
||||
const blob = yield r.blob();
|
||||
return getDataURL(blob);
|
||||
});
|
||||
const generatePDF = (imgBlobs, imgType, width, height) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const fetchText = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const r = yield fetch(imgUrl);
|
||||
return r.text();
|
||||
});
|
||||
const generatePDF = (imgURLs, imgType, width, height) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
// @ts-ignore
|
||||
const pdf = new PDFDocument({
|
||||
// compress: true,
|
||||
|
@ -26472,7 +26469,7 @@ Please pipe the document into a Node stream.\
|
|||
layout: 'portrait',
|
||||
});
|
||||
if (imgType === 'png') {
|
||||
const imgDataUrlList = yield Promise.all(imgBlobs.map(b => readData(b, 'dataUrl')));
|
||||
const imgDataUrlList = yield Promise.all(imgURLs.map(fetchDataURL));
|
||||
imgDataUrlList.forEach((data) => {
|
||||
pdf.addPage();
|
||||
pdf.image(data, {
|
||||
|
@ -26482,7 +26479,7 @@ Please pipe the document into a Node stream.\
|
|||
});
|
||||
}
|
||||
else { // imgType == "svg"
|
||||
const svgList = yield Promise.all(imgBlobs.map(b => readData(b, 'text')));
|
||||
const svgList = yield Promise.all(imgURLs.map(fetchText));
|
||||
svgList.forEach((svg) => {
|
||||
pdf.addPage();
|
||||
source(pdf, svg, 0, 0, {
|
||||
|
@ -26495,9 +26492,8 @@ Please pipe the document into a Node stream.\
|
|||
return buf.buffer;
|
||||
});
|
||||
onmessage = (e) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const [imgUrls, imgType, width, height,] = e.data;
|
||||
const imgBlobs = yield Promise.all(imgUrls.map(url => fetchBlob(url)));
|
||||
const pdfBuf = yield generatePDF(imgBlobs, imgType, width, height);
|
||||
const [imgURLs, imgType, width, height,] = e.data;
|
||||
const pdfBuf = yield generatePDF(imgURLs, imgType, width, height);
|
||||
postMessage(pdfBuf, [pdfBuf]);
|
||||
});
|
||||
|
||||
|
@ -26575,7 +26571,7 @@ Please pipe the document into a Node stream.\
|
|||
}
|
||||
|
||||
/* eslint-disable no-extend-native */
|
||||
const TYPE_REG = /type=(img|mp3|midi)/;
|
||||
const TYPE_REG = /id=(\d+)&type=(img|mp3|midi)/;
|
||||
/**
|
||||
* I know this is super hacky.
|
||||
*/
|
||||
|
@ -26596,9 +26592,8 @@ Please pipe the document into a Node stream.\
|
|||
const token = (_a = init === null || init === void 0 ? void 0 : init.headers) === null || _a === void 0 ? void 0 : _a.Authorization;
|
||||
if (typeof url === 'string' && token) {
|
||||
const m = url.match(TYPE_REG);
|
||||
console$1.debug(url, token, m);
|
||||
if (m) {
|
||||
const type = m[1];
|
||||
const type = m[2];
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
(_b = l[type]) === null || _b === void 0 ? void 0 : _b.call(l, token);
|
||||
}
|
||||
|
@ -26638,7 +26633,7 @@ Please pipe the document into a Node stream.\
|
|||
// force to retrieve the MAGIC
|
||||
switch (type) {
|
||||
case 'midi': {
|
||||
const el = document.querySelector('button[hasaccess]');
|
||||
const el = document.querySelectorAll('.SD7H- > button')[3];
|
||||
el.click();
|
||||
break;
|
||||
}
|
||||
|
@ -26736,7 +26731,7 @@ Please pipe the document into a Node stream.\
|
|||
// read further error msg
|
||||
const err = cidRes.Message;
|
||||
if (err.includes('no link named')) { // file not found
|
||||
throw new Error('Score not in dataset');
|
||||
throw new Error('score not in dataset');
|
||||
}
|
||||
else {
|
||||
throw new Error(err);
|
||||
|
@ -26923,22 +26918,12 @@ Please pipe the document into a Node stream.\
|
|||
return locale[key];
|
||||
}
|
||||
|
||||
var dependencies = {
|
||||
"@librescore/fonts": "^0.4.0",
|
||||
"@librescore/sf3": "^0.3.0",
|
||||
"detect-node": "^2.0.4",
|
||||
inquirer: "^7.3.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
ora: "^5.1.0",
|
||||
webmscore: "^0.18.0"
|
||||
};
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const WEBMSCORE_URL = `https://cdn.jsdelivr.net/npm/webmscore@${dependencies.webmscore}/webmscore.js`;
|
||||
const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.12/webmscore.js';
|
||||
// fonts for Chinese characters (CN) and Korean hangul (KR)
|
||||
// JP characters are included in the CN font
|
||||
const FONT_URLS = ['CN', 'KR'].map(l => `https://cdn.jsdelivr.net/npm/@librescore/fonts@${dependencies['@librescore/fonts']}/SourceHanSans${l}.min.woff2`);
|
||||
const SF3_URL = `https://cdn.jsdelivr.net/npm/@librescore/sf3@${dependencies['@librescore/sf3']}/FluidR3Mono_GM.sf3`;
|
||||
const FONT_URLS = ['CN', 'KR'].map(l => `https://cdn.jsdelivr.net/npm/@librescore/fonts/SourceHanSans${l}-Regular.woff2`);
|
||||
const SF3_URL = 'https://cdn.jsdelivr.net/npm/@librescore/sf3/FluidR3Mono_GM.sf3';
|
||||
const SOUND_FONT_LOADED = Symbol('SoundFont loaded');
|
||||
const initMscore = (w) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (!detectNode) { // attached to a page
|
||||
|
@ -27037,8 +27022,7 @@ Please pipe the document into a Node stream.\
|
|||
},
|
||||
];
|
||||
|
||||
const _getLink = (indexingInfo) => {
|
||||
const { scorepack } = JSON.parse(indexingInfo);
|
||||
const _getLink = (scorepack) => {
|
||||
return `https://librescore.org/score/${scorepack}`;
|
||||
};
|
||||
const getLibreScoreLink = (scoreinfo, _fetch = getFetch()) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
|
@ -27057,7 +27041,7 @@ Please pipe the document into a Node stream.\
|
|||
return _getLink(res);
|
||||
});
|
||||
|
||||
var btnListCss = "div {\n width: 422px;\n right: 0;\n margin: 0 18px 18px 0;\n\n text-align: center;\n align-items: center;\n font-family: 'Inter', 'Helvetica neue', Helvetica, sans-serif;\n position: absolute;\n z-index: 9999;\n background: #f6f6f6;\n min-width: 230px;\n\n /* pass the scroll event through the btns background */\n pointer-events: none;\n}\n\n@media screen and (max-width: 950px) {\n div {\n width: auto !important;\n }\n}\n\nbutton {\n width: 178px !important;\n min-width: 178px;\n height: 40px;\n\n color: #fff;\n background: #2e68c0;\n\n cursor: pointer;\n pointer-events: auto;\n\n margin-bottom: 8px;\n margin-right: 8px;\n padding: 4px 12px;\n\n justify-content: start;\n align-self: center;\n\n font-size: 16px;\n border-radius: 6px;\n border: 0;\n\n display: inline-flex;\n position: relative;\n\n font-family: inherit;\n}\n\n/* fix `View in LibreScore` button text overflow */\nbutton:last-of-type {\n width: unset !important;\n}\n\nbutton:hover {\n background: #1a4f9f;\n}\n\n/* light theme btn */\nbutton.light {\n color: #2e68c0;\n background: #e1effe;\n}\n\nbutton.light:hover {\n background: #c3ddfd;\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}";
|
||||
var btnListCss = "div {\n width: 422px;\n right: 0;\n margin: 0 18px 18px 0;\n\n text-align: center;\n align-items: center;\n font-family: 'Open Sans', 'Roboto', 'Helvetica neue', Helvetica, sans-serif;\n position: absolute;\n z-index: 9999;\n background: #f6f6f6;\n min-width: 230px;\n}\n\n@media screen and (max-width: 950px) {\n div {\n width: auto !important;\n }\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}";
|
||||
|
||||
var ICON;
|
||||
(function (ICON) {
|
||||
|
@ -27066,28 +27050,26 @@ Please pipe the document into a Node stream.\
|
|||
})(ICON || (ICON = {}));
|
||||
const getBtnContainer = () => {
|
||||
var _a;
|
||||
const els = [...document.querySelectorAll('span')];
|
||||
const els = [...document.querySelectorAll('*')].reverse();
|
||||
const el = els.find(b => {
|
||||
var _a;
|
||||
const text = ((_a = b === null || b === void 0 ? void 0 : b.textContent) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, '')) || '';
|
||||
return text.includes('Download') || text.includes('Print');
|
||||
});
|
||||
const btnParent = (_a = el === null || el === void 0 ? void 0 : el.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement;
|
||||
if (!btnParent || !(btnParent instanceof HTMLDivElement))
|
||||
if (!btnParent)
|
||||
throw new Error('btn parent not found');
|
||||
return btnParent;
|
||||
};
|
||||
const buildDownloadBtn = (icon, lightTheme = false) => {
|
||||
const buildDownloadBtn = (icon) => {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
if (lightTheme)
|
||||
btn.className = 'light';
|
||||
// build icon svg element
|
||||
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
svg.setAttribute('viewBox', '0 0 24 24');
|
||||
const svgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
||||
svgPath.setAttribute('d', icon);
|
||||
svgPath.setAttribute('fill', lightTheme ? '#2e68c0' : '#fff');
|
||||
svgPath.setAttribute('fill', '#fff');
|
||||
svg.append(svgPath);
|
||||
const textNode = document.createElement('span');
|
||||
btn.append(svg, textNode);
|
||||
|
@ -27106,22 +27088,6 @@ Please pipe the document into a Node stream.\
|
|||
return getScrollParent(node.parentNode);
|
||||
}
|
||||
}
|
||||
function onPageRendered(getEl) {
|
||||
return new Promise((resolve) => {
|
||||
var _a;
|
||||
const observer = new MutationObserver(() => {
|
||||
try {
|
||||
const el = getEl();
|
||||
if (el) {
|
||||
observer.disconnect();
|
||||
resolve(el);
|
||||
}
|
||||
}
|
||||
catch (_a) { }
|
||||
});
|
||||
observer.observe((_a = document.querySelector('div > section')) !== null && _a !== void 0 ? _a : document.body, { childList: true, subtree: true });
|
||||
});
|
||||
}
|
||||
var BtnListMode;
|
||||
(function (BtnListMode) {
|
||||
BtnListMode[BtnListMode["InPage"] = 0] = "InPage";
|
||||
|
@ -27134,7 +27100,7 @@ Please pipe the document into a Node stream.\
|
|||
}
|
||||
add(options) {
|
||||
var _a;
|
||||
const btnTpl = buildDownloadBtn((_a = options.icon) !== null && _a !== void 0 ? _a : ICON.DOWNLOAD, options.lightTheme);
|
||||
const btnTpl = buildDownloadBtn((_a = options.icon) !== null && _a !== void 0 ? _a : ICON.DOWNLOAD);
|
||||
const setText = (btn) => {
|
||||
const textNode = btn.querySelector('span');
|
||||
return (str) => {
|
||||
|
@ -27164,14 +27130,10 @@ Please pipe the document into a Node stream.\
|
|||
return btnTpl;
|
||||
}
|
||||
_positionBtns(anchorDiv, newParent) {
|
||||
let { top } = anchorDiv.getBoundingClientRect();
|
||||
top += window.scrollY; // relative to the entire document instead of viewport
|
||||
const { top } = anchorDiv.getBoundingClientRect();
|
||||
if (top > 0) {
|
||||
newParent.style.top = `${top}px`;
|
||||
}
|
||||
else {
|
||||
newParent.style.top = '0px';
|
||||
}
|
||||
}
|
||||
_commit() {
|
||||
const btnParent = document.querySelector('div');
|
||||
|
@ -27186,17 +27148,20 @@ Please pipe the document into a Node stream.\
|
|||
const newParent = document.createElement('div');
|
||||
newParent.append(...this.list.map(e => cloneBtn(e)));
|
||||
shadow.append(newParent);
|
||||
// default position
|
||||
newParent.style.top = `${window.innerHeight - newParent.getBoundingClientRect().height}px`;
|
||||
void onPageRendered(this.getBtnParent).then((anchorDiv) => {
|
||||
try {
|
||||
const anchorDiv = this.getBtnParent();
|
||||
const pos = () => this._positionBtns(anchorDiv, newParent);
|
||||
pos();
|
||||
document.addEventListener('readystatechange', pos);
|
||||
// reposition btns when window resizes
|
||||
window.addEventListener('resize', pos, { passive: true });
|
||||
window.addEventListener('resize', pos);
|
||||
// reposition btns when scrolling
|
||||
const scroll = getScrollParent(anchorDiv);
|
||||
scroll.addEventListener('scroll', pos, { passive: true });
|
||||
});
|
||||
scroll.addEventListener('scroll', pos);
|
||||
}
|
||||
catch (err) {
|
||||
console$1.error(err);
|
||||
}
|
||||
return btnParent;
|
||||
}
|
||||
/**
|
||||
|
@ -27303,15 +27268,6 @@ Please pipe the document into a Node stream.\
|
|||
}
|
||||
else {
|
||||
setText(i18n('BTN_ERROR')());
|
||||
// ask user to send Discord message
|
||||
alert('❌Download Failed!\n\n' +
|
||||
'Send your URL to the #dataset-bugs channel ' +
|
||||
'in the LibreScore Community Discord server:\n' + DISCORD_URL);
|
||||
// open Discord on 'OK'
|
||||
const a = document.createElement('a');
|
||||
a.href = DISCORD_URL;
|
||||
a.target = '_blank';
|
||||
a.dispatchEvent(new MouseEvent('click'));
|
||||
}
|
||||
}
|
||||
btn.onclick = _onclick;
|
||||
|
@ -27329,7 +27285,7 @@ Please pipe the document into a Node stream.\
|
|||
class ScoreInfo {
|
||||
constructor() {
|
||||
this.RADIX = 20;
|
||||
this.INDEX_RADIX = 32;
|
||||
this.INDEX_RADIX = 40;
|
||||
this.store = new Map();
|
||||
}
|
||||
get idLastDigit() {
|
||||
|
@ -27345,7 +27301,7 @@ Please pipe the document into a Node stream.\
|
|||
return `https://ipfs.infura.io:5001/api/v0/block/stat?arg=${this.getMsczIpfsRef(mainCid)}`;
|
||||
}
|
||||
getScorepackRef(mainCid) {
|
||||
return `/ipfs/${mainCid}/index/${(+this.id) % this.INDEX_RADIX}/${this.id}`;
|
||||
return `/ipfs/${mainCid}/index/${(+this.id) % this.INDEX_RADIX}/${this.id}/scorepack`;
|
||||
}
|
||||
}
|
||||
class ScoreInfoInPage extends ScoreInfo {
|
||||
|
@ -27380,22 +27336,13 @@ Please pipe the document into a Node stream.\
|
|||
super();
|
||||
this.document = document;
|
||||
}
|
||||
get sheet0Img() {
|
||||
return this.document.querySelector('img[src*=score_]');
|
||||
}
|
||||
get pageCount() {
|
||||
var _a;
|
||||
const sheet0Div = (_a = this.sheet0Img) === null || _a === void 0 ? void 0 : _a.parentElement;
|
||||
if (!sheet0Div) {
|
||||
throw new Error('no sheet images found');
|
||||
}
|
||||
return this.document.getElementsByClassName(sheet0Div.className).length;
|
||||
return this.document.querySelectorAll('.gXB83').length;
|
||||
}
|
||||
get thumbnailUrl() {
|
||||
var _a;
|
||||
// url to the image of the first page
|
||||
const el = this.document.querySelector('link[as=image]');
|
||||
const url = ((el === null || el === void 0 ? void 0 : el.href) || ((_a = this.sheet0Img) === null || _a === void 0 ? void 0 : _a.src));
|
||||
const url = el.href;
|
||||
return url.split('@')[0];
|
||||
}
|
||||
}
|
||||
|
@ -27444,7 +27391,7 @@ Please pipe the document into a Node stream.\
|
|||
action: BtnAction.process(() => downloadPDF(scoreinfo, new SheetInfoInPage(document)), fallback, 3 * 60 * 1000 /* 3min */),
|
||||
});
|
||||
btnList.add({
|
||||
name: i18n('DOWNLOAD')('MXL'),
|
||||
name: i18n('DOWNLOAD')('MusicXML'),
|
||||
action: BtnAction.mscoreWindow(scoreinfo, (w, score) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const mxl = yield score.saveMxl();
|
||||
const data = new Blob([mxl]);
|
||||
|
@ -27524,9 +27471,7 @@ Please pipe the document into a Node stream.\
|
|||
action: BtnAction.openUrl(() => getLibreScoreLink(scoreinfo)),
|
||||
tooltip: 'BETA',
|
||||
icon: ICON.LIBRESCORE,
|
||||
lightTheme: true,
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
btnList.commit(BtnListMode.InPage);
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
|
|
40
package-lock.json
generated
40
package-lock.json
generated
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"name": "musescore-downloader",
|
||||
"version": "0.24.1",
|
||||
"version": "0.23.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@librescore/fonts": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@librescore/fonts/-/fonts-0.4.0.tgz",
|
||||
"integrity": "sha512-T286OfxcQAYc/Bll9AtSP2ElggqTpoa08uY9Kgx6z1TcDVn7i7uMkKVO7sw/8aELWFNRmQE2vGQuEkmJNfWmBA=="
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@librescore/fonts/-/fonts-0.2.1.tgz",
|
||||
"integrity": "sha512-lzEk82wZWZVA4CvE2S6Wwc6EAvFZ0G6L2ExNjpJLebxAh0k/eNpHeO9a2LFwfMVUfacVWwXhDkAbmJpvUGcqzA=="
|
||||
},
|
||||
"@librescore/sf3": {
|
||||
"version": "0.3.0",
|
||||
|
@ -709,26 +709,18 @@
|
|||
}
|
||||
},
|
||||
"elliptic": {
|
||||
"version": "6.5.4",
|
||||
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
|
||||
"integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==",
|
||||
"version": "6.5.3",
|
||||
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
|
||||
"integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bn.js": "^4.11.9",
|
||||
"brorand": "^1.1.0",
|
||||
"bn.js": "^4.4.0",
|
||||
"brorand": "^1.0.1",
|
||||
"hash.js": "^1.0.0",
|
||||
"hmac-drbg": "^1.0.1",
|
||||
"inherits": "^2.0.4",
|
||||
"minimalistic-assert": "^1.0.1",
|
||||
"minimalistic-crypto-utils": "^1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"bn.js": {
|
||||
"version": "4.12.0",
|
||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz",
|
||||
"integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==",
|
||||
"dev": true
|
||||
}
|
||||
"hmac-drbg": "^1.0.0",
|
||||
"inherits": "^2.0.1",
|
||||
"minimalistic-assert": "^1.0.0",
|
||||
"minimalistic-crypto-utils": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"emoji-regex": {
|
||||
|
@ -2439,9 +2431,9 @@
|
|||
}
|
||||
},
|
||||
"webmscore": {
|
||||
"version": "0.18.0",
|
||||
"resolved": "https://registry.npmjs.org/webmscore/-/webmscore-0.18.0.tgz",
|
||||
"integrity": "sha512-/J/2/KKWKST0A+Qix/SBSVtZY0C/33GQoYI3V84XEu/V3nij2ZFIcsyGQPYVr6y0HVasj6dQtvY+y7MrmYcsTw=="
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/webmscore/-/webmscore-0.12.0.tgz",
|
||||
"integrity": "sha512-lmie1LWQueAIih93hXGuphl6D18pdZIKLCv91Hu0n5jklJw3RZactRxGujdJbMaeRW2AjIU2FLKklcGzqdrnJA=="
|
||||
},
|
||||
"word-wrap": {
|
||||
"version": "1.2.3",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "musescore-downloader",
|
||||
"version": "0.24.1",
|
||||
"version": "0.23.1",
|
||||
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱",
|
||||
"main": "dist/main.js",
|
||||
"bin": "dist/cli.js",
|
||||
|
@ -37,13 +37,13 @@
|
|||
"dist/main.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@librescore/fonts": "^0.4.0",
|
||||
"@librescore/fonts": "^0.2.1",
|
||||
"@librescore/sf3": "^0.3.0",
|
||||
"detect-node": "^2.0.4",
|
||||
"inquirer": "^7.3.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
"ora": "^5.1.0",
|
||||
"webmscore": "^0.18.0"
|
||||
"webmscore": "^0.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
|
|
38
src/btn.css
38
src/btn.css
|
@ -5,14 +5,11 @@ div {
|
|||
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
font-family: 'Inter', 'Helvetica neue', Helvetica, sans-serif;
|
||||
font-family: 'Open Sans', 'Roboto', 'Helvetica neue', Helvetica, sans-serif;
|
||||
position: absolute;
|
||||
z-index: 9999;
|
||||
background: #f6f6f6;
|
||||
min-width: 230px;
|
||||
|
||||
/* pass the scroll event through the btns background */
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 950px) {
|
||||
|
@ -22,25 +19,23 @@ div {
|
|||
}
|
||||
|
||||
button {
|
||||
width: 178px !important;
|
||||
min-width: 178px;
|
||||
height: 40px;
|
||||
width: 205px !important;
|
||||
height: 38px;
|
||||
|
||||
color: #fff;
|
||||
background: #2e68c0;
|
||||
background: #1f74bd;
|
||||
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
|
||||
margin-bottom: 8px;
|
||||
margin-right: 8px;
|
||||
margin-bottom: 4px;
|
||||
margin-right: 4px;
|
||||
padding: 4px 12px;
|
||||
|
||||
justify-content: start;
|
||||
align-self: center;
|
||||
|
||||
font-size: 16px;
|
||||
border-radius: 6px;
|
||||
border-radius: 2px;
|
||||
border: 0;
|
||||
|
||||
display: inline-flex;
|
||||
|
@ -49,25 +44,6 @@ button {
|
|||
font-family: inherit;
|
||||
}
|
||||
|
||||
/* fix `View in LibreScore` button text overflow */
|
||||
button:last-of-type {
|
||||
width: unset !important;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #1a4f9f;
|
||||
}
|
||||
|
||||
/* light theme btn */
|
||||
button.light {
|
||||
color: #2e68c0;
|
||||
background: #e1effe;
|
||||
}
|
||||
|
||||
button.light:hover {
|
||||
background: #c3ddfd;
|
||||
}
|
||||
|
||||
svg {
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
|
|
60
src/btn.ts
60
src/btn.ts
|
@ -1,7 +1,7 @@
|
|||
|
||||
import { ScoreInfo } from './scoreinfo'
|
||||
import { loadMscore, WebMscore } from './mscore'
|
||||
import { useTimeout, windowOpenAsync, console, attachShadow, DISCORD_URL } from './utils'
|
||||
import { useTimeout, windowOpenAsync, console, attachShadow } from './utils'
|
||||
import { isGmAvailable, _GM } from './gm'
|
||||
import i18n from './i18n'
|
||||
// @ts-ignore
|
||||
|
@ -15,27 +15,26 @@ export enum ICON {
|
|||
}
|
||||
|
||||
const getBtnContainer = (): HTMLDivElement => {
|
||||
const els = [...document.querySelectorAll('span')]
|
||||
const els = [...document.querySelectorAll('*')].reverse()
|
||||
const el = els.find(b => {
|
||||
const text = b?.textContent?.replace(/\s/g, '') || ''
|
||||
return text.includes('Download') || text.includes('Print')
|
||||
}) as HTMLDivElement | null
|
||||
const btnParent = el?.parentElement?.parentElement as HTMLDivElement | undefined
|
||||
if (!btnParent || !(btnParent instanceof HTMLDivElement)) throw new Error('btn parent not found')
|
||||
if (!btnParent) throw new Error('btn parent not found')
|
||||
return btnParent
|
||||
}
|
||||
|
||||
const buildDownloadBtn = (icon: ICON, lightTheme = false) => {
|
||||
const buildDownloadBtn = (icon: ICON) => {
|
||||
const btn = document.createElement('button')
|
||||
btn.type = 'button'
|
||||
if (lightTheme) btn.className = 'light'
|
||||
|
||||
// build icon svg element
|
||||
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
||||
svg.setAttribute('viewBox', '0 0 24 24')
|
||||
const svgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
||||
svgPath.setAttribute('d', icon)
|
||||
svgPath.setAttribute('fill', lightTheme ? '#2e68c0' : '#fff')
|
||||
svgPath.setAttribute('fill', '#fff')
|
||||
svg.append(svgPath)
|
||||
|
||||
const textNode = document.createElement('span')
|
||||
|
@ -58,28 +57,12 @@ function getScrollParent (node: HTMLElement): HTMLElement {
|
|||
}
|
||||
}
|
||||
|
||||
function onPageRendered (getEl: () => HTMLElement) {
|
||||
return new Promise<HTMLElement>((resolve) => {
|
||||
const observer = new MutationObserver(() => {
|
||||
try {
|
||||
const el = getEl()
|
||||
if (el) {
|
||||
observer.disconnect()
|
||||
resolve(el)
|
||||
}
|
||||
} catch { }
|
||||
})
|
||||
observer.observe(document.querySelector('div > section') ?? document.body, { childList: true, subtree: true })
|
||||
})
|
||||
}
|
||||
|
||||
interface BtnOptions {
|
||||
readonly name: string;
|
||||
readonly action: BtnAction;
|
||||
readonly disabled?: boolean;
|
||||
readonly tooltip?: string;
|
||||
readonly icon?: ICON;
|
||||
readonly lightTheme?: boolean;
|
||||
}
|
||||
|
||||
export enum BtnListMode {
|
||||
|
@ -93,7 +76,7 @@ export class BtnList {
|
|||
constructor (private getBtnParent: () => HTMLDivElement = getBtnContainer) { }
|
||||
|
||||
add (options: BtnOptions): BtnElement {
|
||||
const btnTpl = buildDownloadBtn(options.icon ?? ICON.DOWNLOAD, options.lightTheme)
|
||||
const btnTpl = buildDownloadBtn(options.icon ?? ICON.DOWNLOAD)
|
||||
const setText = (btn: BtnElement) => {
|
||||
const textNode = btn.querySelector('span')
|
||||
return (str: string): void => {
|
||||
|
@ -130,12 +113,9 @@ export class BtnList {
|
|||
}
|
||||
|
||||
private _positionBtns (anchorDiv: HTMLDivElement, newParent: HTMLDivElement) {
|
||||
let { top } = anchorDiv.getBoundingClientRect()
|
||||
top += window.scrollY // relative to the entire document instead of viewport
|
||||
const { top } = anchorDiv.getBoundingClientRect()
|
||||
if (top > 0) {
|
||||
newParent.style.top = `${top}px`
|
||||
} else {
|
||||
newParent.style.top = '0px'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,20 +136,21 @@ export class BtnList {
|
|||
newParent.append(...this.list.map(e => cloneBtn(e)))
|
||||
shadow.append(newParent)
|
||||
|
||||
// default position
|
||||
newParent.style.top = `${window.innerHeight - newParent.getBoundingClientRect().height}px`
|
||||
|
||||
void onPageRendered(this.getBtnParent).then((anchorDiv: HTMLDivElement) => {
|
||||
try {
|
||||
const anchorDiv = this.getBtnParent()
|
||||
const pos = () => this._positionBtns(anchorDiv, newParent)
|
||||
pos()
|
||||
document.addEventListener('readystatechange', pos)
|
||||
|
||||
// reposition btns when window resizes
|
||||
window.addEventListener('resize', pos, { passive: true })
|
||||
window.addEventListener('resize', pos)
|
||||
|
||||
// reposition btns when scrolling
|
||||
const scroll = getScrollParent(anchorDiv)
|
||||
scroll.addEventListener('scroll', pos, { passive: true })
|
||||
})
|
||||
scroll.addEventListener('scroll', pos)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
return btnParent
|
||||
}
|
||||
|
@ -288,17 +269,6 @@ export namespace BtnAction {
|
|||
setText(name)
|
||||
} else {
|
||||
setText(i18n('BTN_ERROR')())
|
||||
// ask user to send Discord message
|
||||
alert(
|
||||
'❌Download Failed!\n\n' +
|
||||
'Send your URL to the #dataset-bugs channel ' +
|
||||
'in the LibreScore Community Discord server:\n' + DISCORD_URL,
|
||||
)
|
||||
// open Discord on 'OK'
|
||||
const a = document.createElement('a')
|
||||
a.href = DISCORD_URL
|
||||
a.target = '_blank'
|
||||
a.dispatchEvent(new MouseEvent('click'))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
23
src/cli.ts
23
src/cli.ts
|
@ -9,8 +9,7 @@ import { fetchMscz, setMscz, MSCZ_URL_SYM } from './mscz'
|
|||
import { loadMscore, INDV_DOWNLOADS, WebMscore } from './mscore'
|
||||
import { ScoreInfo, ScoreInfoHtml, ScoreInfoObj, getActualId } from './scoreinfo'
|
||||
import { getLibreScoreLink } from './librescore-link'
|
||||
import { escapeFilename, DISCORD_URL } from './utils'
|
||||
import { isNpx, getVerInfo, getSelfVer } from './npm-data'
|
||||
import { escapeFilename } from './utils'
|
||||
import i18n from './i18n'
|
||||
|
||||
const inquirer: typeof import('inquirer') = require('inquirer')
|
||||
|
@ -30,12 +29,6 @@ interface Params {
|
|||
}
|
||||
|
||||
void (async () => {
|
||||
const arg = process.argv[2]
|
||||
if (['-v', '--version'].includes(arg)) { // ran with flag -v or --version, `msdl -v`
|
||||
console.log(getSelfVer()) // print musescore-downloader version
|
||||
return // exit process
|
||||
}
|
||||
|
||||
// Determine platform and paste message
|
||||
const platform = os.platform()
|
||||
let pasteMessage = ''
|
||||
|
@ -62,7 +55,7 @@ void (async () => {
|
|||
(input.endsWith(EXT) && fs.statSync(input).isFile())
|
||||
)
|
||||
},
|
||||
default: arg,
|
||||
default: process.argv[2],
|
||||
})
|
||||
|
||||
const isLocalFile = fileInit.endsWith(EXT)
|
||||
|
@ -89,7 +82,6 @@ void (async () => {
|
|||
|
||||
// initiate LibreScore link request
|
||||
librescoreLink = getLibreScoreLink(scoreinfo)
|
||||
librescoreLink.catch(() => '') // silence this unhandled Promise rejection
|
||||
|
||||
// print a blank line to the terminal
|
||||
console.log()
|
||||
|
@ -134,10 +126,6 @@ void (async () => {
|
|||
spinner.info('Score loaded by webmscore')
|
||||
} catch (err) {
|
||||
spinner.fail(err.message)
|
||||
spinner.info(
|
||||
'Send your URL to the #dataset-bugs channel in the LibreScore Community Discord server:\n ' +
|
||||
DISCORD_URL,
|
||||
)
|
||||
return
|
||||
}
|
||||
spinner.succeed('OK\n')
|
||||
|
@ -196,11 +184,4 @@ void (async () => {
|
|||
}),
|
||||
)
|
||||
spinner.succeed('OK')
|
||||
|
||||
if (!isNpx()) {
|
||||
const { installed, latest, isLatest } = await getVerInfo()
|
||||
if (!isLatest) {
|
||||
console.log(chalk.yellowBright(`\nYour installed version (${installed}) of the musescore-downloader CLI is not the latest one (${latest})!\nRun npm i -g musescore-downloader@${latest} to update.`))
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
|
|
@ -6,7 +6,7 @@ import { console } from './utils'
|
|||
|
||||
type FileType = 'img' | 'mp3' | 'midi'
|
||||
|
||||
const TYPE_REG = /type=(img|mp3|midi)/
|
||||
const TYPE_REG = /id=(\d+)&type=(img|mp3|midi)/
|
||||
|
||||
/**
|
||||
* I know this is super hacky.
|
||||
|
@ -31,9 +31,8 @@ const magicHookConstr = (() => {
|
|||
const token = init?.headers?.Authorization
|
||||
if (typeof url === 'string' && token) {
|
||||
const m = url.match(TYPE_REG)
|
||||
console.debug(url, token, m)
|
||||
if (m) {
|
||||
const type = m[1]
|
||||
const type = m[2]
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
l[type]?.(token)
|
||||
}
|
||||
|
@ -79,7 +78,7 @@ const getApiAuth = async (type: FileType, index: number): Promise<string> => {
|
|||
// force to retrieve the MAGIC
|
||||
switch (type) {
|
||||
case 'midi': {
|
||||
const el = document.querySelector('button[hasaccess]') as HTMLButtonElement
|
||||
const el = document.querySelectorAll('.SD7H- > button')[3] as HTMLButtonElement
|
||||
el.click()
|
||||
break
|
||||
}
|
||||
|
|
|
@ -2,9 +2,8 @@ import { assertRes, getFetch } from './utils'
|
|||
import { getMainCid } from './mscz'
|
||||
import { ScoreInfo } from './scoreinfo'
|
||||
|
||||
const _getLink = (indexingInfo: string) => {
|
||||
const { scorepack } = JSON.parse(indexingInfo)
|
||||
return `https://librescore.org/score/${scorepack as string}`
|
||||
const _getLink = (scorepack: string) => {
|
||||
return `https://librescore.org/score/${scorepack}`
|
||||
}
|
||||
|
||||
export const getLibreScoreLink = async (scoreinfo: ScoreInfo, _fetch = getFetch()): Promise<string> => {
|
||||
|
|
|
@ -38,7 +38,7 @@ const main = (): void => {
|
|||
})
|
||||
|
||||
btnList.add({
|
||||
name: i18n('DOWNLOAD')('MXL'),
|
||||
name: i18n('DOWNLOAD')('MusicXML'),
|
||||
action: BtnAction.mscoreWindow(scoreinfo, async (w, score) => {
|
||||
const mxl = await score.saveMxl()
|
||||
const data = new Blob([mxl])
|
||||
|
@ -137,10 +137,8 @@ const main = (): void => {
|
|||
action: BtnAction.openUrl(() => getLibreScoreLink(scoreinfo)),
|
||||
tooltip: 'BETA',
|
||||
icon: ICON.LIBRESCORE,
|
||||
lightTheme: true,
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
btnList.commit(BtnListMode.InPage)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// @version %VERSION%
|
||||
// @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱
|
||||
// @author Xmader
|
||||
// @icon https://librescore.org/img/icons/logo.svg
|
||||
// @match https://musescore.com/*/*
|
||||
// @match https://s.musescore.com/*/*
|
||||
// @license MIT
|
||||
|
|
|
@ -6,15 +6,14 @@ import { fetchData } from './utils'
|
|||
import { ScoreInfo } from './scoreinfo'
|
||||
import isNodeJs from 'detect-node'
|
||||
import i18n from './i18n'
|
||||
import { dependencies as depVers } from '../package.json'
|
||||
|
||||
const WEBMSCORE_URL = `https://cdn.jsdelivr.net/npm/webmscore@${depVers.webmscore}/webmscore.js`
|
||||
const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.12/webmscore.js'
|
||||
|
||||
// fonts for Chinese characters (CN) and Korean hangul (KR)
|
||||
// JP characters are included in the CN font
|
||||
const FONT_URLS = ['CN', 'KR'].map(l => `https://cdn.jsdelivr.net/npm/@librescore/fonts@${depVers['@librescore/fonts']}/SourceHanSans${l}.min.woff2`)
|
||||
const FONT_URLS = ['CN', 'KR'].map(l => `https://cdn.jsdelivr.net/npm/@librescore/fonts/SourceHanSans${l}-Regular.woff2`)
|
||||
|
||||
const SF3_URL = `https://cdn.jsdelivr.net/npm/@librescore/sf3@${depVers['@librescore/sf3']}/FluidR3Mono_GM.sf3`
|
||||
const SF3_URL = 'https://cdn.jsdelivr.net/npm/@librescore/sf3/FluidR3Mono_GM.sf3'
|
||||
const SOUND_FONT_LOADED = Symbol('SoundFont loaded')
|
||||
|
||||
export type WebMscore = import('webmscore').default
|
||||
|
|
|
@ -48,7 +48,7 @@ export const loadMsczUrl = async (scoreinfo: ScoreInfo, _fetch = getFetch()): Pr
|
|||
// read further error msg
|
||||
const err = cidRes.Message
|
||||
if (err.includes('no link named')) { // file not found
|
||||
throw new Error('Score not in dataset')
|
||||
throw new Error('score not in dataset')
|
||||
} else {
|
||||
throw new Error(err)
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
require("musescore-downloader/dist/cli.js")
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "msdl",
|
||||
"version": "%VERSION%",
|
||||
"author": "Xmader",
|
||||
"bin": "cli.js",
|
||||
"description": "Alias for musescore-downloader",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Xmader/musescore-downloader.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Xmader/musescore-downloader/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Xmader/musescore-downloader#readme",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"musescore-downloader": "%VERSION%"
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { name as pkgName, version as pkgVer } from '../package.json'
|
||||
import { getFetch } from './utils'
|
||||
|
||||
const IS_NPX_REG = /_npx(\/|\\)\d+\1/
|
||||
const NPM_REGISTRY = 'https://registry.npmjs.org'
|
||||
|
||||
export function isNpx (): boolean {
|
||||
// file is in a npx cache dir
|
||||
// TODO: installed locally?
|
||||
return __dirname.match(IS_NPX_REG) !== null
|
||||
}
|
||||
|
||||
export function getSelfVer (): string {
|
||||
return pkgVer
|
||||
}
|
||||
|
||||
export async function getLatestVer (_fetch = getFetch()): Promise<string> {
|
||||
// fetch pkg info from the npm registry
|
||||
const r = await _fetch(`${NPM_REGISTRY}/${pkgName}`)
|
||||
const json = await r.json()
|
||||
return json['dist-tags'].latest as string
|
||||
}
|
||||
|
||||
export async function getVerInfo () {
|
||||
const installed = getSelfVer()
|
||||
const latest = await getLatestVer()
|
||||
return {
|
||||
installed,
|
||||
latest,
|
||||
isLatest: installed === latest,
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import { getMainCid } from './mscz'
|
|||
|
||||
export abstract class ScoreInfo {
|
||||
private readonly RADIX = 20;
|
||||
private readonly INDEX_RADIX = 32;
|
||||
private readonly INDEX_RADIX = 40;
|
||||
|
||||
abstract id: number;
|
||||
abstract title: string;
|
||||
|
@ -28,7 +28,7 @@ export abstract class ScoreInfo {
|
|||
}
|
||||
|
||||
public getScorepackRef (mainCid: string): string {
|
||||
return `/ipfs/${mainCid}/index/${(+this.id) % this.INDEX_RADIX}/${this.id}`
|
||||
return `/ipfs/${mainCid}/index/${(+this.id) % this.INDEX_RADIX}/${this.id}/scorepack`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,22 +105,14 @@ export abstract class SheetInfo {
|
|||
export class SheetInfoInPage extends SheetInfo {
|
||||
constructor (private document: Document) { super() }
|
||||
|
||||
private get sheet0Img (): HTMLImageElement | null {
|
||||
return this.document.querySelector('img[src*=score_]')
|
||||
}
|
||||
|
||||
get pageCount (): number {
|
||||
const sheet0Div = this.sheet0Img?.parentElement
|
||||
if (!sheet0Div) {
|
||||
throw new Error('no sheet images found')
|
||||
}
|
||||
return this.document.getElementsByClassName(sheet0Div.className).length
|
||||
return this.document.querySelectorAll('.gXB83').length
|
||||
}
|
||||
|
||||
get thumbnailUrl (): string {
|
||||
// url to the image of the first page
|
||||
const el = this.document.querySelector<HTMLLinkElement>('link[as=image]')
|
||||
const url = (el?.href || this.sheet0Img?.src) as string
|
||||
const el = this.document.querySelector('link[as=image]') as HTMLLinkElement
|
||||
const url = el.href
|
||||
return url.split('@')[0]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
import isNodeJs from 'detect-node'
|
||||
import { isGmAvailable, _GM } from './gm'
|
||||
|
||||
export const DISCORD_URL = 'https://discord.gg/gSsTUvJmD8'
|
||||
|
||||
export const escapeFilename = (s: string): string => {
|
||||
return s.replace(/[\s<>:{}"/\\|?*~.\0\cA-\cZ]+/g, '_')
|
||||
}
|
||||
|
|
|
@ -6,9 +6,7 @@ import SVGtoPDF from 'svg-to-pdfkit'
|
|||
|
||||
type ImgType = 'svg' | 'png'
|
||||
|
||||
type DataResultType = 'dataUrl' | 'text'
|
||||
|
||||
const readData = (blob: Blob, type: DataResultType): Promise<string> => {
|
||||
const getDataURL = (blob: Blob): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onload = (): void => {
|
||||
|
@ -16,22 +14,22 @@ const readData = (blob: Blob, type: DataResultType): Promise<string> => {
|
|||
resolve(result as string)
|
||||
}
|
||||
reader.onerror = reject
|
||||
if (type === 'dataUrl') {
|
||||
reader.readAsDataURL(blob)
|
||||
} else {
|
||||
reader.readAsText(blob)
|
||||
}
|
||||
reader.readAsDataURL(blob)
|
||||
})
|
||||
}
|
||||
|
||||
const fetchBlob = async (imgUrl: string): Promise<Blob> => {
|
||||
const r = await fetch(imgUrl, {
|
||||
cache: 'no-cache',
|
||||
})
|
||||
return r.blob()
|
||||
const fetchDataURL = async (imgUrl: string): Promise<string> => {
|
||||
const r = await fetch(imgUrl)
|
||||
const blob = await r.blob()
|
||||
return getDataURL(blob)
|
||||
}
|
||||
|
||||
const generatePDF = async (imgBlobs: Blob[], imgType: ImgType, width: number, height: number): Promise<ArrayBuffer> => {
|
||||
const fetchText = async (imgUrl: string): Promise<string> => {
|
||||
const r = await fetch(imgUrl)
|
||||
return r.text()
|
||||
}
|
||||
|
||||
const generatePDF = async (imgURLs: string[], imgType: ImgType, width: number, height: number): Promise<ArrayBuffer> => {
|
||||
// @ts-ignore
|
||||
const pdf = new (PDFDocument as typeof import('pdfkit'))({
|
||||
// compress: true,
|
||||
|
@ -42,7 +40,7 @@ const generatePDF = async (imgBlobs: Blob[], imgType: ImgType, width: number, he
|
|||
})
|
||||
|
||||
if (imgType === 'png') {
|
||||
const imgDataUrlList: string[] = await Promise.all(imgBlobs.map(b => readData(b, 'dataUrl')))
|
||||
const imgDataUrlList: string[] = await Promise.all(imgURLs.map(fetchDataURL))
|
||||
|
||||
imgDataUrlList.forEach((data) => {
|
||||
pdf.addPage()
|
||||
|
@ -52,7 +50,7 @@ const generatePDF = async (imgBlobs: Blob[], imgType: ImgType, width: number, he
|
|||
})
|
||||
})
|
||||
} else { // imgType == "svg"
|
||||
const svgList = await Promise.all(imgBlobs.map(b => readData(b, 'text')))
|
||||
const svgList = await Promise.all(imgURLs.map(fetchText))
|
||||
|
||||
svgList.forEach((svg) => {
|
||||
pdf.addPage()
|
||||
|
@ -72,16 +70,14 @@ export type PDFWorkerMessage = [string[], ImgType, number, number];
|
|||
|
||||
onmessage = async (e): Promise<void> => {
|
||||
const [
|
||||
imgUrls,
|
||||
imgURLs,
|
||||
imgType,
|
||||
width,
|
||||
height,
|
||||
] = e.data as PDFWorkerMessage
|
||||
|
||||
const imgBlobs = await Promise.all(imgUrls.map(url => fetchBlob(url)))
|
||||
|
||||
const pdfBuf = await generatePDF(
|
||||
imgBlobs,
|
||||
imgURLs,
|
||||
imgType,
|
||||
width,
|
||||
height,
|
||||
|
|
|
@ -41,7 +41,7 @@ new Promise(resolve => {
|
|||
const loaderOutro = '})()'.repeat(stackN)
|
||||
const mockUrl = "https://c.amazon-adsystem.com/aax2/apstag.js"
|
||||
|
||||
Function(`${loaderIntro}const d=new Image();window['${id}'](d);delete window['${id}'];document.body.prepend(d)${loaderOutro}//# sourceURL=${mockUrl}`)()
|
||||
setTimeout(`${loaderIntro}const d=new Image();window['${id}'](d);delete window['${id}'];document.body.prepend(d)${loaderOutro}//# sourceURL=${mockUrl}`)
|
||||
}).then(d => {
|
||||
d.style.display = 'none';
|
||||
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
||||
|
|
Loading…
Reference in a new issue