mirror of
https://notabug.org/SuperSaltyGamer/ame
synced 2026-01-15 16:22:56 -03:00
[musicbrainz] Fix obtaining release title for pages with recent edits
This commit is contained in:
4
dist/musicbrainz.user.js
vendored
4
dist/musicbrainz.user.js
vendored
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @namespace ame-musicbrainz
|
||||
// @name Ame (MusicBrainz)
|
||||
// @version 1.4.0
|
||||
// @version 1.4.1
|
||||
// @author SuperSaltyGamer
|
||||
// @run-at document-end
|
||||
// @match https://musicbrainz.org/*
|
||||
@@ -12,7 +12,7 @@
|
||||
// @updateURL https://notabug.org/SuperSaltyGamer/ame/raw/main/dist/musicbrainz.user.js
|
||||
// ==/UserScript==
|
||||
|
||||
(function(me){typeof define=="function"&&define.amd?define(me):me()})(function(){"use strict";function me(){return location.pathname.split("/")[2]}function ze(){var V;let P=(V=document.querySelector(".barcode"))==null?void 0:V.innerText;return P==="[none]"&&(P=void 0),{id:me(),title:document.querySelector("h1 > a").innerText,artist:document.querySelector(".subheader bdi").innerText,catalogs:Array.from(document.querySelectorAll(".catalog-number")).map(A=>A.innerText),barcode:P}}const je=/(\d+) +\| +([0-9:.]+) +\| +([0-9:.]+) +\| +(\d+) +\| +(\d+)/g,we=document.querySelector("form[action='/search']"),Fe=document.querySelector("form[action='/search'] button"),Se=document.querySelector("#headerid-query");Se.focus(),Se.placeholder="Enhanced search",we.addEventListener("dragover",P=>{P.preventDefault();const V=P.dataTransfer;V&&(V.dropEffect="link")}),we.addEventListener("drop",async P=>{P.preventDefault();const V=P.dataTransfer;if(!V)return;const A=V.files.item(0);A!=null&&A.name.match(/\.log$/)&&(Se.value=await A.text(),Fe.click())}),we.addEventListener("submit",P=>{const A=new FormData(we).get("query").trim(),z=He(A);if(z!=="other")switch(P.preventDefault(),z){case"catalog":location.href=`https://musicbrainz.org/search?type=release&method=advanced&query=catno:${encodeURIComponent(We(A))}`;break;case"barcode":location.href=`https://musicbrainz.org/search?type=release&method=advanced&query=barcode:${encodeURIComponent(A)}`;break;case"isrc":location.href=`https://musicbrainz.org/search?type=recording&method=advanced&query=isrc:${encodeURIComponent(A)}`;break;case"log-eac":case"log-xld":let _=`?toc=${Ze(A)}`;location.pathname.startsWith("/release/")&&(_+=`&filter-release.query=${me()}`),location.href=`https://musicbrainz.org/cdtoc/attach${_}`;break}});function He(P){return P.match(/^(\d{8}|\d{12}|\d{13}|\d{14})$/i)?"barcode":P.match(/^[a-z]{5}[0-9]{7}$/i)?"isrc":P===P.toUpperCase()&&P.match(/\d/i)&&P.match(/[a-z]/i)&&P.match(/[ ~-]/i)?"catalog":P.includes("TOC of the extracted CD")&&P.includes("EAC extraction logfile")?"log-eac":P.includes("TOC of the extracted CD")&&P.includes("XLD extraction logfile")?"log-xld":"other"}function We(P){return/^(.+)([1-9][0-9]*)~([0-9]+)$/.test(P)?P.split("~")[0]:P}function Ze(P){const V=[];let A=0;for(const z of P.matchAll(je)){const _=Number(z[1]);if(A>_)break;A=_,V.push({no:_,start:z[2],length:z[3],startSector:Number(z[4]),endSector:Number(z[5])})}return[1,V.length,V[V.length-1].endSector+150+1].concat(V.map(z=>z.startSector+150)).join("%20")}const Pe=new Map;function De(P,V){return new Promise((A,z)=>{const _=Pe.get(P);if(_){A(_.clone());return}GM.xmlHttpRequest({url:P,method:(V==null?void 0:V.method)??"GET",headers:Object.fromEntries(new Headers(V==null?void 0:V.headers)),responseType:"blob",onload(a){if((a.status<200||a.status>299)&&a.status!==404){z(new Error(`Fetching "${P}" responded with an erroneous status code.`));return}const c=a.responseHeaders.split(`\r
|
||||
(function(me){typeof define=="function"&&define.amd?define(me):me()})(function(){"use strict";function me(){return location.pathname.split("/")[2]}function ze(){var V;let P=(V=document.querySelector(".barcode"))==null?void 0:V.innerText;return P==="[none]"&&(P=void 0),{id:me(),title:document.querySelector("h1 a").innerText,artist:document.querySelector(".subheader bdi").innerText,catalogs:Array.from(document.querySelectorAll(".catalog-number")).map(A=>A.innerText),barcode:P}}const je=/(\d+) +\| +([0-9:.]+) +\| +([0-9:.]+) +\| +(\d+) +\| +(\d+)/g,we=document.querySelector("form[action='/search']"),Fe=document.querySelector("form[action='/search'] button"),Se=document.querySelector("#headerid-query");Se.focus(),Se.placeholder="Enhanced search",we.addEventListener("dragover",P=>{P.preventDefault();const V=P.dataTransfer;V&&(V.dropEffect="link")}),we.addEventListener("drop",async P=>{P.preventDefault();const V=P.dataTransfer;if(!V)return;const A=V.files.item(0);A!=null&&A.name.match(/\.log$/)&&(Se.value=await A.text(),Fe.click())}),we.addEventListener("submit",P=>{const A=new FormData(we).get("query").trim(),z=He(A);if(z!=="other")switch(P.preventDefault(),z){case"catalog":location.href=`https://musicbrainz.org/search?type=release&method=advanced&query=catno:${encodeURIComponent(We(A))}`;break;case"barcode":location.href=`https://musicbrainz.org/search?type=release&method=advanced&query=barcode:${encodeURIComponent(A)}`;break;case"isrc":location.href=`https://musicbrainz.org/search?type=recording&method=advanced&query=isrc:${encodeURIComponent(A)}`;break;case"log-eac":case"log-xld":let _=`?toc=${Ze(A)}`;location.pathname.startsWith("/release/")&&(_+=`&filter-release.query=${me()}`),location.href=`https://musicbrainz.org/cdtoc/attach${_}`;break}});function He(P){return P.match(/^(\d{8}|\d{12}|\d{13}|\d{14})$/i)?"barcode":P.match(/^[a-z]{5}[0-9]{7}$/i)?"isrc":P===P.toUpperCase()&&P.match(/\d/i)&&P.match(/[a-z]/i)&&P.match(/[ ~-]/i)?"catalog":P.includes("TOC of the extracted CD")&&P.includes("EAC extraction logfile")?"log-eac":P.includes("TOC of the extracted CD")&&P.includes("XLD extraction logfile")?"log-xld":"other"}function We(P){return/^(.+)([1-9][0-9]*)~([0-9]+)$/.test(P)?P.split("~")[0]:P}function Ze(P){const V=[];let A=0;for(const z of P.matchAll(je)){const _=Number(z[1]);if(A>_)break;A=_,V.push({no:_,start:z[2],length:z[3],startSector:Number(z[4]),endSector:Number(z[5])})}return[1,V.length,V[V.length-1].endSector+150+1].concat(V.map(z=>z.startSector+150)).join("%20")}const Pe=new Map;function De(P,V){return new Promise((A,z)=>{const _=Pe.get(P);if(_){A(_.clone());return}GM.xmlHttpRequest({url:P,method:(V==null?void 0:V.method)??"GET",headers:Object.fromEntries(new Headers(V==null?void 0:V.headers)),responseType:"blob",onload(a){if((a.status<200||a.status>299)&&a.status!==404){z(new Error(`Fetching "${P}" responded with an erroneous status code.`));return}const c=a.responseHeaders.split(`\r
|
||||
`).slice(0,-1).map(u=>u.split(": ")),t=new Response(a.response,{headers:Object.fromEntries(c),status:a.status,statusText:a.statusText});Object.defineProperty(t,"url",{value:P}),Pe.set(P,t.clone()),A(t)},onerror(){z(new Error("Network request errored."))},ontimeout(){z(new Error("Network request timed out."))}})})}function ge(P){const V=document.createElement("template");return V.innerHTML=P,V.content.firstElementChild}const pe=(unsafeWindow==null?void 0:unsafeWindow.wrappedJSObject)??unsafeWindow,Ye=typeof cloneInto=="function"?cloneInto:P=>P,Ve=typeof exportFunction=="function"?exportFunction:P=>P;function Ge(P){return Ye(P,pe,{cloneFunctions:!0,wrapReflectors:!0})}function qe(P){return Ve(P,pe)}function Xe(P,V){return V??(V=pe),function(...A){return P.call(V,...Ge(A))}}const Ce={},Ke=Xe(pe.history.pushState,pe.history);pe.history.pushState=qe(Qe);function Qe(P,V,A){Ke(P,V,A),Te()}addEventListener("popstate",()=>{Te()});function Te(){for(const P of Object.values(Ce)){const V=P.pattern.test(location.pathname)?P.onCallbacks:P.offCallbacks;for(const A of V)A()}}function Je(P){const V=new RegExp(`^/${P.replaceAll("/","\\/")}$`);let A=Ce[P];return A||(A={pattern:V,onCallbacks:[],offCallbacks:[]},Ce[P]=A,A)}function Ee(P,V){const A=Je(P),z=A.pattern.test(location.pathname);A.onCallbacks.push(V),z&&V()}const $e="release/[0-9a-f-]+",er="release/[0-9a-f-]+/cover-art",rr="release/[0-9a-f-]+/add-cover-art";function tr(P){Ee($e,P)}function nr(P){Ee(er,P)}function ir(P){Ee(rr,P)}ir(()=>{const P=document.querySelector(".fileinput-button.buttons");if(!P)return;const V=ge('<button type="button">Pick from MH Covers...</button>');V.onclick=ar,P.appendChild(V)});function ar(P){P.preventDefault();const V=ze();if(!V)return;const A=new URLSearchParams;A.set("artist",V.artist),A.set("album",V.title),A.set("remote.port","browser"),A.set("remote.agent","Ame - MusicBrainz"),A.set("remote.text","Pick cover for MusicBrainz release.");const z=open(`https://covers.musichoarders.xyz?${A}`,"_blank");z&&(addEventListener("beforeunload",()=>{z.close()}),addEventListener("message",async _=>{try{if(_.source!==z)return;const a=JSON.parse(_.data);switch(a.action){case"primary":case"secondary":z==null||z.close(),await sr(a);break}}catch{}},!1))}async function sr(P){var u;const A=await(await De(P.bigCoverUrl)).blob(),z=new DataTransfer;Object.defineProperty(z,"files",{value:[A]});const _=new DragEvent("drop",{dataTransfer:z});(u=document.querySelector("#drop-zone"))==null||u.dispatchEvent(_);const a=document.querySelector("#add-cover-art tr:last-of-type");if(!a)return;const c=a.querySelector('input[type="checkbox"]');c&&c.click();const t=document.body.querySelector(".edit-note");if(t){let g="Seeded with Ame through https://covers.musichoarders.xyz";P.releaseInfo.url&&(g+=` for ${P.releaseInfo.url}`),g+=` from ${P.bigCoverUrl}`,t.value=g}}var Oe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function or(P){return P&&P.__esModule&&Object.prototype.hasOwnProperty.call(P,"default")?P.default:P}function ye(P){throw new Error('Could not dynamically require "'+P+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Be={exports:{}};/*!
|
||||
|
||||
JSZip v3.9.1 - A JavaScript class for generating and reading zip files
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @namespace ame-musicbrainz
|
||||
// @name Ame (MusicBrainz)
|
||||
// @version 1.4.0
|
||||
// @version 1.4.1
|
||||
// @author SuperSaltyGamer
|
||||
// @run-at document-end
|
||||
// @match https://musicbrainz.org/*
|
||||
|
||||
@@ -16,7 +16,7 @@ export function getPageReleaseInfo(): ReleaseInfo | null {
|
||||
|
||||
return {
|
||||
id: getPageReleaseId(),
|
||||
title: document.querySelector<HTMLElement>("h1 > a")!.innerText,
|
||||
title: document.querySelector<HTMLElement>("h1 a")!.innerText,
|
||||
artist: document.querySelector<HTMLElement>(".subheader bdi")!.innerText,
|
||||
catalogs: Array.from(document.querySelectorAll<HTMLElement>(".catalog-number")).map(el => el.innerText),
|
||||
barcode
|
||||
|
||||
Reference in New Issue
Block a user