dl-librescore
Advanced tools
Comparing version 0.34.53 to 0.34.54
{ | ||
"name": "dl-librescore", | ||
"version": "0.34.53", | ||
"version": "0.34.54", | ||
"description": "Download sheet music", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.user.js", |
@@ -147,3 +147,4 @@ import { useTimeout, windowOpenAsync, console, attachShadow } from "./utils"; | ||
anchorDiv: HTMLDivElement, | ||
newParent: HTMLDivElement | ||
newParent: HTMLDivElement, | ||
id: number | ||
) { | ||
@@ -153,3 +154,3 @@ let { top } = anchorDiv.getBoundingClientRect(); | ||
if (top > 0) { | ||
newParent.style.top = `${top}px`; | ||
newParent.style.top = `${top - id * 48}px`; | ||
} else { | ||
@@ -160,3 +161,3 @@ newParent.style.top = "0px"; | ||
private _commit() { | ||
private _commit(id: number) { | ||
const btnParent = document.querySelector( | ||
@@ -185,9 +186,10 @@ "div.react-container" | ||
newParent.append(...this.list.map((e) => cloneBtn(e))); | ||
isNew | ||
newParent.id = id.toString(); | ||
!shadow.querySelector("div#id") | ||
? shadow.append(newParent) | ||
: shadow.replaceChild(newParent, shadow.querySelector("div")!); | ||
: shadow.replaceChild(newParent, shadow.querySelector("div#id")!); | ||
// default position | ||
newParent.style.top = `${ | ||
window.innerHeight - newParent.getBoundingClientRect().height | ||
window.innerHeight - newParent.getBoundingClientRect().height * id | ||
}px`; | ||
@@ -197,3 +199,3 @@ | ||
(anchorDiv: HTMLDivElement) => { | ||
const pos = () => this._positionBtns(anchorDiv, newParent); | ||
const pos = () => this._positionBtns(anchorDiv, newParent, id); | ||
pos(); | ||
@@ -217,3 +219,6 @@ if (isNew) { | ||
*/ | ||
async commit(mode: BtnListMode = BtnListMode.InPage): Promise<void> { | ||
async commit( | ||
mode: BtnListMode = BtnListMode.InPage, | ||
id: number | ||
): Promise<void> { | ||
switch (mode) { | ||
@@ -223,6 +228,6 @@ case BtnListMode.InPage: { | ||
try { | ||
el = this._commit(); | ||
el = this._commit(id); | ||
} catch { | ||
// fallback to BtnListMode.ExtWindow | ||
return this.commit(BtnListMode.ExtWindow); | ||
return this.commit(BtnListMode.ExtWindow, id); | ||
} | ||
@@ -234,3 +239,3 @@ const observer = new MutationObserver(() => { | ||
// performance issue? | ||
el = this._commit(); | ||
el = this._commit(id); | ||
} | ||
@@ -243,3 +248,3 @@ }); | ||
case BtnListMode.ExtWindow: { | ||
const div = this._commit(); | ||
const div = this._commit(id); | ||
const w = await windowOpenAsync( | ||
@@ -246,0 +251,0 @@ undefined, |
109
src/main.ts
@@ -46,40 +46,41 @@ import "./meta"; | ||
const observer = new MutationObserver(() => { | ||
const img = document.querySelector( | ||
"img[src^='https://musescore.com/static/musescore/scoredata/g/']" | ||
); | ||
if (!img) { | ||
if ( | ||
document.querySelector( | ||
"meta[property='musescore:author'][content='Official Scores']" | ||
) || | ||
document.querySelector( | ||
"meta[property='musescore:author'][content='Official Author']" | ||
) | ||
) { | ||
if (!isOfficial) { | ||
isOfficial = true; | ||
const btnList = new BtnList(); | ||
btnList.add({ | ||
name: i18next.t("official_button"), | ||
action: BtnAction.openUrl( | ||
"https://musescore.com/upgrade" | ||
), | ||
tooltip: i18next.t("official_tooltip"), | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
btnList.commit(BtnListMode.InPage); | ||
} | ||
observer.disconnect(); | ||
const scoreinfo = new ScoreInfoInPage(document); | ||
const btnList = new BtnList(); | ||
let indvPartBtn: HTMLButtonElement | null = null; | ||
const fallback = () => { | ||
// btns fallback to load from MSCZ file (`Individual Parts`) | ||
return indvPartBtn?.click(); | ||
}; | ||
if ( | ||
document.querySelector( | ||
"meta[property='musescore:author'][content='Official Scores']" | ||
) || | ||
document.querySelector( | ||
"meta[property='musescore:author'][content='Official Author']" | ||
) | ||
) { | ||
const btnOffList = new BtnList(); | ||
if (!isOfficial) { | ||
isOfficial = true; | ||
btnOffList.add({ | ||
name: | ||
i18next.t("download", { fileType: "PDF" }) + | ||
"\n(" + | ||
i18next.t("official_button") + | ||
")", | ||
action: BtnAction.openUrl( | ||
"https://musescore.com/upgrade" | ||
), | ||
tooltip: i18next.t("official_tooltip"), | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
btnOffList.commit(BtnListMode.InPage, 2); | ||
} | ||
} else { | ||
observer.disconnect(); | ||
const scoreinfo = new ScoreInfoInPage(document); | ||
const btnList = new BtnList(); | ||
let indvPartBtn: HTMLButtonElement | null = null; | ||
const fallback = () => { | ||
// btns fallback to load from MSCZ file (`Individual Parts`) | ||
return indvPartBtn?.click(); | ||
}; | ||
btnList.add({ | ||
name: i18next.t("download", { fileType: "PDF" }), | ||
name: i18next.t("download", { | ||
fileType: "PDF", | ||
}), | ||
action: BtnAction.process( | ||
@@ -96,23 +97,23 @@ () => | ||
}); | ||
} | ||
btnList.add({ | ||
name: i18next.t("download", { fileType: "MIDI" }), | ||
action: BtnAction.download( | ||
() => getFileUrl(scoreinfo.id, "midi"), | ||
fallback, | ||
30 * 1000 /* 30s */ | ||
), | ||
}); | ||
btnList.add({ | ||
name: i18next.t("download", { fileType: "MIDI" }), | ||
action: BtnAction.download( | ||
() => getFileUrl(scoreinfo.id, "midi"), | ||
fallback, | ||
30 * 1000 /* 30s */ | ||
), | ||
}); | ||
btnList.add({ | ||
name: i18next.t("download", { fileType: "MP3" }), | ||
action: BtnAction.download( | ||
() => getFileUrl(scoreinfo.id, "mp3"), | ||
fallback, | ||
30 * 1000 /* 30s */ | ||
), | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
btnList.commit(BtnListMode.InPage); | ||
} | ||
btnList.add({ | ||
name: i18next.t("download", { fileType: "MP3" }), | ||
action: BtnAction.download( | ||
() => getFileUrl(scoreinfo.id, "mp3"), | ||
fallback, | ||
30 * 1000 /* 30s */ | ||
), | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
btnList.commit(BtnListMode.InPage, 1); | ||
}); | ||
@@ -119,0 +120,0 @@ observer.observe(document, { childList: true, subtree: true }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Telemetry
Supply chain riskThis package contains telemetry which tracks how it is used.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Telemetry
Supply chain riskThis package contains telemetry which tracks how it is used.
Found 1 instance in 1 package
3615905
82095