diff --git a/dist/musicbrainz-works.user.js b/dist/musicbrainz-works.user.js index 2760522..1748a68 100644 --- a/dist/musicbrainz-works.user.js +++ b/dist/musicbrainz-works.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @namespace ame-musicbrainz-works // @name Ame (MusicBrainz - Works) -// @version 0.3.1 +// @version 0.3.2 // @author SuperSaltyGamer // @run-at document-end // @match https://musicbrainz.org/* @@ -17,8 +17,8 @@ // @updateURL https://notabug.org/SuperSaltyGamer/ame/raw/main/dist/musicbrainz-works.user.js // ==/UserScript== -(function(l){typeof define=="function"&&define.amd?define(l):l()})(function(){"use strict";function l(e){return new Promise(t=>{setTimeout(t,e)})}function N(e){const t=document.createElement("template");return t.innerHTML=e,t.content.firstElementChild}function S(e,t){return new Promise(r=>{const n=t==null?void 0:t.waitSelector,o=(t==null?void 0:t.timeout)??3e3;if(o!==0){const c=document.querySelector(e);if(c){r(c);return}}const a=setTimeout(()=>{o!==0&&(i.disconnect(),r(null))},o),i=new MutationObserver(c=>{for(const u of c)for(const s of Array.from(u.addedNodes))if(s instanceof Element&&s.matches(n??e)){o!==0&&(i.disconnect(),clearTimeout(a)),r(n?document.querySelector(e):s);return}});i.observe(document.body,{childList:!0,subtree:!0})})}function k(e,t){new MutationObserver(async n=>{for(const o of n)for(const a of o.addedNodes){if(!(a instanceof HTMLElement))continue;const i=a.matches(e)?a:a.querySelector(e);i&&await t(i)}}).observe(document.body,{childList:!0,subtree:!0})}function d(e,t){return document.evaluate(t,e,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function g(e,t){const r=document.evaluate(t,e,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);return Array.from({length:r.snapshotLength},(n,o)=>r.snapshotItem(o))}var f=(e=>(e.Work="work",e))(f||{});function v(e,t){if(document.visibilityState==="visible")return t==null?GM.deleteValue(e):(console.info("setBusValue",e,t),GM.setValue(e,{value:t,timestamp:new Date().getTime()+60*1e3}))}async function M(e){if(document.visibilityState!=="visible")return null;const t=await GM.getValue(e);return!t||(await v(e,null),t.timestamp>﹥≯¬¬||~~−⁻₋⁒∓-∕⁄∖-∛؆∜؇∝-∭⨌∮-∼≁∽-≀≂-≅≇≆≈-≍≭≎-≟≡-≤≰≥≱≦-≬≲≴≳≵≶≸≷≹≺⊀≻⊁≼⋠≽⋡≾≿⊂⊄⊃⊅⊆⊈⊇⊉-⊑⋢⊒⋣⊓-⊢⊬⊣-⊨⊭⊩⊮⊪⊫⊯-⊲⋪⊳⋫⊴⋬⊵⋭⊶-⊼⅋⊽-⋟⋤-⋩⋮-⋿⌠⌡⍼⎛-⎳⏜-⏡▷◁◸-◺◿⟀-⟄⟇-⟥⟰-⟿⤀-⤳⤶-⦂⦙-⧗⧜-⧻⧾-⨋⨍-⩳⩷-⫛⫝⫝̸⫞-⫿⬰-⭄⭇-⭌♯↔↮⤴⤵‼⁉〰〽◼◻◾◽]`.split("")),x={0:1,"0":1,1:2,"1":2,2:3,"2":3,3:4,"3":4,4:5,"4":5,5:6,"5":6,6:7,"6":7,7:8,"7":8,8:9,"8":9,9:10,"9":10,a:11,a:11,ä:11,b:12,b:12,c:13,c:13,d:14,d:14,e:15,e:15,f:16,f:16,g:17,g:17,h:18,h:18,i:19,i:19,j:20,j:20,k:21,k:21,l:22,l:22,m:23,m:23,n:24,n:24,o:25,o:25,ö:25,õ:25,p:26,p:26,q:27,q:27,r:28,r:28,s:29,s:29,$:29,t:30,t:30,u:31,u:31,ü:31,v:32,v:32,w:33,w:33,x:34,x:34,y:35,y:35,z:36,z:36},D=Object.entries(x).reduce((e,[t,r])=>(r in e||(e[r]=[]),e[r].push(t),e),{});function I(e){const t=x[e];return t?D[t]??[e]:[e]}function _(e){return e=e.replace(/[\s・]+/g,"").split("").map(t=>j.has(t)?"":`[${I(t).join("")}]`).join("[\\s\\p{Pc}\\p{Pd}\\p{Pe}\\p{Pf}\\p{Pi}\\p{Po}\\p{Ps}\\p{Sm}]{0,4}"),new RegExp(`(?)${e}`,"gui")}function P(e,t){e.innerHTML=e.innerHTML.replaceAll(t,r=>{const n=document.createElement("span");n.classList.add("ame__mark--inner"),n.innerText=r;const o=document.createElement("span");return o.classList.add("ame__mark"),o.appendChild(n),o.outerHTML})}function T(e){const t=e.value;return e.addEventListener("input",()=>{e.value!==t&&(e.style.backgroundColor="yellow")}),e}function y(e,t){if(e instanceof HTMLInputElement){Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value").set.call(e,t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("focusout",{bubbles:!0}));return}if(e instanceof HTMLSelectElement){Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype,"value").set.call(e,t),e.dispatchEvent(new Event("change",{bubbles:!0})),e.dispatchEvent(new Event("focusout",{bubbles:!0}));return}}function q(e,t){const r=p.createOscillator(),n=p.createGain();r.connect(n),n.connect(p.destination),n.gain.value=.25,r.frequency.value=t,r.start(p.currentTime),r.stop(p.currentTime+e/1e3)}async function z(){k("a[class^='LandingPage_languageButton__']",()=>{location.href="/search"})}async function G(){let e=!1;await w(f.Work,async t=>{if(!t.iswc)return;const r=document.querySelector("#iswc"),n=document.querySelector("button[type='submit']");if(y(r,t.iswc),n==null||n.click(),e=await Promise.any([S("div[class^='Search_resultsContainer__'] div[class^='AlertMessage_text__']").then(()=>!0),S("[class^='Search_sectionTitle__']").then(i=>!i)]),e)return;const o=document.querySelector("[id='View More']");o.click(),await l(100);const a=d(document,"//button[.='Copy work codes']");a?(a.click(),t.codes.external=!0):o.after(N('
Install Bulk copy-paste work codes for better integration.
')),t.sources.push(location.href),t.sources=Array.from(new Set(t.sources)),q(50,1e3)}),e&&(location.href="/")}function $(){const e=document.querySelector(".logo > a");e&&(e.href=`${location.origin}/search`)}function U(){return w(f.Work,async e=>{if(!e.name)return;const t=document.querySelector("#kyokunm"),r=document.querySelector("#search-by-track-and-artist");t.value=e.name,r.click()})}function F(){for(const e of document.querySelectorAll(".saku-detail-link")){const t=document.createElement("a");t.target="_blank",t.href=`/saku/detail/?${e.getAttribute("data-href")}`,t.innerHTML=e.innerHTML,e.replaceWith(t)}return w(f.Work,async e=>{for(const n of e.context.tokens){const o=_(n);for(const a of document.querySelectorAll("#track-list tr td:nth-child(3), #track-list tr td:nth-child(4)"))P(a,o)}if(e.name)for(const n of document.querySelectorAll("#track-list tr td:nth-child(2)"))P(n,_(e.name));const t=document.querySelector("#kyokunm"),r=document.querySelector("#search-by-track-and-artist");!e.name||t.value===e.name||(t.value=e.name,r.click())})}function Q(){return w(f.Work,async e=>{var s,m,h,R,C,V,H,B;const t=((m=(s=d(document,"//h2/text()"))==null?void 0:s.nodeValue)==null?void 0:m.trim())||null,r=((R=(h=d(document,"//h3/text()[.!='-']"))==null?void 0:h.nodeValue)==null?void 0:R.replaceAll(" ",""))||null,n=((V=(C=d(document,"//a[@href='#jasrac']/following-sibling::*/span[2][.!='']"))==null?void 0:C.innerText)==null?void 0:V.trim())||null,o=((B=(H=d(document,"//a[@href='#nextone']/following-sibling::*/span[2][.!='']"))==null?void 0:H.innerText)==null?void 0:B.trim())||null,a=g(document,"//td[contains(., '作詞')]/parent::tr/*[2]").map(b).filter(Boolean),i=g(document,"//td[contains(., '作曲')]/parent::tr/*[2]").map(b).filter(Boolean),c=g(document,"//td[contains(., '編曲')]/parent::tr/*[2]").map(b).filter(Boolean),u=g(document,"//td[contains(., '出版者')]/parent::tr/*[2]").map(b).filter(Boolean);r&&(e.iswc=r),n&&(e.codes.jasrac=n),o&&(e.codes.nextone=o),e.lyricists=a,e.composers=i,e.arrangers=c,e.publishers=u,e.sources.push(location.href),e.sources=Array.from(new Set(e.sources)),q(50,1e3)})}function b(e){var t,r,n;return((n=(r=(t=e.firstChild)==null?void 0:t.textContent)==null?void 0:r.split(` -`)[0])==null?void 0:n.replace(/\s*\/\s*$/,""))??""}let L=!1;function X(){A(),k("#add-relationship-dialog",async e=>{const t=d(e,"//td[.='Work']/following-sibling::td//button");await l(100),t==null||t.click()})}async function Y(){A();const e=T(document.querySelector("#id-edit-work\\.name")),t=T(document.querySelector("input[name='edit-work.iswcs.0']")),r=document.querySelector("#id-edit-work\\.edit_note"),n=await M(f.Work);if(!(n!=null&&n.sources.length)){L||(await v(f.Work,{name:e.value||null,iswc:t.value||null,codes:{external:!1,jasrac:null,nextone:null},lyricists:[],composers:[],arrangers:[],publishers:[],sources:[],context:{tokens:Array.from(O(parent===window?document.body:parent.document.body))}}),q(50,1e3));return}if(L=!0,n.iswc&&y(t,n.iswc),n.codes.jasrac&&W("jasrac",n.codes.jasrac),n.codes.nextone&&W("nextone",n.codes.nextone),n.sources.length&&(r.value=`Filled out with Ame (MusicBrainz - Works): +(function(l){typeof define=="function"&&define.amd?define(l):l()})(function(){"use strict";function l(e){return new Promise(t=>{setTimeout(t,e)})}function N(e){const t=document.createElement("template");return t.innerHTML=e,t.content.firstElementChild}function S(e,t){return new Promise(r=>{const n=t==null?void 0:t.waitSelector,o=(t==null?void 0:t.timeout)??3e3;if(o!==0){const c=document.querySelector(e);if(c){r(c);return}}const a=setTimeout(()=>{o!==0&&(i.disconnect(),r(null))},o),i=new MutationObserver(c=>{for(const u of c)for(const s of Array.from(u.addedNodes))if(s instanceof Element&&s.matches(n??e)){o!==0&&(i.disconnect(),clearTimeout(a)),r(n?document.querySelector(e):s);return}});i.observe(document.body,{childList:!0,subtree:!0})})}function v(e,t){new MutationObserver(async n=>{for(const o of n)for(const a of o.addedNodes){if(!(a instanceof HTMLElement))continue;const i=a.matches(e)?a:a.querySelector(e);i&&await t(i)}}).observe(document.body,{childList:!0,subtree:!0})}function d(e,t){return document.evaluate(t,e,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function g(e,t){const r=document.evaluate(t,e,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);return Array.from({length:r.snapshotLength},(n,o)=>r.snapshotItem(o))}var m=(e=>(e.Work="work",e))(m||{});function k(e,t){if(document.visibilityState==="visible")return t==null?GM.deleteValue(e):(console.info("setBusValue",e,t),GM.setValue(e,{value:t,timestamp:new Date().getTime()+60*1e3}))}async function M(e){if(document.visibilityState!=="visible")return null;const t=await GM.getValue(e);return!t||(await k(e,null),t.timestamp>﹥≯¬¬||~~−⁻₋⁒∓-∕⁄∖-∛؆∜؇∝-∭⨌∮-∼≁∽-≀≂-≅≇≆≈-≍≭≎-≟≡-≤≰≥≱≦-≬≲≴≳≵≶≸≷≹≺⊀≻⊁≼⋠≽⋡≾≿⊂⊄⊃⊅⊆⊈⊇⊉-⊑⋢⊒⋣⊓-⊢⊬⊣-⊨⊭⊩⊮⊪⊫⊯-⊲⋪⊳⋫⊴⋬⊵⋭⊶-⊼⅋⊽-⋟⋤-⋩⋮-⋿⌠⌡⍼⎛-⎳⏜-⏡▷◁◸-◺◿⟀-⟄⟇-⟥⟰-⟿⤀-⤳⤶-⦂⦙-⧗⧜-⧻⧾-⨋⨍-⩳⩷-⫛⫝⫝̸⫞-⫿⬰-⭄⭇-⭌♯↔↮⤴⤵‼⁉〰〽◼◻◾◽]`.split("")),x={0:1,"0":1,1:2,"1":2,2:3,"2":3,3:4,"3":4,4:5,"4":5,5:6,"5":6,6:7,"6":7,7:8,"7":8,8:9,"8":9,9:10,"9":10,a:11,a:11,ä:11,b:12,b:12,c:13,c:13,d:14,d:14,e:15,e:15,f:16,f:16,g:17,g:17,h:18,h:18,i:19,i:19,j:20,j:20,k:21,k:21,l:22,l:22,m:23,m:23,n:24,n:24,o:25,o:25,ö:25,õ:25,p:26,p:26,q:27,q:27,r:28,r:28,s:29,s:29,$:29,t:30,t:30,u:31,u:31,ü:31,v:32,v:32,w:33,w:33,x:34,x:34,y:35,y:35,z:36,z:36},D=Object.entries(x).reduce((e,[t,r])=>(r in e||(e[r]=[]),e[r].push(t),e),{});function I(e){const t=x[e];return t?D[t]??[e]:[e]}function _(e){return e=e.replace(/[\s・]+/g,"").split("").map(t=>j.has(t)?"":`[${I(t).join("")}]`).join("[\\s\\p{Pc}\\p{Pd}\\p{Pe}\\p{Pf}\\p{Pi}\\p{Po}\\p{Ps}\\p{Sm}]{0,4}"),new RegExp(`(?)${e}`,"gui")}function P(e,t){e.innerHTML=e.innerHTML.replaceAll(t,r=>{const n=document.createElement("span");n.classList.add("ame__mark--inner"),n.innerText=r;const o=document.createElement("span");return o.classList.add("ame__mark"),o.appendChild(n),o.outerHTML})}function T(e){const t=e.value;return e.addEventListener("input",()=>{e.value!==t&&(e.style.backgroundColor="yellow")}),e}function y(e,t){if(e instanceof HTMLInputElement){Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value").set.call(e,t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("focusout",{bubbles:!0}));return}if(e instanceof HTMLSelectElement){Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype,"value").set.call(e,t),e.dispatchEvent(new Event("change",{bubbles:!0})),e.dispatchEvent(new Event("focusout",{bubbles:!0}));return}}function q(e,t){const r=p.createOscillator(),n=p.createGain();r.connect(n),n.connect(p.destination),n.gain.value=.25,r.frequency.value=t,r.start(p.currentTime),r.stop(p.currentTime+e/1e3)}async function z(){v("a[class^='LandingPage_languageButton__']",()=>{location.href="/search"})}async function G(){let e=!1;await w(m.Work,async t=>{if(!t.iswc)return;const r=document.querySelector("#iswc"),n=document.querySelector("button[type='submit']");if(y(r,t.iswc),await l(500),n==null||n.click(),e=await Promise.any([S("div[class^='Search_resultsContainer__'] div[class^='AlertMessage_text__']").then(()=>!0),S("[class^='Search_sectionTitle__']").then(i=>!i)]),e)return;const o=document.querySelector("[id='View More']");o.click(),await l(100);const a=d(document,"//button[.='Copy work codes']");a?(a.click(),t.codes.external=!0):o.after(N('
Install Bulk copy-paste work codes for better integration.
')),t.sources.push(location.href),t.sources=Array.from(new Set(t.sources)),q(50,1e3)}),e&&(location.href="/")}function $(){const e=document.querySelector(".logo > a");e&&(e.href=`${location.origin}/search`)}function U(){return w(m.Work,async e=>{if(!e.name)return;const t=document.querySelector("#kyokunm"),r=document.querySelector("#search-by-track-and-artist");t.value=e.name,r.click()})}function F(){for(const e of document.querySelectorAll(".saku-detail-link")){const t=document.createElement("a");t.target="_blank",t.href=`/saku/detail/?${e.getAttribute("data-href")}`,t.innerHTML=e.innerHTML,e.replaceWith(t)}return w(m.Work,async e=>{for(const n of e.context.tokens){const o=_(n);for(const a of document.querySelectorAll("#track-list tr td:nth-child(3), #track-list tr td:nth-child(4)"))P(a,o)}if(e.name)for(const n of document.querySelectorAll("#track-list tr td:nth-child(2)"))P(n,_(e.name));const t=document.querySelector("#kyokunm"),r=document.querySelector("#search-by-track-and-artist");!e.name||t.value===e.name||(t.value=e.name,r.click())})}function Q(){return w(m.Work,async e=>{var s,f,h,R,C,V,H,B;const t=((f=(s=d(document,"//h2/text()"))==null?void 0:s.nodeValue)==null?void 0:f.trim())||null,r=((R=(h=d(document,"//h3/text()[.!='-']"))==null?void 0:h.nodeValue)==null?void 0:R.replaceAll(" ",""))||null,n=((V=(C=d(document,"//a[@href='#jasrac']/following-sibling::*/span[2][.!='']"))==null?void 0:C.innerText)==null?void 0:V.trim())||null,o=((B=(H=d(document,"//a[@href='#nextone']/following-sibling::*/span[2][.!='']"))==null?void 0:H.innerText)==null?void 0:B.trim())||null,a=g(document,"//div[contains(@class, 'management')]//td[contains(., '作詞')]/parent::tr/*[2]").map(b).filter(Boolean),i=g(document,"//div[contains(@class, 'management')]//td[contains(., '作曲')]/parent::tr/*[2]").map(b).filter(Boolean),c=g(document,"//div[contains(@class, 'management')]//td[contains(., '編曲')]/parent::tr/*[2]").map(b).filter(Boolean),u=g(document,"//div[contains(@class, 'management')]//td[contains(., '出版者')]/parent::tr/*[2]").map(b).filter(Boolean);r&&(e.iswc=r),n&&(e.codes.jasrac=n),o&&(e.codes.nextone=o),e.lyricists=a,e.composers=i,e.arrangers=c,e.publishers=u,e.sources.push(location.href),e.sources=Array.from(new Set(e.sources)),q(50,1e3)})}function b(e){var t,r,n;return((n=(r=(t=e.firstChild)==null?void 0:t.textContent)==null?void 0:r.split(` +`)[0])==null?void 0:n.replace(/\s*\/\s*$/,""))??""}let L=!1;function X(){A(),v("#add-relationship-dialog",async e=>{const t=d(e,"//td[.='Work']/following-sibling::td//button");await l(100),t==null||t.click()})}async function Y(){A();const e=T(document.querySelector("#id-edit-work\\.name")),t=T(document.querySelector("input[name='edit-work.iswcs.0']")),r=document.querySelector("#id-edit-work\\.edit_note"),n=await M(m.Work);if(!(n!=null&&n.sources.length)){L||(await k(m.Work,{name:e.value||null,iswc:t.value||null,codes:{external:!1,jasrac:null,nextone:null},lyricists:[],composers:[],arrangers:[],publishers:[],sources:[],context:{tokens:Array.from(O(parent===window?document.body:parent.document.body))}}),q(50,1e3));return}if(L=!0,n.iswc&&y(t,n.iswc),n.codes.jasrac&&W("jasrac",n.codes.jasrac),n.codes.nextone&&W("nextone",n.codes.nextone),n.sources.length&&(r.value=`Filled out with Ame (MusicBrainz - Works): ${n.sources.join(` `)} -`),n.codes.external){const o=document.querySelector("#ROpdebee_MB_Paste_Work");o==null||o.click()}for(const o of n.lyricists)await E("artist","lyrics / lyricist",o);for(const o of n.composers)await E("artist","composed / composer",o);for(const o of n.arrangers)await E("artist","arranged / arranger",o);for(const o of n.publishers)await E("label","published / publisher",o)}function A(){k("ul[id^='relationship-target']",async e=>{new MutationObserver(async r=>{const n=r[0],o=e.style.visibility;if(o==="hidden"||o===n.oldValue)return;const a=e.firstElementChild;if(a!=null&&a.innerText.includes("Click here to try again")){await l(100),a.click();return}const c=document.getElementById(e.getAttribute("aria-labelledby")).control,u=O();c.value&&u.add(c.value);for(const s of u){const m=_(s);for(const h of e.children)P(h,m)}}).observe(e,{attributes:!0,attributeOldValue:!0,attributeFilter:["style"]})})}function O(e=document.body){return new Set(Array.from(e.querySelectorAll("a[href^='/artist/'][title]")).map(t=>t.innerText.trim()))}async function E(e,t,r){document.querySelector("button.add-relationship").click();const o=await S("#add-relationship-dialog");if(!o)return;const a=o.querySelector("select.entity-type");y(a,e);const i=o.querySelector("input.relationship-type");y(i,t),d(o,`//li[contains(@class, 'option-item') and contains(., '${t}')]`).click();const c=o.querySelector(".relationship-target input");y(c,r),await l(300),o.querySelector(".relationship-target button").click(),await new Promise(s=>{const m=o.querySelector("button.negative"),h=o.querySelector("button.positive");m.addEventListener("click",()=>s()),h.addEventListener("click",()=>s())}),await l(300)}function W(e,t){e=e.toLowerCase();const r=document.querySelector("#add-work-attribute");for(let n=0;n<2;n++){for(const o of document.querySelectorAll("#work-attributes tr:not(:last-child)")){const a=o.querySelector("select"),i=a.selectedOptions[0],c=Array.from(a.options).filter(s=>s.innerText.trim().toLowerCase().startsWith(e))[0];if(i!==c&&i.value)continue;c.selected=!0;const u=T(o.querySelector("input"));u.value=t;return}r.click(),W(e,t)}}GM.addStyle(".ame__mark{background-color:#ff0e!important;outline:2px solid #ffff00ee!important}.ame__mark--inner{color:#000!important;filter:brightness(.1)}");const K=new URLSearchParams(location.search);window.addEventListener("focus",async()=>{var e,t;await l(100),!(!window.document.hasFocus()&&!((e=window.top)!=null&&e.document.hasFocus()))&&(location.host.endsWith("musicbrainz.org")?location.pathname.startsWith("/release/")&&location.pathname.endsWith("/edit-relationships")?await X():(location.pathname.startsWith("/work/")&&location.pathname.endsWith("/edit")||location.pathname.startsWith("/dialog")&&((t=K.get("path"))!=null&&t.startsWith("/work/create")))&&await Y():location.host.endsWith("minc.or.jp")?(await $(),location.pathname.startsWith("/search")?await U():location.pathname.startsWith("/music/list")?await F():location.pathname.startsWith("/saku/detail")&&await Q()):location.host.endsWith("cisac.org")&&(await z(),location.pathname.startsWith("/search")&&await G()))}),window.dispatchEvent(new Event("focus"))}); +`),n.codes.external){const o=document.querySelector("#ROpdebee_MB_Paste_Work");o==null||o.click()}for(const o of n.lyricists)await E("artist","lyrics / lyricist",o);for(const o of n.composers)await E("artist","composed / composer",o);for(const o of n.arrangers)await E("artist","arranged / arranger",o);for(const o of n.publishers)await E("label","published / publisher",o)}function A(){v("ul[id^='relationship-target']",async e=>{new MutationObserver(async r=>{const n=r[0],o=e.style.visibility;if(o==="hidden"||o===n.oldValue)return;const a=e.firstElementChild;if(a!=null&&a.innerText.includes("Click here to try again")){await l(100),a.click();return}const c=document.getElementById(e.getAttribute("aria-labelledby")).control,u=O();c.value&&u.add(c.value);for(const s of u){const f=_(s);for(const h of e.children)P(h,f)}}).observe(e,{attributes:!0,attributeOldValue:!0,attributeFilter:["style"]})})}function O(e=document.body){return new Set(Array.from(e.querySelectorAll("a[href^='/artist/'][title]")).map(t=>t.innerText.trim()))}async function E(e,t,r){document.querySelector("button.add-relationship").click();const o=await S("#add-relationship-dialog");if(!o)return;const a=o.querySelector("select.entity-type");y(a,e);const i=o.querySelector("input.relationship-type");y(i,t),d(o,`//li[contains(@class, 'option-item') and contains(., '${t}')]`).click();const c=o.querySelector(".relationship-target input");y(c,r),await l(300),o.querySelector(".relationship-target button").click(),await new Promise(s=>{const f=o.querySelector("button.negative"),h=o.querySelector("button.positive");f.addEventListener("click",()=>s()),h.addEventListener("click",()=>s())}),await l(300)}function W(e,t){e=e.toLowerCase();const r=document.querySelector("#add-work-attribute");for(let n=0;n<2;n++){for(const o of document.querySelectorAll("#work-attributes tr:not(:last-child)")){const a=o.querySelector("select"),i=a.selectedOptions[0],c=Array.from(a.options).filter(s=>s.innerText.trim().toLowerCase().startsWith(e))[0];if(i!==c&&i.value)continue;c.selected=!0;const u=T(o.querySelector("input"));u.value=t;return}r.click(),W(e,t)}}GM.addStyle(".ame__mark{background-color:#ff0e!important;outline:2px solid #ffff00ee!important}.ame__mark--inner{color:#000!important;filter:brightness(.1)}");const K=new URLSearchParams(location.search);window.addEventListener("focus",async()=>{var e,t;await l(100),!(!window.document.hasFocus()&&!((e=window.top)!=null&&e.document.hasFocus()))&&(location.host.endsWith("musicbrainz.org")?location.pathname.startsWith("/release/")&&location.pathname.endsWith("/edit-relationships")?await X():(location.pathname.startsWith("/work/")&&location.pathname.endsWith("/edit")||location.pathname.startsWith("/dialog")&&((t=K.get("path"))!=null&&t.startsWith("/work/create")))&&await Y():location.host.endsWith("minc.or.jp")?(await $(),location.pathname.startsWith("/search")?await U():location.pathname.startsWith("/music/list")?await F():location.pathname.startsWith("/saku/detail")&&await Q()):location.host.endsWith("cisac.org")&&(await z(),location.pathname.startsWith("/search")&&await G()))}),window.dispatchEvent(new Event("focus"))}); diff --git a/src/musicbrainz-works/main.ts b/src/musicbrainz-works/main.ts index 90a4474..0f43256 100644 --- a/src/musicbrainz-works/main.ts +++ b/src/musicbrainz-works/main.ts @@ -1,7 +1,7 @@ // ==UserScript== // @namespace ame-musicbrainz-works // @name Ame (MusicBrainz - Works) -// @version 0.3.1 +// @version 0.3.2 // @author SuperSaltyGamer // @run-at document-end // @match https://musicbrainz.org/* diff --git a/src/musicbrainz-works/modules/iswcnet.ts b/src/musicbrainz-works/modules/iswcnet.ts index 6fbd3b0..8e65b73 100644 --- a/src/musicbrainz-works/modules/iswcnet.ts +++ b/src/musicbrainz-works/modules/iswcnet.ts @@ -20,6 +20,7 @@ export async function onIswcNetSearchPage() { const searchEl = document.querySelector("button[type='submit']")!; setReactInputValue(iswcEl, work.iswc); + await sleep(500); searchEl?.click(); captcha = await Promise.any([ diff --git a/src/musicbrainz-works/modules/minc.ts b/src/musicbrainz-works/modules/minc.ts index ded70ca..acd9d43 100644 --- a/src/musicbrainz-works/modules/minc.ts +++ b/src/musicbrainz-works/modules/minc.ts @@ -52,10 +52,10 @@ export function onMincWorkPage() { const iswc = pathSelector(document, "//h3/text()[.!='-']")?.nodeValue?.replaceAll(" ", "") || null; const jasrac = pathSelector(document, "//a[@href='#jasrac']/following-sibling::*/span[2][.!='']")?.innerText?.trim() || null; const nextone = pathSelector(document, "//a[@href='#nextone']/following-sibling::*/span[2][.!='']")?.innerText?.trim() || null; - const lyricists = pathSelectorAll(document, "//td[contains(., '作詞')]/parent::tr/*[2]").map(getCredit).filter(Boolean); - const composers = pathSelectorAll(document, "//td[contains(., '作曲')]/parent::tr/*[2]").map(getCredit).filter(Boolean); - const arrangers = pathSelectorAll(document, "//td[contains(., '編曲')]/parent::tr/*[2]").map(getCredit).filter(Boolean); - const publishers = pathSelectorAll(document, "//td[contains(., '出版者')]/parent::tr/*[2]").map(getCredit).filter(Boolean); + const lyricists = pathSelectorAll(document, "//div[contains(@class, 'management')]//td[contains(., '作詞')]/parent::tr/*[2]").map(getCredit).filter(Boolean); + const composers = pathSelectorAll(document, "//div[contains(@class, 'management')]//td[contains(., '作曲')]/parent::tr/*[2]").map(getCredit).filter(Boolean); + const arrangers = pathSelectorAll(document, "//div[contains(@class, 'management')]//td[contains(., '編曲')]/parent::tr/*[2]").map(getCredit).filter(Boolean); + const publishers = pathSelectorAll(document, "//div[contains(@class, 'management')]//td[contains(., '出版者')]/parent::tr/*[2]").map(getCredit).filter(Boolean); if (iswc) work.iswc = iswc; if (jasrac) work.codes.jasrac = jasrac;