Compare commits
156 commits
Author | SHA1 | Date | |
---|---|---|---|
|
8e3dd94c12 | ||
|
b1a3456646 | ||
|
d269ae9be9 | ||
|
20298e5c0e | ||
|
49880d63da | ||
|
0c2106993d | ||
|
3ac3a51ad1 | ||
|
9c05dd5d3d | ||
|
ae08ff847a | ||
|
8cc089357f | ||
|
4e92c06791 | ||
|
5d1639dddf | ||
|
88fdfff054 | ||
|
893c64edda | ||
|
1bf3050513 | ||
|
ffbac084fb | ||
|
861af6d3f0 | ||
|
30514e9507 | ||
|
7a397e068f | ||
|
d97b3d86d8 | ||
|
bef85c5c3e | ||
|
b68ff38028 | ||
|
a571fed456 | ||
|
f9be984d17 | ||
|
9adba49de1 | ||
|
6d93907df0 | ||
|
c5d6d87b8c | ||
|
8475941d47 | ||
|
71def367e8 | ||
|
d1c9634331 | ||
|
49aef0ccf3 | ||
|
ec15d44811 | ||
|
4494e15540 | ||
|
6a6e2a5ea1 | ||
|
3260672412 | ||
|
004cb16fce | ||
|
ec1c1ea87c | ||
|
69e5bd0a78 | ||
|
06a91b1c2d | ||
|
41f5286d48 | ||
|
29a09c2596 | ||
|
f2a52dd514 | ||
|
1e3e2d7581 | ||
|
eda8342a3d | ||
|
e9ed0812b9 | ||
|
4bd5d55676 | ||
|
c571a49093 | ||
|
b5477a4059 | ||
|
d33c06c892 | ||
|
04884a137f | ||
|
263f72dc7a | ||
|
c46343b46c | ||
|
6202321a42 | ||
|
3c72b5a92f | ||
|
085c6a2d2a | ||
|
1eb0f35bde | ||
|
49fcb99160 | ||
|
bd943675d8 | ||
|
030d37ddc0 | ||
|
d014ade9ca | ||
|
b8181f421d | ||
|
463ea5d416 | ||
|
da5d53898a | ||
|
2b842e267f | ||
|
08294f564b | ||
|
46a7f50115 | ||
|
7bb3aaf7b1 | ||
|
dd30454b5a | ||
|
d99848c6fc | ||
|
c973d5d06f | ||
|
d919441966 | ||
|
86c15d55fe | ||
|
1faaf660c4 | ||
|
8250d80d4b | ||
|
d9d09c4e8f | ||
|
20704eba75 | ||
|
3b329301c1 | ||
|
86c5429dce | ||
|
7f860faf66 | ||
|
de5ff6ff98 | ||
|
1b0d3d2eae | ||
|
28ac964ba3 | ||
|
44f7edfaa3 | ||
|
46879ffacd | ||
|
8945a53896 | ||
|
60d842bac7 | ||
|
bca9f5e150 | ||
|
519a5c3671 | ||
|
13031c323b | ||
|
2cfb060750 | ||
|
047fbf06b6 | ||
|
c01d797983 | ||
|
bb39ebccc9 | ||
|
8e0ce90093 | ||
|
d50fb677b4 | ||
|
003377e9ec | ||
|
2eca89e672 | ||
|
eb0f2b4b1d | ||
|
90d34bd05b | ||
|
541393eb0c | ||
|
2df57606e3 | ||
|
8e6992ab27 | ||
|
2d75ae45be | ||
|
e123108928 | ||
|
1a4efa76fa | ||
|
e5ffc4b9a2 | ||
|
e10e23ffec | ||
|
99bec9b4b4 | ||
|
5ea64e81d7 | ||
|
18da36a34a | ||
|
cc8bddd551 | ||
|
741684329a | ||
|
557a531e5b | ||
|
3f6818fde5 | ||
|
f6b8ab4413 | ||
|
05e147a03c | ||
|
f224edbc49 | ||
|
bdbcdd62e9 | ||
|
0522e5935c | ||
|
63bf02046a | ||
|
1831ffa7c8 | ||
|
334b452fcc | ||
|
ffa8683dbe | ||
|
9491f6c848 | ||
|
63ac2030a9 | ||
|
95ec4725e1 | ||
|
baa2be3ca3 | ||
|
c8467bf5b7 | ||
|
48c41d1c7c | ||
|
73ad8618c2 | ||
|
0e1f4aeafd | ||
|
b9d5ffa6fb | ||
|
9ee64ab7d5 | ||
|
3871a03127 | ||
|
4eb5134b68 | ||
|
2d635039b2 | ||
|
bc0b12d362 | ||
|
c11d6d2c48 | ||
|
2a29e378f2 | ||
|
b6837ee8e0 | ||
|
65c1e02d8b | ||
|
7f12c76413 | ||
|
e142c7a3db | ||
|
4b91be54a6 | ||
|
baf187ee46 | ||
|
f1412cdffa | ||
|
f53ff45057 | ||
|
9a3d16f86c | ||
|
58dc01224d | ||
|
32aa5e6938 | ||
|
79f139e663 | ||
|
f4d43443b9 | ||
|
6b5f0d3321 | ||
|
7fc1a5fb6a | ||
|
7485d884bf | ||
|
d171f46dfe |
31 changed files with 1279 additions and 188 deletions
|
@ -20,6 +20,8 @@
|
|||
"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",
|
||||
|
|
16
.github/workflows/release.yml
vendored
16
.github/workflows/release.yml
vendored
|
@ -13,12 +13,16 @@ on:
|
|||
ref:
|
||||
description: 'The branch, tag or SHA to release from'
|
||||
required: false
|
||||
chrome_ext_url:
|
||||
description: 'URL to the Chrome Extension crx'
|
||||
required: true
|
||||
|
||||
env:
|
||||
VERSION: ${{ github.event.inputs.version }}
|
||||
NPM_TAG: ${{ github.event.inputs.npm_tag }}
|
||||
REF: ${{ github.event.inputs.ref || github.sha }}
|
||||
ARTIFACTS_DIR: ./.artifacts
|
||||
CHROME_EXT_URL: ${{ github.event.inputs.chrome_ext_url }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
|
@ -49,6 +53,15 @@ 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
|
||||
|
@ -64,6 +77,8 @@ jobs:
|
|||
mkdir -p $ARTIFACTS_DIR
|
||||
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
|
||||
|
@ -83,6 +98,7 @@ jobs:
|
|||
IPFS_HASH: ${{ steps.ipfs.outputs.hash }}
|
||||
run: |
|
||||
cd $ARTIFACTS_DIR
|
||||
rm *.tar.gz
|
||||
|
||||
files=$(ls .)
|
||||
assets=()
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019-2020 Xmader
|
||||
Copyright (c) 2019-2021 Xmader
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
125
README.md
125
README.md
|
@ -1,7 +1,7 @@
|
|||
|
||||
# musescore-downloader
|
||||
|
||||
**English** | [简体中文](#musescore-downloader-1) | [Español](#musescore-downloader-2)
|
||||
**English** | [简体中文](#musescore-downloader-1) | [Español](#musescore-downloader-2) | [Italian](#musescore-downloader-3)
|
||||
|
||||
> download sheet music from musescore.com for free, no login or Musescore Pro required
|
||||
|
||||
|
@ -63,7 +63,7 @@ Install this script from <https://msdl.librescore.org/install.user.js>
|
|||
|
||||
The alternative method is to install this script as a Chrome or Firefox extension.
|
||||
|
||||
You may install the browser extension directly from [addons.mozilla.org (for Firefox)](https://addons.mozilla.org/en-US/firefox/addon/musescore-downloader/) or [chrome web store (for Chrome and Chromium based browsers)](https://chrome.google.com/webstore/detail/fmmnkcdlphpgbdcdfnjkldfljedbbokp).
|
||||
You may install the browser extension directly from [addons.mozilla.org (for Firefox)](https://addons.mozilla.org/en-US/firefox/addon/musescore-downloader/) or [chrome web store (for Chrome and Chromium based browsers)](https://chrome.google.com/webstore/detail/mhdlcdhakmmikknpefblmnhdhjloanjc).
|
||||
|
||||
The up-to-date version can be found on the [Github Releases](https://github.com/Xmader/musescore-downloader/releases) page.
|
||||
|
||||
|
@ -243,6 +243,7 @@ En tercer lugar, la propiedad de los derechos de autor de los contenidos de muse
|
|||
|
||||
Si no podemos ver pruebas de que musescore.com realmente paga la tarifa de licencia a los propietarios de los derechos de autor, podemos pensar que es solo una excusa para obtener ganancias robando.
|
||||
|
||||
|
||||
> utilizo ilegalmente nuestra API privada con contenido de música licenciada.
|
||||
|
||||
No, el documento de la API está en https://developers.musescore.com/.
|
||||
|
@ -251,3 +252,123 @@ No, el documento de la API está en https://developers.musescore.com/.
|
|||
**Lanzaré una alternativa de código abierto (GPLv3), sin servidor, offline, y totalmente gratuita a musescore.com, [LibreScore](https://github.com/LibreScore). ETodos son bienvenidos a unirse al desarrollo del proyecto abriendo un problema o [enviándome un correo electrónico.](mailto:i@xmader.com).**
|
||||
|
||||
**Además, estoy desarrollando musescore.js. Podría convertir un archivo mscz en cualquier formato que admita el software Musescore, y en el navegador.** Dado que el software Musescore es de código abierto bajo [GPL](https://github.com/musescore/MuseScore/blob/master/LICENSE.GPL), Podría traducir el código fuente a js o compilarlo en asm.js/WASM.
|
||||
|
||||
---
|
||||
|
||||
# musescore-downloader
|
||||
|
||||
[English](#musescore-downloader) | [简体中文](#musescore-downloader-1) | [Español](#musescore-downloader-2) | **Italian**
|
||||
|
||||
> Scarica spartiti da musescore.com gratuitamente, non è richisto login o Musescore Pro.
|
||||
|
||||
**Avvia questo progetto su [Github](https://github.com/Xmader/musescore-downloader) e [Gitlab](https://gitlab.com/Xmader/musescore-downloader)** (Mirror)
|
||||
|
||||
[![Discord](https://img.shields.io/discord/774491656643674122?color=7289da&label=Discord&logo=discord)](https://discord.gg/DKu7cUZ4XQ)
|
||||
|
||||
Hai bisogno di datset di musescore.com per l'analisi/machine learning? Prova [musescore-dataset](https://github.com/Xmader/musescore-dataset).
|
||||
|
||||
![](https://cdn.statically.io/gh/Xmader/musescore-downloader/master/screenshot.png?env=dev)
|
||||
|
||||
## Utilizzo leale
|
||||
|
||||
Solo per scopi di ricerca e studio
|
||||
|
||||
## In breve
|
||||
|
||||
Di recente è necessario un account Musescore Pro ($6,99/mese) per scaricare spartiti da musescore.com.
|
||||
(Tuttavia, alcuni mesi fa, era possibile scaricare gratuitamente.)
|
||||
|
||||
La società Musescore ha affermato che a causa di copyright e licenze, devono pagare i proprietari del copyright.
|
||||
|
||||
Molte musiche su musescore.com sono già di **Pubblico Dominio**, il che significa che o l'autore le ha pubblicate in pubblico dominio o l'autore è morto da oltre 70 anni.
|
||||
Devono pagare anche i compositori che sono morti centinaia di anni fa?
|
||||
*Aggiornamento: gli spartiti di Dominio Pubblico, ora possono essere scaricati senza Musescore Pro, ma hai ancora bisogno di un account per poter scaricare.*
|
||||
|
||||
|
||||
Inoltre, ci sono molti autori di spartiti su musescore.com che hanno creato le proprie canzoni e le hanno pubblicate sotto licenza [CC-BY-**NC** (Creative Commons Attribution-**NonCommercial**)](https://creativecommons.org/licenses/by-nc/4.0/).
|
||||
È illegale venderli **a scopo di lucro**?
|
||||
*Nota: Mettere annunci (per vendere Musescore Pro) sul sito web significa anche che lo usano per generare entrate.*
|
||||
|
||||
Questo è assolutamente inaccettabile e l'unico scopo è trarre profitto dal furto.
|
||||
|
||||
C'è un articolo sul loro sito web: [Il download degli spartiti diventa parte dell'abbonamento Pro](https://musescore.com/groups/improving-musescore-com/discuss/5044610)
|
||||
|
||||
## Installazione
|
||||
|
||||
### Utilizzo della CLI
|
||||
|
||||
(consigliato)
|
||||
|
||||
1. Installa Node.js LTS (https://nodejs.org/)
|
||||
2. Apri il terminale CMD o Powershell
|
||||
3. Digita `npx msdl`, e premi invio
|
||||
(`npx msdl` eseguirà sempre l'ultima versione)
|
||||
4. Seguire le istruzioni
|
||||
|
||||
[codice sorgente](/src/cli.ts)
|
||||
|
||||
### Installa come Userscript
|
||||
|
||||
Questo script è disponibile come [Userscript](https://en.wikipedia.org/wiki/Userscript). Per utilizzare questo Userscript, è necessario prima installare un [gestore di script utente].(https://greasyfork.org/en/help/installing-user-scripts), come Tampermonkey.
|
||||
|
||||
1. Installa [Tampermonkey](https://www.tampermonkey.net/)
|
||||
|
||||
2. ~~Installa da [Greasy Fork](https://greasyfork.org/scripts/391931).~~ [#42](https://github.com/Xmader/musescore-downloader/issues/42)
|
||||
Installa lo script da <https://msdl.librescore.org/install.user.js>
|
||||
|
||||
### Installa come estensione web
|
||||
|
||||
Il metodo alternativo consiste nell'installare questo script come estensione per Chrome o Firefox.
|
||||
|
||||
Puoi installare l'estensione del browser direttamente da [addons.mozilla.org (per Firefox)](https://addons.mozilla.org/en-US/firefox/addon/musescore-downloader/) o dal [web store di Chrome (per browser basati su Chrome e Chromium)](https://chrome.google.com/webstore/detail/mhdlcdhakmmikknpefblmnhdhjloanjc).
|
||||
|
||||
La versione aggiornata può essere trovata nella pagina [Github Releases](https://github.com/Xmader/musescore-downloader/releases).
|
||||
|
||||
## Istruzioni per il building
|
||||
|
||||
Assicurati di avere installato [Node.js](https://nodejs.org/en/).
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run build # build come script utente
|
||||
npm run pack:ext # pack Web Extension
|
||||
```
|
||||
|
||||
## Mirrors
|
||||
|
||||
* Visualizza questo progetto su [Github](https://github.com/Xmader/musescore-downloader) (Repo principale) | [Gitlab](https://gitlab.com/Xmader/musescore-downloader) (Mirror)
|
||||
|
||||
* Questo repo è disponibile anche su IPFS per evitare la rimozione DMCA: [ipns://msdl.librescore.org](https://ipfs.io/ipns/msdl.librescore.org/)
|
||||
|
||||
## Feedback
|
||||
|
||||
[Problemi con GitHub](https://github.com/Xmader/musescore-downloader/issues)
|
||||
|
||||
## Licenza
|
||||
|
||||
MIT
|
||||
|
||||
## Informazioni sulla richiesta di rimozione
|
||||
|
||||
Ho ricevuto un'e-mail di [richiesta di rimozione](https://github.com/Xmader/musescore-downloader/issues/5)da uno degli sviluppatori di Musescore, ma ho qualcosa da ridire.
|
||||
|
||||
> Non tutti i contenuti di pubblico dominio su musescore.com sono concessi in licenza dai principali editori musicali (Alfred, EMI, Sony, ecc.). State distribuendo gratuitamente contenuti musicali con licenza da Musescore.com violando i loro diritti.
|
||||
|
||||
In primo luogo, se violi i diritti dei principali editori musicali, la richiesta di rimozione dovrebbe essere inviata da loro invece che dagli sviluppatori di Musescore.
|
||||
|
||||
In secondo luogo, musescore.com non è un semplice sito di condivisione di musica. Gli autori di spartiti devono trascrivere e riorganizzare le canzoni originali in spartiti, non solo copiare file da qualche altra parte su musescore.com. Di conseguenza, la licenza dovrebbe concentrarsi sui diritti di trascrizione / riorganizzazione degli autori di spartiti, invece che sui diritti di condivisione della musica su alcuni siti web.
|
||||
|
||||
In terzo luogo, la proprietà del copyright dei contenuti su musescore.com non è chiara. Non tutte le canzoni di pubblico dominio su musescore.com sono di proprietà dei principali editori musicali. Ci sono molti piccoli editori musicali e cantautori indipendenti. Le canzoni potrebbero essere concesse in licenza con licenze gratuite come Creative Commons. Inoltre, ci sono molti autori che hanno creato le proprie canzoni e pubblicato gli spartiti su musescore.com; Musescore.com paga questi autori?
|
||||
|
||||
Se ci sono prove che musescore.com paga davvero la tassa di licenza ai proprietari del copyright, potremmo pensare che sia solo una scusa per ottenere profitto dal furto.
|
||||
|
||||
> utilizzi illegalmente la nostra API privata con contenuti musicali con licenza.
|
||||
|
||||
No, il documento API è su https://developers.musescore.com/.
|
||||
|
||||
|
||||
**Avvierò un'alternativa open source (GPLv3), serverless, offline-first, frontend-first e totalmente gratuita a musescore.com, [LibreScore](https://github.com/LibreScore). Tutti sono invitati a partecipare allo sviluppo del progetto aprendo una issue o [inviandomi un'e-mail](mailto:i@xmader.com).**
|
||||
|
||||
**Inoltre, sto sviluppando musescore.js. Potrebbe convertire un file mscz in qualsiasi formato supportato dal software Musescore e nel browser.** Poiché il software Musescore è open source sotto [GPL](https://github.com/musescore/MuseScore/blob/master/LICENSE.GPL), potrei tradurre il codice sorgente in js o compilarlo in asm.js/WASM.
|
||||
|
||||
---
|
||||
|
|
532
dist/main.js
vendored
532
dist/main.js
vendored
|
@ -5,19 +5,75 @@
|
|||
// @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.19.5
|
||||
// @version 0.24.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/*/*
|
||||
// @match https://s.musescore.com/*/*
|
||||
// @license MIT
|
||||
// @copyright Copyright (c) 2019-2020 Xmader
|
||||
// @copyright Copyright (c) 2019-2021 Xmader
|
||||
// @grant unsafeWindow
|
||||
// @grant GM.registerMenuCommand
|
||||
// @grant GM.addElement
|
||||
// @grant GM.openInTab
|
||||
// @run-at document-start
|
||||
// ==/UserScript==
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/* eslint-disable */
|
||||
const w = typeof unsafeWindow == 'object' ? unsafeWindow : window;
|
||||
|
||||
// GM APIs glue
|
||||
const _GM = typeof GM == 'object' ? GM : undefined;
|
||||
const gmId = '' + Math.random();
|
||||
w[gmId] = _GM;
|
||||
|
||||
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(
|
||||
'** Source Code **',
|
||||
() => _GM.openInTab(_GM.info.script.homepage, { active: true })
|
||||
)
|
||||
|
||||
_GM.registerMenuCommand(
|
||||
'** Discord **',
|
||||
() => _GM.openInTab("https://discord.gg/DKu7cUZ4XQ", { active: true })
|
||||
)
|
||||
}
|
||||
|
||||
function getRandL () {
|
||||
return String.fromCharCode(97 + Math.floor(Math.random() * 26))
|
||||
}
|
||||
|
||||
// script loader
|
||||
new Promise(resolve => {
|
||||
const id = '' + Math.random();
|
||||
w[id] = resolve;
|
||||
|
||||
const stackN = 9
|
||||
let loaderIntro = ''
|
||||
for (let i = 0; i < stackN; i++) {
|
||||
loaderIntro += `(function ${getRandL()}(){`
|
||||
}
|
||||
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}`)()
|
||||
}).then(d => {
|
||||
d.style.display = 'none';
|
||||
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
||||
d.once = false;
|
||||
d.setAttribute('onload', `if(this.once)return;this.once=true;this.remove();const GM=window['${gmId}'];delete window['${gmId}'];(` + function a () {
|
||||
/** script code here */
|
||||
|
||||
|
||||
function __awaiter(thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
|
@ -269,16 +325,32 @@
|
|||
// Only Node.JS has a process variable that is of [[Class]] process
|
||||
var detectNode = Object.prototype.toString.call(typeof process$1 !== 'undefined' ? process$1 : 0) === '[object process]';
|
||||
|
||||
const _GM = (typeof GM === 'object' ? GM : undefined);
|
||||
const isGmAvailable = (requiredMethod = 'info') => {
|
||||
return typeof GM !== 'undefined' &&
|
||||
typeof GM[requiredMethod] !== 'undefined';
|
||||
};
|
||||
|
||||
const DISCORD_URL = 'https://discord.gg/gSsTUvJmD8';
|
||||
const escapeFilename = (s) => {
|
||||
return s.replace(/[\s<>:{}"/\\|?*~.\0\cA-\cZ]+/g, '_');
|
||||
};
|
||||
const NODE_FETCH_HEADERS = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
|
||||
'Accept-Language': 'en-US,en;q=0.8',
|
||||
};
|
||||
const getFetch = () => {
|
||||
if (!detectNode) {
|
||||
return fetch;
|
||||
}
|
||||
else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return require('node-fetch');
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const nodeFetch = require('node-fetch');
|
||||
return (input, init) => {
|
||||
init = Object.assign({ headers: NODE_FETCH_HEADERS }, init);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return nodeFetch(input, init);
|
||||
};
|
||||
}
|
||||
};
|
||||
const fetchData = (url, init) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
|
@ -304,6 +376,12 @@
|
|||
const getSandboxWindowAsync = (targetEl = undefined) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (typeof document === 'undefined')
|
||||
return {};
|
||||
if (isGmAvailable('addElement')) {
|
||||
// create iframe using GM_addElement API
|
||||
const iframe = yield _GM.addElement('iframe', {});
|
||||
iframe.style.display = 'none';
|
||||
return iframe.contentWindow;
|
||||
}
|
||||
if (!targetEl) {
|
||||
return new Promise((resolve) => {
|
||||
// You need ads in your pages, right?
|
||||
|
@ -345,16 +423,20 @@
|
|||
const attachShadow = (el) => {
|
||||
return Element.prototype.attachShadow.call(el, { mode: 'closed' });
|
||||
};
|
||||
const waitForDocumentLoaded = () => {
|
||||
/**
|
||||
* Run script before the page is fully loaded
|
||||
*/
|
||||
const waitForSheetLoaded = () => {
|
||||
if (document.readyState !== 'complete') {
|
||||
return new Promise(resolve => {
|
||||
const cb = () => {
|
||||
if (document.readyState === 'complete') {
|
||||
const observer = new MutationObserver(() => {
|
||||
const img = document.querySelector('img');
|
||||
if (img) {
|
||||
resolve();
|
||||
document.removeEventListener('readystatechange', cb);
|
||||
observer.disconnect();
|
||||
}
|
||||
};
|
||||
document.addEventListener('readystatechange', cb);
|
||||
});
|
||||
observer.observe(document, { childList: true, subtree: true });
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
@ -26358,7 +26440,7 @@ Please pipe the document into a Node stream.\
|
|||
});
|
||||
|
||||
/// <reference lib="webworker" />
|
||||
const getDataURL = (blob) => {
|
||||
const readData = (blob, type) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
|
@ -26366,19 +26448,21 @@ Please pipe the document into a Node stream.\
|
|||
resolve(result);
|
||||
};
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(blob);
|
||||
if (type === 'dataUrl') {
|
||||
reader.readAsDataURL(blob);
|
||||
}
|
||||
else {
|
||||
reader.readAsText(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 fetchBlob = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const r = yield fetch(imgUrl, {
|
||||
cache: 'no-cache',
|
||||
});
|
||||
return r.blob();
|
||||
});
|
||||
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* () {
|
||||
const generatePDF = (imgBlobs, imgType, width, height) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
// @ts-ignore
|
||||
const pdf = new PDFDocument({
|
||||
// compress: true,
|
||||
|
@ -26388,7 +26472,7 @@ Please pipe the document into a Node stream.\
|
|||
layout: 'portrait',
|
||||
});
|
||||
if (imgType === 'png') {
|
||||
const imgDataUrlList = yield Promise.all(imgURLs.map(fetchDataURL));
|
||||
const imgDataUrlList = yield Promise.all(imgBlobs.map(b => readData(b, 'dataUrl')));
|
||||
imgDataUrlList.forEach((data) => {
|
||||
pdf.addPage();
|
||||
pdf.image(data, {
|
||||
|
@ -26398,7 +26482,7 @@ Please pipe the document into a Node stream.\
|
|||
});
|
||||
}
|
||||
else { // imgType == "svg"
|
||||
const svgList = yield Promise.all(imgURLs.map(fetchText));
|
||||
const svgList = yield Promise.all(imgBlobs.map(b => readData(b, 'text')));
|
||||
svgList.forEach((svg) => {
|
||||
pdf.addPage();
|
||||
source(pdf, svg, 0, 0, {
|
||||
|
@ -26411,8 +26495,9 @@ 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 pdfBuf = yield generatePDF(imgURLs, imgType, width, height);
|
||||
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);
|
||||
postMessage(pdfBuf, [pdfBuf]);
|
||||
});
|
||||
|
||||
|
@ -26421,7 +26506,7 @@ Please pipe the document into a Node stream.\
|
|||
|
||||
const scriptUrlFromFunction = (fn) => {
|
||||
const blob = new Blob(['(' + fn.toString() + ')()'], { type: 'application/javascript' });
|
||||
return URL.createObjectURL(blob);
|
||||
return window.URL.createObjectURL(blob);
|
||||
};
|
||||
class PDFWorkerHelper extends Worker {
|
||||
constructor() {
|
||||
|
@ -26445,12 +26530,96 @@ Please pipe the document into a Node stream.\
|
|||
}
|
||||
|
||||
/* eslint-disable no-extend-native */
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
/**
|
||||
* make hooked methods "native"
|
||||
*/
|
||||
const makeNative = (() => {
|
||||
const l = new Map();
|
||||
hookNative(Function.prototype, 'toString', (_toString) => {
|
||||
return function () {
|
||||
if (l.has(this)) {
|
||||
const _fn = l.get(this) || parseInt; // "function () {\n [native code]\n}"
|
||||
if (l.has(_fn)) { // nested
|
||||
return _fn.toString();
|
||||
}
|
||||
else {
|
||||
return _toString.call(_fn);
|
||||
}
|
||||
}
|
||||
return _toString.call(this);
|
||||
};
|
||||
}, true);
|
||||
return (fn, original) => {
|
||||
l.set(fn, original);
|
||||
};
|
||||
})();
|
||||
function hookNative(target, method, hook, async = false) {
|
||||
// reserve for future hook update
|
||||
const _fn = target[method];
|
||||
const detach = () => {
|
||||
target[method] = _fn; // detach
|
||||
};
|
||||
// This script can run before anything on the page,
|
||||
// so setting this function to be non-configurable and non-writable is no use.
|
||||
const hookedFn = hook(_fn, detach);
|
||||
target[method] = hookedFn;
|
||||
if (!async) {
|
||||
makeNative(hookedFn, _fn);
|
||||
}
|
||||
else {
|
||||
setTimeout(() => {
|
||||
makeNative(hookedFn, _fn);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* eslint-disable no-extend-native */
|
||||
const TYPE_REG = /type=(img|mp3|midi)/;
|
||||
/**
|
||||
* I know this is super hacky.
|
||||
*/
|
||||
const magicHookConstr = (() => {
|
||||
const l = {};
|
||||
try {
|
||||
const p = Object.getPrototypeOf(document.body);
|
||||
Object.setPrototypeOf(document.body, null);
|
||||
hookNative(document.body, 'append', () => {
|
||||
return function (...nodes) {
|
||||
p.append.call(this, ...nodes);
|
||||
if (nodes[0].nodeName === 'IFRAME') {
|
||||
const iframe = nodes[0];
|
||||
const w = iframe.contentWindow;
|
||||
hookNative(w, 'fetch', () => {
|
||||
return function (url, init) {
|
||||
var _a, _b;
|
||||
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];
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
(_b = l[type]) === null || _b === void 0 ? void 0 : _b.call(l, token);
|
||||
}
|
||||
}
|
||||
return fetch(url, init);
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
Object.setPrototypeOf(document.body, p);
|
||||
}
|
||||
catch (err) {
|
||||
console$1.error(err);
|
||||
}
|
||||
return (type) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
return new Promise((resolve) => {
|
||||
l[type] = (token) => {
|
||||
resolve(token);
|
||||
magics[type] = token;
|
||||
};
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
@ -26469,12 +26638,12 @@ Please pipe the document into a Node stream.\
|
|||
// force to retrieve the MAGIC
|
||||
switch (type) {
|
||||
case 'midi': {
|
||||
const el = document.querySelectorAll('.SD7H- > button')[3];
|
||||
const el = document.querySelector('button[hasaccess]');
|
||||
el.click();
|
||||
break;
|
||||
}
|
||||
case 'mp3': {
|
||||
const el = document.querySelector('#playerBtnExprt');
|
||||
const el = document.querySelector('button[title="Toggle Play"]');
|
||||
el.click();
|
||||
break;
|
||||
}
|
||||
|
@ -26567,7 +26736,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);
|
||||
|
@ -26626,6 +26795,9 @@ Please pipe the document into a Node stream.\
|
|||
'IND_PARTS_TOOLTIP'() {
|
||||
return 'Download individual parts (BETA)';
|
||||
},
|
||||
'VIEW_IN_LIBRESCORE'() {
|
||||
return 'View in LibreScore';
|
||||
},
|
||||
'FULL_SCORE'() {
|
||||
return 'Full score';
|
||||
},
|
||||
|
@ -26639,7 +26811,7 @@ Please pipe the document into a Node stream.\
|
|||
return '❌¡Descarga Fallida!';
|
||||
},
|
||||
'DEPRECATION_NOTICE'(btnName) {
|
||||
return `¡OBSOLETO!\nParecer ser que \`${btnName}\` no funciona correctamente, use \`Partes Indivduales\` en su lugar.\n(Esto todavía puede funcionar. Haga click en \`Aceptar\` para continuar.)`;
|
||||
return `¡OBSOLETO!\nUtilizar \`${btnName}\` dentro de \`Partes Indivduales\` en su lugar.\n(Esto todavía puede funcionar. Pulsa \`Aceptar\` para continuar.)`;
|
||||
},
|
||||
'DOWNLOAD'(fileType) {
|
||||
return `Descargar ${fileType}`;
|
||||
|
@ -26653,14 +26825,79 @@ Please pipe the document into a Node stream.\
|
|||
'IND_PARTS_TOOLTIP'() {
|
||||
return 'Descargar partes individuales (BETA)';
|
||||
},
|
||||
'VIEW_IN_LIBRESCORE'() {
|
||||
return 'Visualizar en LibreScore';
|
||||
},
|
||||
'FULL_SCORE'() {
|
||||
return 'Partitura Completa';
|
||||
},
|
||||
});
|
||||
|
||||
var it = createLocale({
|
||||
'PROCESSING'() {
|
||||
return 'Caricamento…';
|
||||
},
|
||||
'BTN_ERROR'() {
|
||||
return '❌Download Fallito!';
|
||||
},
|
||||
'DEPRECATION_NOTICE'(btnName) {
|
||||
return `¡DEPRECATO!\nUtilizzare \`${btnName}\` all'interno di \`Parti Indivduali\`.\n(Qusto potrebbe funzionare. Cliccare \`Ok\` per continuare.)`;
|
||||
},
|
||||
'DOWNLOAD'(fileType) {
|
||||
return `Scaricare ${fileType}`;
|
||||
},
|
||||
'DOWNLOAD_AUDIO'(fileType) {
|
||||
return `Scaricare ${fileType} Audio`;
|
||||
},
|
||||
'IND_PARTS'() {
|
||||
return 'Parti Singole';
|
||||
},
|
||||
'IND_PARTS_TOOLTIP'() {
|
||||
return 'Scaricare Parti Singole (BETA)';
|
||||
},
|
||||
'VIEW_IN_LIBRESCORE'() {
|
||||
return 'Visualizzare in LibreScore';
|
||||
},
|
||||
'FULL_SCORE'() {
|
||||
return 'Spartito Completo';
|
||||
},
|
||||
});
|
||||
|
||||
var zh = createLocale({
|
||||
'PROCESSING'() {
|
||||
return '处理中…';
|
||||
},
|
||||
'BTN_ERROR'() {
|
||||
return '❌下载失败!';
|
||||
},
|
||||
'DEPRECATION_NOTICE'(btnName) {
|
||||
return `不建议使用\n请使用 \`单独分谱\` 里的 \`${btnName}\` 按钮代替\n(这也许仍会起作用。单击\`确定\`以继续。)`;
|
||||
},
|
||||
'DOWNLOAD'(fileType) {
|
||||
return `下载 ${fileType}`;
|
||||
},
|
||||
'DOWNLOAD_AUDIO'(fileType) {
|
||||
return `下载 ${fileType} 音频`;
|
||||
},
|
||||
'IND_PARTS'() {
|
||||
return '单独分谱';
|
||||
},
|
||||
'IND_PARTS_TOOLTIP'() {
|
||||
return '下载单独分谱 (BETA)';
|
||||
},
|
||||
'VIEW_IN_LIBRESCORE'() {
|
||||
return '在 LibreScore 中查看';
|
||||
},
|
||||
'FULL_SCORE'() {
|
||||
return '完整乐谱';
|
||||
},
|
||||
});
|
||||
|
||||
const locales = ((l) => Object.freeze(l))({
|
||||
en,
|
||||
es,
|
||||
it,
|
||||
zh,
|
||||
});
|
||||
// detect browser language
|
||||
const lang = (() => {
|
||||
|
@ -26686,12 +26923,22 @@ 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@0.10/webmscore.js';
|
||||
const WEBMSCORE_URL = `https://cdn.jsdelivr.net/npm/webmscore@${dependencies.webmscore}/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/SourceHanSans${l}-Regular.woff2`);
|
||||
const SF3_URL = 'https://cdn.jsdelivr.net/npm/@librescore/sf3/FluidR3Mono_GM.sf3';
|
||||
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 SOUND_FONT_LOADED = Symbol('SoundFont loaded');
|
||||
const initMscore = (w) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (!detectNode) { // attached to a page
|
||||
|
@ -26773,6 +27020,11 @@ Please pipe the document into a Node stream.\
|
|||
fileExt: 'mid',
|
||||
action: (score) => score.saveMidi(true, true),
|
||||
},
|
||||
{
|
||||
name: i18n('DOWNLOAD_AUDIO')('MP3'),
|
||||
fileExt: 'mp3',
|
||||
action: (score) => loadSoundFont(score).then(() => score.saveAudio('mp3')),
|
||||
},
|
||||
{
|
||||
name: i18n('DOWNLOAD_AUDIO')('FLAC'),
|
||||
fileExt: 'flac',
|
||||
|
@ -26785,30 +27037,57 @@ Please pipe the document into a Node stream.\
|
|||
},
|
||||
];
|
||||
|
||||
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 position: fixed;\n z-index: 999;\n background: #f6f6f6;\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}";
|
||||
const _getLink = (indexingInfo) => {
|
||||
const { scorepack } = JSON.parse(indexingInfo);
|
||||
return `https://librescore.org/score/${scorepack}`;
|
||||
};
|
||||
const getLibreScoreLink = (scoreinfo, _fetch = getFetch()) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const mainCid = yield getMainCid(scoreinfo, _fetch);
|
||||
const ref = scoreinfo.getScorepackRef(mainCid);
|
||||
const url = `https://ipfs.infura.io:5001/api/v0/dag/get?arg=${ref}`;
|
||||
const r0 = yield _fetch(url);
|
||||
if (r0.status !== 500) {
|
||||
assertRes(r0);
|
||||
}
|
||||
const res = yield r0.json();
|
||||
if (typeof res !== 'string') {
|
||||
// read further error msg
|
||||
throw new Error(res.Message);
|
||||
}
|
||||
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 ICON;
|
||||
(function (ICON) {
|
||||
ICON["DOWNLOAD"] = "M9.6 2.4h4.8V12h2.784l-5.18 5.18L6.823 12H9.6V2.4zM19.2 19.2H4.8v2.4h14.4v-2.4z";
|
||||
ICON["LIBRESCORE"] = "m5.4837 4.4735v10.405c-1.25-0.89936-3.0285-0.40896-4.1658 0.45816-1.0052 0.76659-1.7881 2.3316-0.98365 3.4943 1 1.1346 2.7702 0.70402 3.8817-0.02809 1.0896-0.66323 1.9667-1.8569 1.8125-3.1814v-5.4822h8.3278v9.3865h9.6438v-2.6282h-6.4567v-12.417c-4.0064-0.015181-8.0424-0.0027-12.06-0.00676zm0.54477 2.2697h8.3278v1.1258h-8.3278v-1.1258z";
|
||||
})(ICON || (ICON = {}));
|
||||
const getBtnContainer = () => {
|
||||
const containers = [...document.querySelectorAll('section>div div')];
|
||||
const btnParent = containers.find(c => {
|
||||
return [...c.children].find((div) => {
|
||||
const b = div.querySelector('button, .button');
|
||||
const text = b ? b.outerHTML.replace(/\s/g, '') : '';
|
||||
return text.includes('Download') || text.includes('Print');
|
||||
});
|
||||
var _a;
|
||||
const els = [...document.querySelectorAll('span')];
|
||||
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');
|
||||
});
|
||||
if (!btnParent)
|
||||
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))
|
||||
throw new Error('btn parent not found');
|
||||
return btnParent;
|
||||
};
|
||||
const buildDownloadBtn = () => {
|
||||
const buildDownloadBtn = (icon, lightTheme = false) => {
|
||||
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', 'M9.6 2.4h4.8V12h2.784l-5.18 5.18L6.823 12H9.6V2.4zM19.2 19.2H4.8v2.4h14.4v-2.4z');
|
||||
svgPath.setAttribute('fill', '#fff');
|
||||
svgPath.setAttribute('d', icon);
|
||||
svgPath.setAttribute('fill', lightTheme ? '#2e68c0' : '#fff');
|
||||
svg.append(svgPath);
|
||||
const textNode = document.createElement('span');
|
||||
btn.append(svg, textNode);
|
||||
|
@ -26819,6 +27098,30 @@ Please pipe the document into a Node stream.\
|
|||
n.onclick = btn.onclick;
|
||||
return n;
|
||||
};
|
||||
function getScrollParent(node) {
|
||||
if (node.scrollHeight > node.clientHeight) {
|
||||
return node;
|
||||
}
|
||||
else {
|
||||
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";
|
||||
|
@ -26830,7 +27133,8 @@ Please pipe the document into a Node stream.\
|
|||
this.list = [];
|
||||
}
|
||||
add(options) {
|
||||
const btnTpl = buildDownloadBtn();
|
||||
var _a;
|
||||
const btnTpl = buildDownloadBtn((_a = options.icon) !== null && _a !== void 0 ? _a : ICON.DOWNLOAD, options.lightTheme);
|
||||
const setText = (btn) => {
|
||||
const textNode = btn.querySelector('span');
|
||||
return (str) => {
|
||||
|
@ -26850,27 +27154,49 @@ Please pipe the document into a Node stream.\
|
|||
if (options.tooltip) {
|
||||
btnTpl.title = options.tooltip;
|
||||
}
|
||||
// add buttons to the userscript manager menu
|
||||
if (isGmAvailable('registerMenuCommand')) {
|
||||
// eslint-disable-next-line no-void
|
||||
void _GM.registerMenuCommand(options.name, () => {
|
||||
options.action(options.name, btnTpl, () => undefined);
|
||||
});
|
||||
}
|
||||
return btnTpl;
|
||||
}
|
||||
_positionBtns(anchorDiv, newParent) {
|
||||
let { top } = anchorDiv.getBoundingClientRect();
|
||||
top += window.scrollY; // relative to the entire document instead of viewport
|
||||
if (top > 0) {
|
||||
newParent.style.top = `${top}px`;
|
||||
}
|
||||
else {
|
||||
newParent.style.top = '0px';
|
||||
}
|
||||
}
|
||||
_commit() {
|
||||
let btnParent = document.createElement('div');
|
||||
try {
|
||||
btnParent = this.getBtnParent();
|
||||
}
|
||||
catch (err) {
|
||||
console$1.error(err);
|
||||
}
|
||||
const btnParent = document.querySelector('div');
|
||||
const shadow = attachShadow(btnParent);
|
||||
// style the shadow DOM
|
||||
const style = document.createElement('style');
|
||||
style.innerText = btnListCss;
|
||||
shadow.append(style);
|
||||
// hide buttons using the shadow DOM
|
||||
const newParent = btnParent.cloneNode(false);
|
||||
newParent.append(...this.list.map(e => cloneBtn(e)));
|
||||
shadow.append(newParent);
|
||||
const slot = document.createElement('slot');
|
||||
shadow.append(slot);
|
||||
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) => {
|
||||
const pos = () => this._positionBtns(anchorDiv, newParent);
|
||||
pos();
|
||||
// reposition btns when window resizes
|
||||
window.addEventListener('resize', pos, { passive: true });
|
||||
// reposition btns when scrolling
|
||||
const scroll = getScrollParent(anchorDiv);
|
||||
scroll.addEventListener('scroll', pos, { passive: true });
|
||||
});
|
||||
return btnParent;
|
||||
}
|
||||
/**
|
||||
|
@ -26880,24 +27206,17 @@ Please pipe the document into a Node stream.\
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
switch (mode) {
|
||||
case BtnListMode.InPage: {
|
||||
// fallback to BtnListMode.ExtWindow
|
||||
let el;
|
||||
try {
|
||||
this.getBtnParent();
|
||||
el = this._commit();
|
||||
}
|
||||
catch (_a) {
|
||||
// fallback to BtnListMode.ExtWindow
|
||||
return this.commit(BtnListMode.ExtWindow);
|
||||
}
|
||||
let el = this._commit();
|
||||
const observer = new MutationObserver(() => {
|
||||
// check if the buttons are still in document when dom updates
|
||||
if (!document.contains(el)) {
|
||||
try {
|
||||
this.getBtnParent();
|
||||
}
|
||||
catch (_a) {
|
||||
observer.disconnect();
|
||||
this.commit(BtnListMode.ExtWindow);
|
||||
}
|
||||
// re-commit
|
||||
// performance issue?
|
||||
el = this._commit();
|
||||
|
@ -26929,14 +27248,17 @@ Please pipe the document into a Node stream.\
|
|||
else
|
||||
return url;
|
||||
};
|
||||
BtnAction.download = (url, fallback, timeout) => {
|
||||
BtnAction.download = (url, fallback, timeout, target) => {
|
||||
return BtnAction.process(() => __awaiter(this, void 0, void 0, function* () {
|
||||
const _url = yield normalizeUrlInput(url);
|
||||
const a = document.createElement('a');
|
||||
a.href = _url;
|
||||
if (target)
|
||||
a.target = target;
|
||||
a.dispatchEvent(new MouseEvent('click'));
|
||||
}), fallback, timeout);
|
||||
};
|
||||
BtnAction.openUrl = BtnAction.download;
|
||||
BtnAction.mscoreWindow = (scoreinfo, fn) => {
|
||||
return (btnName, btn, setText) => __awaiter(this, void 0, void 0, function* () {
|
||||
const _onclick = btn.onclick;
|
||||
|
@ -26981,6 +27303,15 @@ 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;
|
||||
|
@ -26998,6 +27329,7 @@ Please pipe the document into a Node stream.\
|
|||
class ScoreInfo {
|
||||
constructor() {
|
||||
this.RADIX = 20;
|
||||
this.INDEX_RADIX = 32;
|
||||
this.store = new Map();
|
||||
}
|
||||
get idLastDigit() {
|
||||
|
@ -27012,6 +27344,9 @@ Please pipe the document into a Node stream.\
|
|||
getMsczCidUrl(mainCid) {
|
||||
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}`;
|
||||
}
|
||||
}
|
||||
class ScoreInfoInPage extends ScoreInfo {
|
||||
constructor(document) {
|
||||
|
@ -27027,6 +27362,11 @@ Please pipe the document into a Node stream.\
|
|||
const el = this.document.querySelector("meta[property='og:title']");
|
||||
return el.content;
|
||||
}
|
||||
get baseUrl() {
|
||||
const el = this.document.querySelector("meta[property='og:image']");
|
||||
const m = el.content.match(/^(.+\/)score_/);
|
||||
return m[1];
|
||||
}
|
||||
}
|
||||
class SheetInfo {
|
||||
get imgType() {
|
||||
|
@ -27040,22 +27380,56 @@ Please pipe the document into a Node stream.\
|
|||
super();
|
||||
this.document = document;
|
||||
}
|
||||
get sheet0Img() {
|
||||
return this.document.querySelector('img[src*=score_]');
|
||||
}
|
||||
get pageCount() {
|
||||
return this.document.querySelectorAll('.gXB83').length;
|
||||
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;
|
||||
}
|
||||
get thumbnailUrl() {
|
||||
var _a;
|
||||
// url to the image of the first page
|
||||
const el = this.document.querySelector('link[as=image]');
|
||||
const url = el.href;
|
||||
const url = ((el === null || el === void 0 ? void 0 : el.href) || ((_a = this.sheet0Img) === null || _a === void 0 ? void 0 : _a.src));
|
||||
return url.split('@')[0];
|
||||
}
|
||||
}
|
||||
const getActualId = (scoreinfo, _fetch = getFetch()) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (scoreinfo.id <= 1000000000000) {
|
||||
// actual id already
|
||||
return scoreinfo.id;
|
||||
}
|
||||
const mainCid = yield getMainCid(scoreinfo, _fetch);
|
||||
const ref = `${mainCid}/sid2id/${scoreinfo.id}`;
|
||||
const url = `https://ipfs.infura.io:5001/api/v0/dag/get?arg=${ref}`;
|
||||
const r0 = yield _fetch(url);
|
||||
if (r0.status !== 500) {
|
||||
assertRes(r0);
|
||||
}
|
||||
const res = yield r0.json();
|
||||
if (typeof res !== 'number') {
|
||||
// read further error msg
|
||||
throw new Error(res.Message);
|
||||
}
|
||||
// assign the actual id back to scoreinfo
|
||||
Object.defineProperty(scoreinfo, 'id', {
|
||||
get() { return res; },
|
||||
});
|
||||
return res;
|
||||
});
|
||||
|
||||
const { saveAs } = FileSaver_min;
|
||||
const main = () => {
|
||||
const btnList = new BtnList();
|
||||
const scoreinfo = new ScoreInfoInPage(document);
|
||||
const { fileName, id } = scoreinfo;
|
||||
const { fileName } = scoreinfo;
|
||||
// eslint-disable-next-line no-void
|
||||
void getActualId(scoreinfo);
|
||||
let indvPartBtn = null;
|
||||
const fallback = () => {
|
||||
// btns fallback to load from MSCZ file (`Individual Parts`)
|
||||
|
@ -27070,7 +27444,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')('MusicXML'),
|
||||
name: i18n('DOWNLOAD')('MXL'),
|
||||
action: BtnAction.mscoreWindow(scoreinfo, (w, score) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const mxl = yield score.saveMxl();
|
||||
const data = new Blob([mxl]);
|
||||
|
@ -27080,11 +27454,11 @@ Please pipe the document into a Node stream.\
|
|||
});
|
||||
btnList.add({
|
||||
name: i18n('DOWNLOAD')('MIDI'),
|
||||
action: BtnAction.download(() => getFileUrl(id, 'midi'), fallback, 30 * 1000 /* 30s */),
|
||||
action: BtnAction.download(() => getFileUrl(scoreinfo.id, 'midi'), fallback, 30 * 1000 /* 30s */),
|
||||
});
|
||||
btnList.add({
|
||||
name: i18n('DOWNLOAD')('MP3'),
|
||||
action: BtnAction.download(() => getFileUrl(id, 'mp3'), fallback, 30 * 1000 /* 30s */),
|
||||
action: BtnAction.download(() => getFileUrl(scoreinfo.id, 'mp3'), fallback, 30 * 1000 /* 30s */),
|
||||
});
|
||||
indvPartBtn = btnList.add({
|
||||
name: i18n('IND_PARTS')(),
|
||||
|
@ -27145,9 +27519,19 @@ Please pipe the document into a Node stream.\
|
|||
}
|
||||
})),
|
||||
});
|
||||
btnList.add({
|
||||
name: i18n('VIEW_IN_LIBRESCORE')(),
|
||||
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
|
||||
waitForDocumentLoaded().then(main);
|
||||
waitForSheetLoaded().then(main);
|
||||
|
||||
}.toString() + ')()')})
|
||||
|
||||
}());
|
||||
|
|
40
package-lock.json
generated
40
package-lock.json
generated
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"name": "musescore-downloader",
|
||||
"version": "0.19.5",
|
||||
"version": "0.24.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@librescore/fonts": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@librescore/fonts/-/fonts-0.2.1.tgz",
|
||||
"integrity": "sha512-lzEk82wZWZVA4CvE2S6Wwc6EAvFZ0G6L2ExNjpJLebxAh0k/eNpHeO9a2LFwfMVUfacVWwXhDkAbmJpvUGcqzA=="
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@librescore/fonts/-/fonts-0.4.0.tgz",
|
||||
"integrity": "sha512-T286OfxcQAYc/Bll9AtSP2ElggqTpoa08uY9Kgx6z1TcDVn7i7uMkKVO7sw/8aELWFNRmQE2vGQuEkmJNfWmBA=="
|
||||
},
|
||||
"@librescore/sf3": {
|
||||
"version": "0.3.0",
|
||||
|
@ -709,18 +709,26 @@
|
|||
}
|
||||
},
|
||||
"elliptic": {
|
||||
"version": "6.5.3",
|
||||
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
|
||||
"integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
|
||||
"version": "6.5.4",
|
||||
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
|
||||
"integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bn.js": "^4.4.0",
|
||||
"brorand": "^1.0.1",
|
||||
"bn.js": "^4.11.9",
|
||||
"brorand": "^1.1.0",
|
||||
"hash.js": "^1.0.0",
|
||||
"hmac-drbg": "^1.0.0",
|
||||
"inherits": "^2.0.1",
|
||||
"minimalistic-assert": "^1.0.0",
|
||||
"minimalistic-crypto-utils": "^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
|
||||
}
|
||||
}
|
||||
},
|
||||
"emoji-regex": {
|
||||
|
@ -2431,9 +2439,9 @@
|
|||
}
|
||||
},
|
||||
"webmscore": {
|
||||
"version": "0.10.4",
|
||||
"resolved": "https://registry.npmjs.org/webmscore/-/webmscore-0.10.4.tgz",
|
||||
"integrity": "sha512-aKFXfK5QpRfJ0xBn+zRV4/HVS4VI6tr+pLkLIHI0n0rMtSBWlkcUeP8eCfP1c1f5LRlrTIaAo4yKZ6Hxg5O7kw=="
|
||||
"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=="
|
||||
},
|
||||
"word-wrap": {
|
||||
"version": "1.2.3",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "musescore-downloader",
|
||||
"version": "0.19.5",
|
||||
"version": "0.24.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",
|
||||
|
@ -25,7 +25,7 @@
|
|||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"*://musescore.com/*/*"
|
||||
"*://*.musescore.com/*/*"
|
||||
],
|
||||
"js": [
|
||||
"src/web-ext.js"
|
||||
|
@ -37,13 +37,13 @@
|
|||
"dist/main.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@librescore/fonts": "^0.2.1",
|
||||
"@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.10.4"
|
||||
"webmscore": "^0.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
|
|
|
@ -15,6 +15,11 @@ const getBannerText = () => {
|
|||
return bannerText
|
||||
}
|
||||
|
||||
const getWrapper = (startL, endL) => {
|
||||
const js = fs.readFileSync("./src/wrapper.js", "utf-8")
|
||||
return js.split(/\n/g).slice(startL, endL).join("\n")
|
||||
}
|
||||
|
||||
const basePlugins = [
|
||||
typescript({
|
||||
target: "ES6",
|
||||
|
@ -83,6 +88,8 @@ export default [
|
|||
format: "iife",
|
||||
sourcemap: false,
|
||||
banner: getBannerText,
|
||||
intro: () => getWrapper(0, -1),
|
||||
outro: () => getWrapper(-1)
|
||||
},
|
||||
plugins,
|
||||
},
|
||||
|
|
56
src/btn.css
56
src/btn.css
|
@ -1,31 +1,46 @@
|
|||
div {
|
||||
flex-wrap: wrap;
|
||||
display: flex;
|
||||
width: 422px;
|
||||
right: 0;
|
||||
margin: 0 18px 18px 0;
|
||||
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
font-family: 'Open Sans', 'Roboto', 'Helvetica neue', Helvetica, sans-serif;
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
font-family: 'Inter', '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) {
|
||||
div {
|
||||
width: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
width: 205px !important;
|
||||
height: 38px;
|
||||
width: 178px !important;
|
||||
min-width: 178px;
|
||||
height: 40px;
|
||||
|
||||
color: #fff;
|
||||
background: #1f74bd;
|
||||
background: #2e68c0;
|
||||
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
|
||||
margin-bottom: 4px;
|
||||
margin-right: 4px;
|
||||
margin-bottom: 8px;
|
||||
margin-right: 8px;
|
||||
padding: 4px 12px;
|
||||
|
||||
justify-content: start;
|
||||
align-self: center;
|
||||
|
||||
font-size: 16px;
|
||||
border-radius: 2px;
|
||||
border-radius: 6px;
|
||||
border: 0;
|
||||
|
||||
display: inline-flex;
|
||||
|
@ -34,6 +49,25 @@ 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;
|
||||
|
|
133
src/btn.ts
133
src/btn.ts
|
@ -1,36 +1,41 @@
|
|||
|
||||
import { ScoreInfo } from './scoreinfo'
|
||||
import { loadMscore, WebMscore } from './mscore'
|
||||
import { useTimeout, windowOpenAsync, console, attachShadow } from './utils'
|
||||
import { useTimeout, windowOpenAsync, console, attachShadow, DISCORD_URL } from './utils'
|
||||
import { isGmAvailable, _GM } from './gm'
|
||||
import i18n from './i18n'
|
||||
// @ts-ignore
|
||||
import btnListCss from './btn.css'
|
||||
|
||||
type BtnElement = HTMLButtonElement
|
||||
|
||||
export enum ICON {
|
||||
DOWNLOAD = 'M9.6 2.4h4.8V12h2.784l-5.18 5.18L6.823 12H9.6V2.4zM19.2 19.2H4.8v2.4h14.4v-2.4z',
|
||||
LIBRESCORE = 'm5.4837 4.4735v10.405c-1.25-0.89936-3.0285-0.40896-4.1658 0.45816-1.0052 0.76659-1.7881 2.3316-0.98365 3.4943 1 1.1346 2.7702 0.70402 3.8817-0.02809 1.0896-0.66323 1.9667-1.8569 1.8125-3.1814v-5.4822h8.3278v9.3865h9.6438v-2.6282h-6.4567v-12.417c-4.0064-0.015181-8.0424-0.0027-12.06-0.00676zm0.54477 2.2697h8.3278v1.1258h-8.3278v-1.1258z',
|
||||
}
|
||||
|
||||
const getBtnContainer = (): HTMLDivElement => {
|
||||
const containers = [...document.querySelectorAll('section>div div')]
|
||||
const btnParent = containers.find(c => {
|
||||
return [...c.children].find((div) => {
|
||||
const b = div.querySelector('button, .button')
|
||||
const text = b ? b.outerHTML.replace(/\s/g, '') : ''
|
||||
return text.includes('Download') || text.includes('Print')
|
||||
})
|
||||
const els = [...document.querySelectorAll('span')]
|
||||
const el = els.find(b => {
|
||||
const text = b?.textContent?.replace(/\s/g, '') || ''
|
||||
return text.includes('Download') || text.includes('Print')
|
||||
}) as HTMLDivElement | null
|
||||
if (!btnParent) throw new Error('btn parent not found')
|
||||
const btnParent = el?.parentElement?.parentElement as HTMLDivElement | undefined
|
||||
if (!btnParent || !(btnParent instanceof HTMLDivElement)) throw new Error('btn parent not found')
|
||||
return btnParent
|
||||
}
|
||||
|
||||
const buildDownloadBtn = () => {
|
||||
const buildDownloadBtn = (icon: ICON, lightTheme = false) => {
|
||||
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', 'M9.6 2.4h4.8V12h2.784l-5.18 5.18L6.823 12H9.6V2.4zM19.2 19.2H4.8v2.4h14.4v-2.4z')
|
||||
svgPath.setAttribute('fill', '#fff')
|
||||
svgPath.setAttribute('d', icon)
|
||||
svgPath.setAttribute('fill', lightTheme ? '#2e68c0' : '#fff')
|
||||
svg.append(svgPath)
|
||||
|
||||
const textNode = document.createElement('span')
|
||||
|
@ -45,11 +50,36 @@ const cloneBtn = (btn: HTMLButtonElement) => {
|
|||
return n
|
||||
}
|
||||
|
||||
function getScrollParent (node: HTMLElement): HTMLElement {
|
||||
if (node.scrollHeight > node.clientHeight) {
|
||||
return node
|
||||
} else {
|
||||
return getScrollParent(node.parentNode as 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 {
|
||||
|
@ -63,7 +93,7 @@ export class BtnList {
|
|||
constructor (private getBtnParent: () => HTMLDivElement = getBtnContainer) { }
|
||||
|
||||
add (options: BtnOptions): BtnElement {
|
||||
const btnTpl = buildDownloadBtn()
|
||||
const btnTpl = buildDownloadBtn(options.icon ?? ICON.DOWNLOAD, options.lightTheme)
|
||||
const setText = (btn: BtnElement) => {
|
||||
const textNode = btn.querySelector('span')
|
||||
return (str: string): void => {
|
||||
|
@ -88,16 +118,29 @@ export class BtnList {
|
|||
btnTpl.title = options.tooltip
|
||||
}
|
||||
|
||||
// add buttons to the userscript manager menu
|
||||
if (isGmAvailable('registerMenuCommand')) {
|
||||
// eslint-disable-next-line no-void
|
||||
void _GM.registerMenuCommand(options.name, () => {
|
||||
options.action(options.name, btnTpl, () => undefined)
|
||||
})
|
||||
}
|
||||
|
||||
return btnTpl
|
||||
}
|
||||
|
||||
private _commit () {
|
||||
let btnParent: HTMLDivElement = document.createElement('div')
|
||||
try {
|
||||
btnParent = this.getBtnParent()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
private _positionBtns (anchorDiv: HTMLDivElement, newParent: HTMLDivElement) {
|
||||
let { top } = anchorDiv.getBoundingClientRect()
|
||||
top += window.scrollY // relative to the entire document instead of viewport
|
||||
if (top > 0) {
|
||||
newParent.style.top = `${top}px`
|
||||
} else {
|
||||
newParent.style.top = '0px'
|
||||
}
|
||||
}
|
||||
|
||||
private _commit () {
|
||||
const btnParent = document.querySelector('div') as HTMLDivElement
|
||||
const shadow = attachShadow(btnParent)
|
||||
|
||||
// style the shadow DOM
|
||||
|
@ -106,12 +149,28 @@ export class BtnList {
|
|||
shadow.append(style)
|
||||
|
||||
// hide buttons using the shadow DOM
|
||||
const newParent = btnParent.cloneNode(false) as HTMLDivElement
|
||||
newParent.append(...this.list.map(e => cloneBtn(e)))
|
||||
shadow.append(newParent)
|
||||
const slot = document.createElement('slot')
|
||||
shadow.append(slot)
|
||||
|
||||
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: HTMLDivElement) => {
|
||||
const pos = () => this._positionBtns(anchorDiv, newParent)
|
||||
pos()
|
||||
|
||||
// reposition btns when window resizes
|
||||
window.addEventListener('resize', pos, { passive: true })
|
||||
|
||||
// reposition btns when scrolling
|
||||
const scroll = getScrollParent(anchorDiv)
|
||||
scroll.addEventListener('scroll', pos, { passive: true })
|
||||
})
|
||||
|
||||
return btnParent
|
||||
}
|
||||
|
||||
|
@ -121,24 +180,16 @@ export class BtnList {
|
|||
async commit (mode: BtnListMode = BtnListMode.InPage): Promise<void> {
|
||||
switch (mode) {
|
||||
case BtnListMode.InPage: {
|
||||
// fallback to BtnListMode.ExtWindow
|
||||
let el: Element
|
||||
try {
|
||||
this.getBtnParent()
|
||||
el = this._commit()
|
||||
} catch {
|
||||
// fallback to BtnListMode.ExtWindow
|
||||
return this.commit(BtnListMode.ExtWindow)
|
||||
}
|
||||
|
||||
let el: Element = this._commit()
|
||||
const observer = new MutationObserver(() => {
|
||||
// check if the buttons are still in document when dom updates
|
||||
if (!document.contains(el)) {
|
||||
try {
|
||||
this.getBtnParent()
|
||||
} catch {
|
||||
observer.disconnect()
|
||||
this.commit(BtnListMode.ExtWindow)
|
||||
}
|
||||
|
||||
// re-commit
|
||||
// performance issue?
|
||||
el = this._commit()
|
||||
|
@ -176,15 +227,18 @@ export namespace BtnAction {
|
|||
else return url
|
||||
}
|
||||
|
||||
export const download = (url: UrlInput, fallback?: () => Promisable<void>, timeout?: number): BtnAction => {
|
||||
export const download = (url: UrlInput, fallback?: () => Promisable<void>, timeout?: number, target?: '_blank'): BtnAction => {
|
||||
return process(async (): Promise<void> => {
|
||||
const _url = await normalizeUrlInput(url)
|
||||
const a = document.createElement('a')
|
||||
a.href = _url
|
||||
if (target) a.target = target
|
||||
a.dispatchEvent(new MouseEvent('click'))
|
||||
}, fallback, timeout)
|
||||
}
|
||||
|
||||
export const openUrl = download
|
||||
|
||||
export const mscoreWindow = (scoreinfo: ScoreInfo, fn: (w: Window, score: WebMscore, processingTextEl: ChildNode) => any): BtnAction => {
|
||||
return async (btnName, btn, setText) => {
|
||||
const _onclick = btn.onclick
|
||||
|
@ -234,6 +288,17 @@ 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'))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
63
src/cli.ts
63
src/cli.ts
|
@ -4,17 +4,21 @@
|
|||
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import os from 'os'
|
||||
import { fetchMscz, setMscz, MSCZ_URL_SYM } from './mscz'
|
||||
import { loadMscore, INDV_DOWNLOADS, WebMscore } from './mscore'
|
||||
import { ScoreInfo, ScoreInfoHtml, ScoreInfoObj } from './scoreinfo'
|
||||
import { escapeFilename } from './utils'
|
||||
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 i18n from './i18n'
|
||||
|
||||
const inquirer: typeof import('inquirer') = require('inquirer')
|
||||
const ora: typeof import('ora') = require('ora')
|
||||
const chalk: typeof import('chalk') = require('chalk')
|
||||
|
||||
const SCORE_URL_PREFIX = 'https://musescore.com/'
|
||||
const SCORE_URL_PREFIX = 'https://(s.)musescore.com/'
|
||||
const SCORE_URL_REG = /https:\/\/(s\.)?musescore\.com\//
|
||||
const EXT = '.mscz'
|
||||
|
||||
interface Params {
|
||||
|
@ -26,27 +30,50 @@ 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 = ''
|
||||
if (platform === 'win32') {
|
||||
pasteMessage = 'right-click to paste'
|
||||
} else if (platform === 'linux') {
|
||||
pasteMessage = 'usually Ctrl+Shift+V to paste'
|
||||
} // For MacOS, no hint is needed because the paste shortcut is universal.
|
||||
|
||||
let scoreinfo: ScoreInfo
|
||||
let librescoreLink: Promise<string> | undefined
|
||||
// ask for the page url or path to local file
|
||||
const { fileInit } = await inquirer.prompt<Params>({
|
||||
type: 'input',
|
||||
name: 'fileInit',
|
||||
message: 'Score URL or path to local MSCZ file:',
|
||||
suffix: `\n (starts with "${SCORE_URL_PREFIX}" or local filepath ends with "${EXT}")\n `,
|
||||
suffix: '\n ' +
|
||||
`(starts with "${SCORE_URL_PREFIX}" or local filepath ends with "${EXT}") ` +
|
||||
`${chalk.bgGray(pasteMessage)}\n `,
|
||||
validate (input: string) {
|
||||
return input &&
|
||||
(
|
||||
input.startsWith(SCORE_URL_PREFIX) ||
|
||||
!!input.match(SCORE_URL_REG) ||
|
||||
(input.endsWith(EXT) && fs.statSync(input).isFile())
|
||||
)
|
||||
},
|
||||
default: process.argv[2],
|
||||
default: arg,
|
||||
})
|
||||
|
||||
const isLocalFile = fileInit.endsWith(EXT)
|
||||
if (!isLocalFile) {
|
||||
// request scoreinfo
|
||||
scoreinfo = await ScoreInfoHtml.request(fileInit)
|
||||
try {
|
||||
await getActualId(scoreinfo as any)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
// confirmation
|
||||
const { confirmed } = await inquirer.prompt<Params>({
|
||||
|
@ -59,7 +86,13 @@ void (async () => {
|
|||
default: true,
|
||||
})
|
||||
if (!confirmed) return
|
||||
console.log() // print a blank line to the terminal
|
||||
|
||||
// initiate LibreScore link request
|
||||
librescoreLink = getLibreScoreLink(scoreinfo)
|
||||
librescoreLink.catch(() => '') // silence this unhandled Promise rejection
|
||||
|
||||
// print a blank line to the terminal
|
||||
console.log()
|
||||
} else {
|
||||
scoreinfo = new ScoreInfoObj(0, path.basename(fileInit, EXT))
|
||||
}
|
||||
|
@ -87,6 +120,11 @@ void (async () => {
|
|||
if (!isLocalFile) {
|
||||
spinner.info(`File URL: ${scoreinfo.store.get(MSCZ_URL_SYM) as string}`)
|
||||
}
|
||||
if (librescoreLink) {
|
||||
try {
|
||||
spinner.info(`${i18n('VIEW_IN_LIBRESCORE')()}: ${await librescoreLink}`)
|
||||
} catch { } // it doesn't affect the main feature
|
||||
}
|
||||
spinner.start()
|
||||
|
||||
// load score using webmscore
|
||||
|
@ -96,6 +134,10 @@ 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')
|
||||
|
@ -154,4 +196,11 @@ 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.`))
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
|
43
src/file.ts
43
src/file.ts
|
@ -1,16 +1,55 @@
|
|||
/* eslint-disable no-extend-native */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
|
||||
import { hookNative } from './anti-detection'
|
||||
import { console } from './utils'
|
||||
|
||||
type FileType = 'img' | 'mp3' | 'midi'
|
||||
|
||||
const TYPE_REG = /type=(img|mp3|midi)/
|
||||
|
||||
/**
|
||||
* I know this is super hacky.
|
||||
*/
|
||||
const magicHookConstr = (() => {
|
||||
const l = {}
|
||||
|
||||
try {
|
||||
const p = Object.getPrototypeOf(document.body)
|
||||
Object.setPrototypeOf(document.body, null)
|
||||
|
||||
hookNative(document.body, 'append', () => {
|
||||
return function (...nodes: Node[]) {
|
||||
p.append.call(this, ...nodes)
|
||||
|
||||
if (nodes[0].nodeName === 'IFRAME') {
|
||||
const iframe = nodes[0] as HTMLIFrameElement
|
||||
const w = iframe.contentWindow as Window
|
||||
|
||||
hookNative(w, 'fetch', () => {
|
||||
return function (url, init) {
|
||||
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]
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
l[type]?.(token)
|
||||
}
|
||||
}
|
||||
return fetch(url, init)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Object.setPrototypeOf(document.body, p)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
return async (type: FileType) => {
|
||||
return new Promise<string>((resolve) => {
|
||||
l[type] = (token) => {
|
||||
|
@ -40,12 +79,12 @@ const getApiAuth = async (type: FileType, index: number): Promise<string> => {
|
|||
// force to retrieve the MAGIC
|
||||
switch (type) {
|
||||
case 'midi': {
|
||||
const el = document.querySelectorAll('.SD7H- > button')[3] as HTMLButtonElement
|
||||
const el = document.querySelector('button[hasaccess]') as HTMLButtonElement
|
||||
el.click()
|
||||
break
|
||||
}
|
||||
case 'mp3': {
|
||||
const el = document.querySelector('#playerBtnExprt') as HTMLButtonElement
|
||||
const el = document.querySelector('button[title="Toggle Play"]') as HTMLButtonElement
|
||||
el.click()
|
||||
break
|
||||
}
|
||||
|
|
22
src/gm.ts
Normal file
22
src/gm.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
/**
|
||||
* UserScript APIs
|
||||
*/
|
||||
declare const GM: {
|
||||
/** https://www.tampermonkey.net/documentation.php#GM_info */
|
||||
info: Record<string, any>;
|
||||
|
||||
/** https://www.tampermonkey.net/documentation.php#GM_registerMenuCommand */
|
||||
registerMenuCommand (name: string, fn: () => any, accessKey?: string): Promise<number>;
|
||||
|
||||
/** https://github.com/Tampermonkey/tampermonkey/issues/881#issuecomment-639705679 */
|
||||
addElement<K extends keyof HTMLElementTagNameMap> (tagName: K, properties: Record<string, any>): Promise<HTMLElementTagNameMap[K]>;
|
||||
}
|
||||
export const _GM = (typeof GM === 'object' ? GM : undefined) as GM
|
||||
|
||||
type GM = typeof GM
|
||||
|
||||
export const isGmAvailable = (requiredMethod: keyof GM = 'info'): boolean => {
|
||||
return typeof GM !== 'undefined' &&
|
||||
typeof GM[requiredMethod] !== 'undefined'
|
||||
}
|
|
@ -27,6 +27,10 @@ export default createLocale({
|
|||
return 'Download individual parts (BETA)' as const
|
||||
},
|
||||
|
||||
'VIEW_IN_LIBRESCORE' () {
|
||||
return 'View in LibreScore' as const
|
||||
},
|
||||
|
||||
'FULL_SCORE' () {
|
||||
return 'Full score' as const
|
||||
},
|
||||
|
|
|
@ -10,7 +10,7 @@ export default createLocale({
|
|||
},
|
||||
|
||||
'DEPRECATION_NOTICE' (btnName: string) {
|
||||
return `¡OBSOLETO!\nParecer ser que \`${btnName}\` no funciona correctamente, use \`Partes Indivduales\` en su lugar.\n(Esto todavía puede funcionar. Haga click en \`Aceptar\` para continuar.)` as const
|
||||
return `¡OBSOLETO!\nUtilizar \`${btnName}\` dentro de \`Partes Indivduales\` en su lugar.\n(Esto todavía puede funcionar. Pulsa \`Aceptar\` para continuar.)` as const
|
||||
},
|
||||
|
||||
'DOWNLOAD' <T extends string> (fileType: T) {
|
||||
|
@ -27,6 +27,10 @@ export default createLocale({
|
|||
return 'Descargar partes individuales (BETA)' as const
|
||||
},
|
||||
|
||||
'VIEW_IN_LIBRESCORE' () {
|
||||
return 'Visualizar en LibreScore' as const
|
||||
},
|
||||
|
||||
'FULL_SCORE' () {
|
||||
return 'Partitura Completa' as const
|
||||
},
|
||||
|
|
|
@ -3,6 +3,8 @@ import isNodeJs from 'detect-node'
|
|||
|
||||
import en from './en'
|
||||
import es from './es'
|
||||
import it from './it'
|
||||
import zh from './zh'
|
||||
|
||||
export interface LOCALE {
|
||||
'PROCESSING' (): string;
|
||||
|
@ -16,12 +18,16 @@ export interface LOCALE {
|
|||
'IND_PARTS' (): string;
|
||||
'IND_PARTS_TOOLTIP' (): string;
|
||||
|
||||
'VIEW_IN_LIBRESCORE' (): string;
|
||||
|
||||
'FULL_SCORE' (): string;
|
||||
}
|
||||
|
||||
const locales = (<L extends { [n: string]: LOCALE } /** type checking */> (l: L) => Object.freeze(l))({
|
||||
en,
|
||||
es,
|
||||
it,
|
||||
zh,
|
||||
})
|
||||
|
||||
// detect browser language
|
||||
|
|
37
src/i18n/it.ts
Normal file
37
src/i18n/it.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
import { createLocale } from './utils'
|
||||
|
||||
export default createLocale({
|
||||
'PROCESSING' () {
|
||||
return 'Caricamento…' as const
|
||||
},
|
||||
'BTN_ERROR' () {
|
||||
return '❌Download Fallito!' as const
|
||||
},
|
||||
|
||||
'DEPRECATION_NOTICE' (btnName: string) {
|
||||
return `¡DEPRECATO!\nUtilizzare \`${btnName}\` all'interno di \`Parti Indivduali\`.\n(Qusto potrebbe funzionare. Cliccare \`Ok\` per continuare.)` as const
|
||||
},
|
||||
|
||||
'DOWNLOAD' <T extends string> (fileType: T) {
|
||||
return `Scaricare ${fileType}` as const
|
||||
},
|
||||
'DOWNLOAD_AUDIO' <T extends string> (fileType: T) {
|
||||
return `Scaricare ${fileType} Audio` as const
|
||||
},
|
||||
|
||||
'IND_PARTS' () {
|
||||
return 'Parti Singole' as const
|
||||
},
|
||||
'IND_PARTS_TOOLTIP' () {
|
||||
return 'Scaricare Parti Singole (BETA)' as const
|
||||
},
|
||||
|
||||
'VIEW_IN_LIBRESCORE' () {
|
||||
return 'Visualizzare in LibreScore' as const
|
||||
},
|
||||
|
||||
'FULL_SCORE' () {
|
||||
return 'Spartito Completo' as const
|
||||
},
|
||||
})
|
37
src/i18n/zh.ts
Normal file
37
src/i18n/zh.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
import { createLocale } from './utils'
|
||||
|
||||
export default createLocale({
|
||||
'PROCESSING' () {
|
||||
return '处理中…' as const
|
||||
},
|
||||
'BTN_ERROR' () {
|
||||
return '❌下载失败!' as const
|
||||
},
|
||||
|
||||
'DEPRECATION_NOTICE' (btnName: string) {
|
||||
return `不建议使用\n请使用 \`单独分谱\` 里的 \`${btnName}\` 按钮代替\n(这也许仍会起作用。单击\`确定\`以继续。)` as const
|
||||
},
|
||||
|
||||
'DOWNLOAD' <T extends string> (fileType: T) {
|
||||
return `下载 ${fileType}` as const
|
||||
},
|
||||
'DOWNLOAD_AUDIO' <T extends string> (fileType: T) {
|
||||
return `下载 ${fileType} 音频` as const
|
||||
},
|
||||
|
||||
'IND_PARTS' () {
|
||||
return '单独分谱' as const
|
||||
},
|
||||
'IND_PARTS_TOOLTIP' () {
|
||||
return '下载单独分谱 (BETA)' as const
|
||||
},
|
||||
|
||||
'VIEW_IN_LIBRESCORE' () {
|
||||
return '在 LibreScore 中查看' as const
|
||||
},
|
||||
|
||||
'FULL_SCORE' () {
|
||||
return '完整乐谱' as const
|
||||
},
|
||||
})
|
26
src/librescore-link.ts
Normal file
26
src/librescore-link.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
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}`
|
||||
}
|
||||
|
||||
export const getLibreScoreLink = async (scoreinfo: ScoreInfo, _fetch = getFetch()): Promise<string> => {
|
||||
const mainCid = await getMainCid(scoreinfo, _fetch)
|
||||
const ref = scoreinfo.getScorepackRef(mainCid)
|
||||
const url = `https://ipfs.infura.io:5001/api/v0/dag/get?arg=${ref}`
|
||||
|
||||
const r0 = await _fetch(url)
|
||||
if (r0.status !== 500) {
|
||||
assertRes(r0)
|
||||
}
|
||||
const res: { Message: string } | string = await r0.json()
|
||||
if (typeof res !== 'string') {
|
||||
// read further error msg
|
||||
throw new Error(res.Message)
|
||||
}
|
||||
|
||||
return _getLink(res)
|
||||
}
|
29
src/main.ts
29
src/main.ts
|
@ -1,13 +1,14 @@
|
|||
import './meta'
|
||||
|
||||
import FileSaver from 'file-saver'
|
||||
import { waitForDocumentLoaded, console } from './utils'
|
||||
import { waitForSheetLoaded, console } from './utils'
|
||||
import { downloadPDF } from './pdf'
|
||||
import { downloadMscz } from './mscz'
|
||||
import { getFileUrl } from './file'
|
||||
import { INDV_DOWNLOADS } from './mscore'
|
||||
import { BtnList, BtnAction, BtnListMode } from './btn'
|
||||
import { ScoreInfoInPage, SheetInfoInPage } from './scoreinfo'
|
||||
import { getLibreScoreLink } from './librescore-link'
|
||||
import { BtnList, BtnAction, BtnListMode, ICON } from './btn'
|
||||
import { ScoreInfoInPage, SheetInfoInPage, getActualId } from './scoreinfo'
|
||||
import i18n from './i18n'
|
||||
|
||||
const { saveAs } = FileSaver
|
||||
|
@ -15,7 +16,10 @@ const { saveAs } = FileSaver
|
|||
const main = (): void => {
|
||||
const btnList = new BtnList()
|
||||
const scoreinfo = new ScoreInfoInPage(document)
|
||||
const { fileName, id } = scoreinfo
|
||||
const { fileName } = scoreinfo
|
||||
|
||||
// eslint-disable-next-line no-void
|
||||
void getActualId(scoreinfo)
|
||||
|
||||
let indvPartBtn: HTMLButtonElement | null = null
|
||||
const fallback = () => {
|
||||
|
@ -34,7 +38,7 @@ const main = (): void => {
|
|||
})
|
||||
|
||||
btnList.add({
|
||||
name: i18n('DOWNLOAD')('MusicXML'),
|
||||
name: i18n('DOWNLOAD')('MXL'),
|
||||
action: BtnAction.mscoreWindow(scoreinfo, async (w, score) => {
|
||||
const mxl = await score.saveMxl()
|
||||
const data = new Blob([mxl])
|
||||
|
@ -45,12 +49,12 @@ const main = (): void => {
|
|||
|
||||
btnList.add({
|
||||
name: i18n('DOWNLOAD')('MIDI'),
|
||||
action: BtnAction.download(() => getFileUrl(id, 'midi'), fallback, 30 * 1000 /* 30s */),
|
||||
action: BtnAction.download(() => getFileUrl(scoreinfo.id, 'midi'), fallback, 30 * 1000 /* 30s */),
|
||||
})
|
||||
|
||||
btnList.add({
|
||||
name: i18n('DOWNLOAD')('MP3'),
|
||||
action: BtnAction.download(() => getFileUrl(id, 'mp3'), fallback, 30 * 1000 /* 30s */),
|
||||
action: BtnAction.download(() => getFileUrl(scoreinfo.id, 'mp3'), fallback, 30 * 1000 /* 30s */),
|
||||
})
|
||||
|
||||
indvPartBtn = btnList.add({
|
||||
|
@ -128,8 +132,17 @@ const main = (): void => {
|
|||
}),
|
||||
})
|
||||
|
||||
btnList.add({
|
||||
name: i18n('VIEW_IN_LIBRESCORE')(),
|
||||
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
|
||||
waitForDocumentLoaded().then(main)
|
||||
waitForSheetLoaded().then(main)
|
||||
|
|
|
@ -8,9 +8,14 @@
|
|||
// @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
|
||||
// @copyright Copyright (c) 2019-2020 Xmader
|
||||
// @copyright Copyright (c) 2019-2021 Xmader
|
||||
// @grant unsafeWindow
|
||||
// @grant GM.registerMenuCommand
|
||||
// @grant GM.addElement
|
||||
// @grant GM.openInTab
|
||||
// @run-at document-start
|
||||
// ==/UserScript==
|
||||
|
|
|
@ -6,14 +6,15 @@ 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@0.10/webmscore.js'
|
||||
const WEBMSCORE_URL = `https://cdn.jsdelivr.net/npm/webmscore@${depVers.webmscore}/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/SourceHanSans${l}-Regular.woff2`)
|
||||
const FONT_URLS = ['CN', 'KR'].map(l => `https://cdn.jsdelivr.net/npm/@librescore/fonts@${depVers['@librescore/fonts']}/SourceHanSans${l}.min.woff2`)
|
||||
|
||||
const SF3_URL = 'https://cdn.jsdelivr.net/npm/@librescore/sf3/FluidR3Mono_GM.sf3'
|
||||
const SF3_URL = `https://cdn.jsdelivr.net/npm/@librescore/sf3@${depVers['@librescore/sf3']}/FluidR3Mono_GM.sf3`
|
||||
const SOUND_FONT_LOADED = Symbol('SoundFont loaded')
|
||||
|
||||
export type WebMscore = import('webmscore').default
|
||||
|
@ -118,6 +119,11 @@ export const INDV_DOWNLOADS: IndividualDownload[] = [
|
|||
fileExt: 'mid',
|
||||
action: (score) => score.saveMidi(true, true),
|
||||
},
|
||||
{
|
||||
name: i18n('DOWNLOAD_AUDIO')('MP3'),
|
||||
fileExt: 'mp3',
|
||||
action: (score) => loadSoundFont(score).then(() => score.saveAudio('mp3')),
|
||||
},
|
||||
{
|
||||
name: i18n('DOWNLOAD_AUDIO')('FLAC'),
|
||||
fileExt: 'flac',
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
2
src/msdl/cli.js
Normal file
2
src/msdl/cli.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env node
|
||||
require("musescore-downloader/dist/cli.js")
|
19
src/msdl/package.json
Normal file
19
src/msdl/package.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"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%"
|
||||
}
|
||||
}
|
34
src/npm-data.ts
Normal file
34
src/npm-data.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* 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,
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
|
||||
import { getFetch, escapeFilename } from './utils'
|
||||
import { getFetch, escapeFilename, assertRes } from './utils'
|
||||
import { getMainCid } from './mscz'
|
||||
|
||||
export abstract class ScoreInfo {
|
||||
private readonly RADIX = 20;
|
||||
private readonly INDEX_RADIX = 32;
|
||||
|
||||
abstract id: number;
|
||||
abstract title: string;
|
||||
|
@ -24,6 +26,10 @@ export abstract class ScoreInfo {
|
|||
public getMsczCidUrl (mainCid: string): string {
|
||||
return `https://ipfs.infura.io:5001/api/v0/block/stat?arg=${this.getMsczIpfsRef(mainCid)}`
|
||||
}
|
||||
|
||||
public getScorepackRef (mainCid: string): string {
|
||||
return `/ipfs/${mainCid}/index/${(+this.id) % this.INDEX_RADIX}/${this.id}`
|
||||
}
|
||||
}
|
||||
|
||||
export class ScoreInfoObj extends ScoreInfo {
|
||||
|
@ -43,11 +49,18 @@ export class ScoreInfoInPage extends ScoreInfo {
|
|||
const el = this.document.querySelector("meta[property='og:title']") as HTMLMetaElement
|
||||
return el.content
|
||||
}
|
||||
|
||||
get baseUrl (): string {
|
||||
const el = this.document.querySelector("meta[property='og:image']") as HTMLMetaElement
|
||||
const m = el.content.match(/^(.+\/)score_/) as RegExpMatchArray
|
||||
return m[1]
|
||||
}
|
||||
}
|
||||
|
||||
export class ScoreInfoHtml extends ScoreInfo {
|
||||
private readonly ID_REG = /<meta property="al:ios:url" content="musescore:\/\/score\/(\d+)">/
|
||||
private readonly TITLE_REG = /<meta property="og:title" content="(.*)">/
|
||||
private readonly BASEURL_REG = /<meta property="og:image" content="(.+\/)score_.*">/
|
||||
|
||||
constructor (private html: string) { super() }
|
||||
|
||||
|
@ -63,6 +76,12 @@ export class ScoreInfoHtml extends ScoreInfo {
|
|||
return m[1]
|
||||
}
|
||||
|
||||
get baseUrl (): string {
|
||||
const m = this.html.match(this.BASEURL_REG)
|
||||
if (!m) return ''
|
||||
return m[1]
|
||||
}
|
||||
|
||||
static async request (url: string, _fetch = getFetch()): Promise<ScoreInfoHtml> {
|
||||
const r = await _fetch(url)
|
||||
if (!r.ok) return new ScoreInfoHtml('')
|
||||
|
@ -86,14 +105,50 @@ 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 {
|
||||
return this.document.querySelectorAll('.gXB83').length
|
||||
const sheet0Div = this.sheet0Img?.parentElement
|
||||
if (!sheet0Div) {
|
||||
throw new Error('no sheet images found')
|
||||
}
|
||||
return this.document.getElementsByClassName(sheet0Div.className).length
|
||||
}
|
||||
|
||||
get thumbnailUrl (): string {
|
||||
// url to the image of the first page
|
||||
const el = this.document.querySelector('link[as=image]') as HTMLLinkElement
|
||||
const url = el.href
|
||||
const el = this.document.querySelector<HTMLLinkElement>('link[as=image]')
|
||||
const url = (el?.href || this.sheet0Img?.src) as string
|
||||
return url.split('@')[0]
|
||||
}
|
||||
}
|
||||
|
||||
export const getActualId = async (scoreinfo: ScoreInfoInPage | ScoreInfoHtml, _fetch = getFetch()): Promise<number> => {
|
||||
if (scoreinfo.id <= 1000000000000) {
|
||||
// actual id already
|
||||
return scoreinfo.id
|
||||
}
|
||||
|
||||
const mainCid = await getMainCid(scoreinfo, _fetch)
|
||||
const ref = `${mainCid}/sid2id/${scoreinfo.id}`
|
||||
const url = `https://ipfs.infura.io:5001/api/v0/dag/get?arg=${ref}`
|
||||
|
||||
const r0 = await _fetch(url)
|
||||
if (r0.status !== 500) {
|
||||
assertRes(r0)
|
||||
}
|
||||
const res: { Message: string } | number = await r0.json()
|
||||
if (typeof res !== 'number') {
|
||||
// read further error msg
|
||||
throw new Error(res.Message)
|
||||
}
|
||||
|
||||
// assign the actual id back to scoreinfo
|
||||
Object.defineProperty(scoreinfo, 'id', {
|
||||
get () { return res },
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
44
src/utils.ts
44
src/utils.ts
|
@ -1,5 +1,8 @@
|
|||
|
||||
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, '_')
|
||||
|
@ -15,12 +18,22 @@ export const getIndexPath = (id: number): string => {
|
|||
return indexN.join('/')
|
||||
}
|
||||
|
||||
const NODE_FETCH_HEADERS = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
|
||||
'Accept-Language': 'en-US,en;q=0.8',
|
||||
}
|
||||
|
||||
export const getFetch = (): typeof fetch => {
|
||||
if (!isNodeJs) {
|
||||
return fetch
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return require('node-fetch')
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const nodeFetch = require('node-fetch')
|
||||
return (input: RequestInfo, init?: RequestInit) => {
|
||||
init = Object.assign({ headers: NODE_FETCH_HEADERS }, init)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return nodeFetch(input, init)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +63,13 @@ export const useTimeout = async <T> (promise: T | Promise<T>, ms: number): Promi
|
|||
export const getSandboxWindowAsync = async (targetEl: Element | undefined = undefined): Promise<Window> => {
|
||||
if (typeof document === 'undefined') return {} as any as Window
|
||||
|
||||
if (isGmAvailable('addElement')) {
|
||||
// create iframe using GM_addElement API
|
||||
const iframe = await _GM.addElement('iframe', {})
|
||||
iframe.style.display = 'none'
|
||||
return iframe.contentWindow as Window
|
||||
}
|
||||
|
||||
if (!targetEl) {
|
||||
return new Promise((resolve) => {
|
||||
// You need ads in your pages, right?
|
||||
|
@ -118,3 +138,23 @@ export const waitForDocumentLoaded = (): Promise<void> => {
|
|||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run script before the page is fully loaded
|
||||
*/
|
||||
export const waitForSheetLoaded = (): Promise<void> => {
|
||||
if (document.readyState !== 'complete') {
|
||||
return new Promise(resolve => {
|
||||
const observer = new MutationObserver(() => {
|
||||
const img = document.querySelector('img')
|
||||
if (img) {
|
||||
resolve()
|
||||
observer.disconnect()
|
||||
}
|
||||
})
|
||||
observer.observe(document, { childList: true, subtree: true })
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { PDFWorker } from '../dist/cache/worker'
|
|||
|
||||
const scriptUrlFromFunction = (fn: () => any): string => {
|
||||
const blob = new Blob(['(' + fn.toString() + ')()'], { type: 'application/javascript' })
|
||||
return URL.createObjectURL(blob)
|
||||
return window.URL.createObjectURL(blob)
|
||||
}
|
||||
|
||||
export class PDFWorkerHelper extends Worker {
|
||||
|
|
|
@ -6,7 +6,9 @@ import SVGtoPDF from 'svg-to-pdfkit'
|
|||
|
||||
type ImgType = 'svg' | 'png'
|
||||
|
||||
const getDataURL = (blob: Blob): Promise<string> => {
|
||||
type DataResultType = 'dataUrl' | 'text'
|
||||
|
||||
const readData = (blob: Blob, type: DataResultType): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onload = (): void => {
|
||||
|
@ -14,22 +16,22 @@ const getDataURL = (blob: Blob): Promise<string> => {
|
|||
resolve(result as string)
|
||||
}
|
||||
reader.onerror = reject
|
||||
reader.readAsDataURL(blob)
|
||||
if (type === 'dataUrl') {
|
||||
reader.readAsDataURL(blob)
|
||||
} else {
|
||||
reader.readAsText(blob)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const fetchDataURL = async (imgUrl: string): Promise<string> => {
|
||||
const r = await fetch(imgUrl)
|
||||
const blob = await r.blob()
|
||||
return getDataURL(blob)
|
||||
const fetchBlob = async (imgUrl: string): Promise<Blob> => {
|
||||
const r = await fetch(imgUrl, {
|
||||
cache: 'no-cache',
|
||||
})
|
||||
return r.blob()
|
||||
}
|
||||
|
||||
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> => {
|
||||
const generatePDF = async (imgBlobs: Blob[], imgType: ImgType, width: number, height: number): Promise<ArrayBuffer> => {
|
||||
// @ts-ignore
|
||||
const pdf = new (PDFDocument as typeof import('pdfkit'))({
|
||||
// compress: true,
|
||||
|
@ -40,7 +42,7 @@ const generatePDF = async (imgURLs: string[], imgType: ImgType, width: number, h
|
|||
})
|
||||
|
||||
if (imgType === 'png') {
|
||||
const imgDataUrlList: string[] = await Promise.all(imgURLs.map(fetchDataURL))
|
||||
const imgDataUrlList: string[] = await Promise.all(imgBlobs.map(b => readData(b, 'dataUrl')))
|
||||
|
||||
imgDataUrlList.forEach((data) => {
|
||||
pdf.addPage()
|
||||
|
@ -50,7 +52,7 @@ const generatePDF = async (imgURLs: string[], imgType: ImgType, width: number, h
|
|||
})
|
||||
})
|
||||
} else { // imgType == "svg"
|
||||
const svgList = await Promise.all(imgURLs.map(fetchText))
|
||||
const svgList = await Promise.all(imgBlobs.map(b => readData(b, 'text')))
|
||||
|
||||
svgList.forEach((svg) => {
|
||||
pdf.addPage()
|
||||
|
@ -70,14 +72,16 @@ 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(
|
||||
imgURLs,
|
||||
imgBlobs,
|
||||
imgType,
|
||||
width,
|
||||
height,
|
||||
|
|
52
src/wrapper.js
Normal file
52
src/wrapper.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* eslint-disable */
|
||||
const w = typeof unsafeWindow == 'object' ? unsafeWindow : window;
|
||||
|
||||
// GM APIs glue
|
||||
const _GM = typeof GM == 'object' ? GM : undefined;
|
||||
const gmId = '' + Math.random();
|
||||
w[gmId] = _GM;
|
||||
|
||||
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(
|
||||
'** Source Code **',
|
||||
() => _GM.openInTab(_GM.info.script.homepage, { active: true })
|
||||
)
|
||||
|
||||
_GM.registerMenuCommand(
|
||||
'** Discord **',
|
||||
() => _GM.openInTab("https://discord.gg/DKu7cUZ4XQ", { active: true })
|
||||
)
|
||||
}
|
||||
|
||||
function getRandL () {
|
||||
return String.fromCharCode(97 + Math.floor(Math.random() * 26))
|
||||
}
|
||||
|
||||
// script loader
|
||||
new Promise(resolve => {
|
||||
const id = '' + Math.random();
|
||||
w[id] = resolve;
|
||||
|
||||
const stackN = 9
|
||||
let loaderIntro = ''
|
||||
for (let i = 0; i < stackN; i++) {
|
||||
loaderIntro += `(function ${getRandL()}(){`
|
||||
}
|
||||
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}`)()
|
||||
}).then(d => {
|
||||
d.style.display = 'none';
|
||||
d.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
||||
d.once = false;
|
||||
d.setAttribute('onload', `if(this.once)return;this.once=true;this.remove();const GM=window['${gmId}'];delete window['${gmId}'];(` + function a () {
|
||||
/** script code here */
|
||||
|
||||
}.toString() + ')()')})
|
Loading…
Reference in a new issue