v0.6.0 - recaptcha

This commit is contained in:
Xmader 2020-03-08 17:36:37 -04:00
parent 7a36eacee2
commit 2745ff9e53
4 changed files with 116 additions and 15 deletions

60
dist/main.js vendored
View File

@ -3,7 +3,7 @@
// @namespace https://www.xmader.com/
// @homepageURL https://github.com/Xmader/musescore-downloader/
// @supportURL https://github.com/Xmader/musescore-downloader/issues
// @version 0.5.3
// @version 0.6.0
// @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/*/*
@ -39,6 +39,42 @@
}
};
/**
* the site key for Google reCAPTCHA v3
*/
const SITE_KEY = "6Ldxtt8UAAAAALvcRqWTlVOVIB7MmEWwN-zw_9fM";
let gr;
/**
* load reCAPTCHA
*/
const load = () => {
// load script
const script = document.createElement("script");
script.src = `https://www.google.com/recaptcha/api.js?render=${SITE_KEY}`;
script.async = true;
document.body.appendChild(script);
// add css
const style = document.createElement("style");
style.innerHTML = ".grecaptcha-badge { display: none !important; }";
document.head.appendChild(style);
return new Promise((resolve) => {
script.onload = () => {
const grecaptcha = window["grecaptcha"];
grecaptcha.ready(() => resolve(grecaptcha));
};
});
};
const init = () => {
if (!gr) {
gr = load();
}
return gr;
};
const execute = () => __awaiter(void 0, void 0, void 0, function* () {
const captcha = yield init();
return captcha.execute(SITE_KEY, { action: "downloadmscz" });
});
var global$1 = (typeof global !== "undefined" ? global :
typeof self !== "undefined" ? self :
typeof window !== "undefined" ? window : {});
@ -28872,13 +28908,15 @@ Please pipe the document into a Node stream.\
if (!window.UGAPP || !window.UGAPP.store || !window.UGAPP.store.jmuse_settings) {
return;
}
// init recaptcha
init();
// @ts-ignore
const scorePlayer = window.UGAPP.store.jmuse_settings.score_player;
const { id } = scorePlayer.json;
const baseURL = scorePlayer.urls.image_path;
// const msczURL = `https://musescore.com/static/musescore/scoredata/score/${getIndexPath(id)}/${id}/score_${vid}_${scoreHexId}.mscz`
// https://github.com/Xmader/cloudflare-worker-musescore-mscz
const msczURL = `https://musescore.now.sh/api/mscz?id=${id}`;
const msczURL = `https://musescore.now.sh/api/mscz?id=${id}&token=`;
const mxlURL = baseURL + "score.mxl";
const { midi: midiURL, mp3: mp3URL } = scorePlayer.urls;
const btnsDiv = document.querySelector(".score-right .buttons-wrapper") || document.querySelectorAll("aside section > div")[4];
@ -28915,12 +28953,7 @@ Please pipe the document into a Node stream.\
const newDownloadBtns = Object.keys(downloadURLs).map((name) => {
const url = downloadURLs[name];
const { btn, textNode } = createBtn(name);
if (name !== "PDF") {
btn.onclick = () => {
window.open(url);
};
}
else {
if (name == "PDF") {
btn.onclick = () => {
const text = textNode.textContent;
const filename = getScoreFileName(scorePlayer);
@ -28930,6 +28963,17 @@ Please pipe the document into a Node stream.\
});
};
}
else if (name == "MSCZ") {
btn.onclick = () => __awaiter(void 0, void 0, void 0, function* () {
const token = yield execute();
window.open(url + token);
});
}
else {
btn.onclick = () => {
window.open(url);
};
}
return btn;
});
downloadBtn.replaceWith(...newDownloadBtns);

View File

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

View File

@ -2,6 +2,7 @@ import "./meta"
import { ScorePlayerData } from "./types"
import { waitForDocumentLoaded } from "./utils"
import * as recaptcha from "./recaptcha"
import { PDFWorkerHelper } from "./worker-helper"
import FileSaver from "file-saver/dist/FileSaver.js"
@ -63,6 +64,9 @@ const main = () => {
// @ts-ignore
if (!window.UGAPP || !window.UGAPP.store || !window.UGAPP.store.jmuse_settings) { return }
// init recaptcha
recaptcha.init()
// @ts-ignore
const scorePlayer: ScorePlayerData = window.UGAPP.store.jmuse_settings.score_player
@ -72,7 +76,7 @@ const main = () => {
// const msczURL = `https://musescore.com/static/musescore/scoredata/score/${getIndexPath(id)}/${id}/score_${vid}_${scoreHexId}.mscz`
// https://github.com/Xmader/cloudflare-worker-musescore-mscz
const msczURL = `https://musescore.now.sh/api/mscz?id=${id}`
const msczURL = `https://musescore.now.sh/api/mscz?id=${id}&token=`
const mxlURL = baseURL + "score.mxl"
const { midi: midiURL, mp3: mp3URL } = scorePlayer.urls
@ -119,11 +123,7 @@ const main = () => {
const url = downloadURLs[name]
const { btn, textNode } = createBtn(name)
if (name !== "PDF") {
btn.onclick = () => {
window.open(url)
}
} else {
if (name == "PDF") {
btn.onclick = () => {
const text = textNode.textContent
const filename = getScoreFileName(scorePlayer)
@ -134,6 +134,15 @@ const main = () => {
textNode.textContent = text
})
}
} else if (name == "MSCZ") {
btn.onclick = async () => {
const token = await recaptcha.execute()
window.open(url + token)
}
} else {
btn.onclick = () => {
window.open(url)
}
}
return btn

48
src/recaptcha.ts Normal file
View File

@ -0,0 +1,48 @@
/**
* the site key for Google reCAPTCHA v3
*/
const SITE_KEY = "6Ldxtt8UAAAAALvcRqWTlVOVIB7MmEWwN-zw_9fM"
type token = string;
interface GRecaptcha {
ready(cb: Function): void;
execute(siteKey: string, opts: { action: string }): Promise<token>;
}
let gr: GRecaptcha | Promise<GRecaptcha>
/**
* load reCAPTCHA
*/
const load = (): Promise<GRecaptcha> => {
// load script
const script = document.createElement("script")
script.src = `https://www.google.com/recaptcha/api.js?render=${SITE_KEY}`
script.async = true
document.body.appendChild(script)
// add css
const style = document.createElement("style")
style.innerHTML = ".grecaptcha-badge { display: none !important; }"
document.head.appendChild(style)
return new Promise((resolve) => {
script.onload = () => {
const grecaptcha: GRecaptcha = window["grecaptcha"]
grecaptcha.ready(() => resolve(grecaptcha))
}
})
}
export const init = () => {
if (!gr) {
gr = load()
}
return gr
}
export const execute = async (): Promise<token> => {
const captcha = await init()
return captcha.execute(SITE_KEY, { action: "downloadmscz" })
}