/mb-bookmarklets

Personal bookmarklets for musicbrainz

Primary LanguageJavaScriptMIT LicenseMIT

musicbrainz bookmarklets

This is a collection of my personal bookmarklets for my personal use. Well actually at this point it is only one and honestly it is not very sophisticated.

ch-track-extractor

Bookmarklet script for extracting track data from Swiss sites.

Bookmarklet to extract track data a number of from Swiss sites. Currently supported are cede.ch ,exlibris.ch and fonoteca.ch. The code here is still alpha level quality! Use at your own risk.

javascript:(()=>{const l={"Audio track":"number","Musical work title":"name","Work title":"name",Position:"number",Musikwerktitel:"name",Werktitel:"name","Traccia audio":"number","Titolo dell'opera musicale":"name","Titolo dell'opera":"name","Plage audio":"number","Titre de l'oeuvre musicale":"name","Titre de l'oeuvre":"name",Pusiziun:"number","Titel da l'ovra musicala":"name","Titel da l'ovra":"name"};function t(){let e=null;const t=[];var n,a;for(n of document.getElementsByClassName("tbl-detail-tdlft"))if(content=n.parentNode.getElementsByTagName("td"),label=(a=content[0].innerText,l[a]??null),text=content[1].innerText,label)switch(label){case"number":e=null==e?0:e+1,t[e]={number:text};break;case"name":t[e].name=text}return t}String.prototype.cleanTrack=function(){return this.replace(/.*-\s+\d+[\.,]\s+/,"")};{let e=[];switch(window.location.hostname.replace(/.*\.(.*\..*)$/,"$1")){case"cede.ch":e=function(){const e=[];var t;for(t of document.getElementById("player").getElementsByClassName("track"))number=t.getElementsByClassName("tracknumber")[0].textContent,duration=t.getElementsByClassName("duration")[0].textContent,name=t.getElementsByClassName("trackname")[0].firstChild.textContent.cleanTrack(),e.push({number:number,name:name,duration:duration});return e}();break;case"exlibris.ch":e=function(){const e=[];var t;for(t of document.getElementsByClassName("o-tracks")[0].getElementsByTagName("table"))for(var n of t.getElementsByTagName("tr"))elements=n.getElementsByTagName("td"),firstCell=elements.length-3,number=elements[firstCell].textContent,name=elements[firstCell+1].textContent.cleanTrack(),duration=elements[firstCell+2].textContent,e.push({number:number,name:name,duration:duration});return e}();break;case"fonoteca.ch":e=t()}var n=function(e){let t="";return e.forEach(e=>{console.log(e),t+=e.number.trim().replace(/\.$/,"")+". ",t+=e.name.trim()+" ",t+="(",t+=e.duration||"??:??",t+=")\n"}),t}(e);console.log(n);{if(""===n)return;let e=document.createElement("textarea");e.value=n,e.style.top="0",e.style.left="0",e.style.position="fixed",document.body.appendChild(e),e.focus(),e.select()}}})();