Skip to content

Commit

Permalink
v0.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Nov 9, 2020
1 parent 45645fe commit b53cc0d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 57 deletions.
155 changes: 100 additions & 55 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @supportURL https://github.com/Xmader/musescore-downloader/issues
// @updateURL https://msdl.librescore.org/install.user.js
// @downloadURL https://msdl.librescore.org/install.user.js
// @version 0.12.0
// @version 0.12.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/*/*
Expand Down Expand Up @@ -26399,8 +26399,52 @@ 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 @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const moduleLookup = (id, globalWebpackJson) => {
const pack = globalWebpackJson.find(x => x[1][id]);
return pack[1][id];
Expand Down Expand Up @@ -26439,50 +26483,49 @@ Please pipe the document into a Node stream.\
});
return t(moduleId);
};

/* 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}"
return _toString.call(_fn);
const webpackGlobalOverride = (() => {
const moduleOverrides = {};
function applyOverride(pack) {
Object.entries(moduleOverrides).forEach(([id, override]) => {
const mod = pack[1][id];
if (mod) {
pack[1][id] = function (n, r, t) {
// make exports configurable
t = Object.assign(t, {
d(exp, name, fn) {
return Object.defineProperty(exp, name, { enumerable: true, get: fn, configurable: true });
},
});
mod(n, r, t);
override(n, r, t);
};
}
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);
});
}
}
// hook `webpackJsonpmusescore.push` as soon as `webpackJsonpmusescore` is available
let jsonp;
Object.defineProperty(window, 'webpackJsonpmusescore', {
get() { return jsonp; },
set(v) {
jsonp = v;
hookNative(v, 'push', (_fn) => {
return function (pack) {
applyOverride(pack);
return _fn.call(this, pack);
};
});
},
});
// set overrides
return (moduleId, override) => {
moduleOverrides[moduleId] = override;
};
})();

/* eslint-disable no-extend-native */
const FILE_URL_MODULE_ID = 'iNJA';
const MAGIC_REG = /^\d+(img|mp3|midi)\d(.+)$/;
const AUTH_MODULE_ID = 'FNf8';
const MAGIC_ARG_INDEX = 3;
const getApiUrl = (id, type, index) => {
// proxy
return `https://musescore.now.sh/api/jmuse?id=${id}&type=${type}&index=${index}`;
Expand All @@ -26491,16 +26534,17 @@ Please pipe the document into a Node stream.\
* I know this is super hacky.
*/
let magic = new Promise((resolve) => {
hookNative(String.prototype, 'charCodeAt', (_fn, detach) => {
return function (i) {
const m = this.match(MAGIC_REG);
if (m) {
resolve(m[2]);
magic = m[2];
detach();
}
return _fn.call(this, i);
};
webpackGlobalOverride(AUTH_MODULE_ID, (_, r, t) => {
const fn = r.a;
t.d(r, 'a', () => {
return (...args) => {
if (magic instanceof Promise) {
magic = args[MAGIC_ARG_INDEX];
resolve(magic);
}
return fn(...args);
};
});
});
});
const getFileUrl = (type, index = 0) => __awaiter(void 0, void 0, void 0, function* () {
Expand All @@ -26517,7 +26561,7 @@ Please pipe the document into a Node stream.\
},
});
const fn = fileUrlModule.a;
if (typeof magic !== 'string') {
if (magic instanceof Promise) {
// force to retrieve the MAGIC
const el = document.querySelectorAll('.SD7H- > button')[3];
el.click();
Expand Down Expand Up @@ -26898,7 +26942,7 @@ Please pipe the document into a Node stream.\
});
btnList.add({
name: i18n('DOWNLOAD')('PDF'),
action: BtnAction.deprecate(BtnAction.process(downloadPDF)),
action: BtnAction.process(downloadPDF),
});
btnList.add({
name: i18n('DOWNLOAD')('MusicXML'),
Expand All @@ -26911,7 +26955,7 @@ Please pipe the document into a Node stream.\
});
btnList.add({
name: i18n('DOWNLOAD')('MIDI'),
action: BtnAction.deprecate(BtnAction.download(() => getFileUrl('midi'))),
action: BtnAction.download(() => getFileUrl('midi')),
});
btnList.add({
name: i18n('DOWNLOAD')('MP3'),
Expand Down Expand Up @@ -26962,14 +27006,15 @@ Please pipe the document into a Node stream.\
},
];
// part selection
const DEFAULT_PART = -1; // initially select "full score"
for (const excerpt of metadata.excerpts) {
const id = excerpt.id;
const partName = excerpt.title;
const e = w.document.createElement('input');
e.name = 'score-part';
e.type = 'radio';
e.alt = partName;
e.checked = id === 0; // initially select the first part
e.checked = id === DEFAULT_PART;
e.onclick = () => {
return score.setExcerptId(id); // set selected part
};
Expand All @@ -26978,7 +27023,7 @@ Please pipe the document into a Node stream.\
const br = w.document.createElement('br');
fieldset.append(e, label, br);
}
yield score.setExcerptId(0); // initially select the first part
yield score.setExcerptId(DEFAULT_PART);
// submit buttons
for (const d of downloads) {
const submitBtn = w.document.createElement('input');
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "musescore-downloader",
"version": "0.12.0",
"version": "0.12.1",
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱",
"main": "dist/main.js",
"repository": {
Expand Down

0 comments on commit b53cc0d

Please sign in to comment.