mirror of
https://notabug.org/SuperSaltyGamer/ame
synced 2026-01-15 16:22:56 -03:00
[musicbrainz-works] Fixes
This commit is contained in:
8
dist/musicbrainz-works.user.js
vendored
8
dist/musicbrainz-works.user.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @namespace ame-musicbrainz-works
|
||||
// @name Ame (MusicBrainz - Works)
|
||||
// @version 0.1.1
|
||||
// @version 0.1.2
|
||||
// @author SuperSaltyGamer
|
||||
// @run-at document-end
|
||||
// @match https://musicbrainz.org/*
|
||||
@@ -27,7 +27,7 @@ const queryParams = new URLSearchParams(location.search);
|
||||
|
||||
window.addEventListener("focus", async () => {
|
||||
await sleep(100);
|
||||
if (!document.hasFocus()) return;
|
||||
if (!window.document.hasFocus() && !window.top?.document.hasFocus()) return;
|
||||
|
||||
if (location.host.endsWith("musicbrainz.org")) {
|
||||
if (location.pathname.startsWith("/release/") && location.pathname.endsWith("/edit-relationships")) {
|
||||
|
||||
@@ -8,26 +8,26 @@ export async function onIswcNetPages() {
|
||||
observeQuerySelector("a[class^='LandingPage_languageButton__']", () => {
|
||||
location.href = "/search";
|
||||
});
|
||||
|
||||
// Skip to captcha on error.
|
||||
observeQuerySelector("div[class^='Search_resultsContainer__'] div[class^='AlertMessage_text__']", () => {
|
||||
location.href = "/";
|
||||
});
|
||||
}
|
||||
|
||||
export function onIswcNetSearchPage() {
|
||||
return updateBusValue(MessageType.Work, async (work) => {
|
||||
export async function onIswcNetSearchPage() {
|
||||
let captcha = false;
|
||||
|
||||
await updateBusValue(MessageType.Work, async (work) => {
|
||||
if (!work.iswc) return;
|
||||
|
||||
const iswcEl = document.querySelector<HTMLInputElement>("#iswc")!;
|
||||
const searchEl = document.querySelector<HTMLButtonElement>("button[type='submit']")!;
|
||||
|
||||
if (iswcEl.value === work.iswc) return;
|
||||
|
||||
setReactInputValue(iswcEl, work.iswc);
|
||||
searchEl?.click();
|
||||
|
||||
await waitQuerySelector("[class^='Search_sectionTitle__']");
|
||||
const success = await Promise.any([
|
||||
waitQuerySelector("div[class^='Search_resultsContainer__'] div[class^='AlertMessage_text__']").then(() => false),
|
||||
waitQuerySelector("[class^='Search_sectionTitle__']").then((el) => Boolean(el))
|
||||
]);
|
||||
|
||||
if (success) return;
|
||||
|
||||
const moreEl = document.querySelector<HTMLButtonElement>("[id='View More']")!;
|
||||
moreEl.click();
|
||||
@@ -41,5 +41,10 @@ export function onIswcNetSearchPage() {
|
||||
copyEl.click();
|
||||
work.workCodes = true;
|
||||
}
|
||||
|
||||
work.sources.push(location.href);
|
||||
});
|
||||
|
||||
// Skip to captcha on error.
|
||||
if (captcha) location.href = "/";
|
||||
}
|
||||
|
||||
@@ -51,5 +51,6 @@ export function onMincWorkPage() {
|
||||
work.lyricists = Array.from(lyricists);
|
||||
work.composers = Array.from(composers);
|
||||
work.publishers = Array.from(publishers);
|
||||
work.sources.push(location.href);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,6 +30,16 @@ export function onMusicBrainzEditRelationshipsPage() {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
observeQuerySelector<HTMLIFrameElement>("iframe[src^='/dialog']", (el) => {
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
el.style.height = `${entries[0].contentRect.height + 100}px`;
|
||||
});
|
||||
|
||||
el.addEventListener("load", () => {
|
||||
observer.observe(el.contentDocument!.body);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function onMusicBrainzEditWorkPage() {
|
||||
@@ -38,7 +48,7 @@ export async function onMusicBrainzEditWorkPage() {
|
||||
const noteEl = markChange(document.querySelector<HTMLTextAreaElement>("#id-edit-work\\.edit_note")!);
|
||||
|
||||
const work = await getBusValue(MessageType.Work);
|
||||
if (!work) {
|
||||
if (!work?.sources.length) {
|
||||
if (!done) {
|
||||
await setBusValue(MessageType.Work, {
|
||||
name: nameEl.value || null,
|
||||
@@ -56,13 +66,14 @@ export async function onMusicBrainzEditWorkPage() {
|
||||
|
||||
done = true;
|
||||
|
||||
if (work.iswc) setReactInputValue(iswcEl, work.iswc);
|
||||
if (work.sources.length) noteEl.value = `Filled out with Ame (MusicBrainz - Works):\n${work.sources.join("\n")}\n`;
|
||||
|
||||
if (work.workCodes) {
|
||||
const pasteWorkCodesEl = document.querySelector<HTMLButtonElement>("#ROpdebee_MB_Paste_Work");
|
||||
pasteWorkCodesEl?.click();
|
||||
}
|
||||
|
||||
if (work.iswc) iswcEl.value = work.iswc;
|
||||
if (work.sources.length) noteEl.value = `Filled out with of Ame (MusicBrainz - Works):\n${work.sources.join("\n")}\n`;
|
||||
for (const composer of work.composers) await addRelationship("artist", "composed / composer", composer);
|
||||
for (const lyricist of work.lyricists) await addRelationship("artist", "lyrics / lyricist", lyricist);
|
||||
for (const publisher of work.publishers) await addRelationship("label", "published / publisher", publisher);
|
||||
|
||||
Reference in New Issue
Block a user