diff --git a/README.md b/README.md index ac4c1cb5..b96cbc0f 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Display all tracks and releases on which a recording appears from the release pa ## MB: QoL: Paste multiple external links at once -Paste multiple external links at once into the external link editor. Input is split on whitespace (newlines, tabs, spaces, etc.) and fed into the link editor separately. +Paste multiple external links at once into the external link editor. Input is split on whitespace (newlines, tabs, spaces, etc.) and fed into the link editor separately. Additionally adds handy bulk Copy buttons to a-tisket release and artist URLs. [![Install](https://img.shields.io/badge/dynamic/json?label=install&query=%24.version&url=https%3A%2F%2Fraw.github.com%2FROpdebee%2Fmb-userscripts%2Fdist%2Fmb_multi_external_links.metadata.json&logo=tampermonkey&style=for-the-badge&color=informational)](https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_multi_external_links.user.js) [![Source](https://img.shields.io/badge/source-grey?style=for-the-badge&logo=github)](src/mb_multi_external_links) diff --git a/src/mb_multi_external_links/index.ts b/src/mb_multi_external_links/index.tsx similarity index 80% rename from src/mb_multi_external_links/index.ts rename to src/mb_multi_external_links/index.tsx index b3270960..3501ccd3 100644 --- a/src/mb_multi_external_links/index.ts +++ b/src/mb_multi_external_links/index.tsx @@ -110,7 +110,7 @@ function insertCheckboxElements(editor: ExternalLinks, checkboxElmt: HTMLInputEl checkboxElmt.style.marginLeft = `${marginLeft}px`; } -async function run(windowInstance: Window): Promise { +async function initSplitter(windowInstance: Window): Promise { // This element should be present even before React is initialized. Checking // for its existence enables us to skip attempting to find the link input on // edit pages that don't have external links, without having to exclude @@ -136,7 +136,7 @@ function onIframeAdded(iframe: HTMLIFrameElement): void { LOGGER.debug(`Initialising on iframe ${iframe.src}`); onAddEntityDialogLoaded(iframe, () => { - logFailure(run(iframe.contentWindow!)); + logFailure(initSplitter(iframe.contentWindow!)); }); } @@ -162,6 +162,46 @@ function listenForIframes(): void { }); } -logFailure(run(window)); +function attachLinkSplitter(): void { + logFailure(initSplitter(window)); + listenForIframes(); +} + +const insertAtisketCopyButtons = ((): (() => void) => { + function createButton(textGetter: () => string): HTMLButtonElement { + const btn = as HTMLButtonElement; + return btn; + } + + function getArtistLinks(): string { + const urls = qsa('.prop.artists a:not(.mb)').map((a) => a.href); + return urls.join('\n'); + } -listenForIframes(); + function getReleaseLinks(): string { + const urls = qsa('section#mba-links a').map((a) => a.href); + return urls.join('\n'); + } + + return (): void => { + qsMaybe('.prop.artists div')?.prepend(createButton(getArtistLinks)); + qsMaybe('section#mba-links > h2')?.append(createButton(getReleaseLinks)); + }; +})(); + + +if (document.location.hostname === 'musicbrainz.org' || document.location.hostname.endsWith('.musicbrainz.org')) { + attachLinkSplitter(); +} else if (document.location.hostname === 'atisket.pulsewidth.org.uk' || document.location.hostname === 'etc.marlonob.info') { + insertAtisketCopyButtons(); +} diff --git a/src/mb_multi_external_links/meta.ts b/src/mb_multi_external_links/meta.ts index 933dbc42..b4aa9888 100644 --- a/src/mb_multi_external_links/meta.ts +++ b/src/mb_multi_external_links/meta.ts @@ -1,20 +1,26 @@ import type { UserscriptMetadata } from '@lib/util/metadata'; import { transformMBMatchURL } from '@lib/util/metadata'; +const mbMatchedUrls = [ + '*/edit', + '*/edit?*', + 'release/*/edit-relationships*', + '*/add', + '*/add?*', + '*/create', + '*/create?*', +].map((path) => transformMBMatchURL(path)); + const metadata: UserscriptMetadata = { name: 'MB: QoL: Paste multiple external links at once', description: 'Enables pasting multiple links, separated by whitespace, into the external link editor.', 'run-at': 'document-end', match: [ - '*/edit', - '*/edit?*', - 'release/*/edit-relationships*', - '*/add', - '*/add?*', - '*/create', - '*/create?*', - ].map((path) => transformMBMatchURL(path)), - blurb: 'Paste multiple external links at once into the external link editor. Input is split on whitespace (newlines, tabs, spaces, etc.) and fed into the link editor separately.', + ...mbMatchedUrls, + '*://atisket.pulsewidth.org.uk/*', + '*://etc.marlonob.info/atisket/*', + ], + blurb: 'Paste multiple external links at once into the external link editor. Input is split on whitespace (newlines, tabs, spaces, etc.) and fed into the link editor separately. Additionally adds handy bulk Copy buttons to a-tisket release and artist URLs.', }; export default metadata;