Last active
July 16, 2020 05:05
-
-
Save jesus2099/8e223f09d64d831a9514 to your computer and use it in GitHub Desktop.
Display AcousticBrainz links in release pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name mb. ACOUSTICBRAINZ LINKS (for STalKer-X) | |
// @version 2015.3.26.1322 | |
// @description musicbrainz.org: displays AB links in release pages | |
// @compatible opera(12) | |
// @compatible opera+violentmonkey | |
// @namespace https://github.com/jesus2099/konami-command | |
// @downloadURL https://gist.github.com/jesus2099/8e223f09d64d831a9514/raw/mb_ACOUSTICBRAINZ-LINKS.user.js | |
// @updateURL https://gist.github.com/jesus2099/8e223f09d64d831a9514/raw/mb_ACOUSTICBRAINZ-LINKS.user.js | |
// @author PATATE12 | |
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/) | |
// @since 2015-03-24 | |
// @grant none | |
// @include http*://*.mbsandbox.org/release/* | |
// @include http*://*musicbrainz.org/release/* | |
// @exclude *.org/release/*/* | |
// @exclude *//*/*mbsandbox.org/* | |
// @exclude *//*/*musicbrainz.org/* | |
// @run-at document-end | |
// ==/UserScript== | |
"use strict"; | |
var recordings = document.querySelectorAll("div#content table.tbl > tbody > tr > td a[href*='/recording/']"); | |
for (var rec = 0; rec < recordings.length; rec++) { | |
var mbid = recordings[rec].getAttribute("href").match(/\/recording\/([a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12})$/i); | |
if (mbid) { | |
var td = !getParent(recordings[rec], "dd") && getParent(recordings[rec], "td"); | |
if (td) { | |
td.appendChild(document.createTextNode(" ")); | |
var ablink = document.createElement("a"); | |
ablink.setAttribute("href", "http://acousticbrainz.org/"+mbid[1]); | |
// ablink.setAttribute("target", "_blank"); | |
ablink.style.setProperty("float", "right"); | |
var abimg = document.createElement("img"); | |
abimg.setAttribute("src", "data:image/png;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M01COE/AgcAAAAASUVORK5CYII="); | |
abimg.setAttribute("alt", "AcousticBrainz"); | |
abimg.setAttribute("title", "AcousticBrainz"); | |
ablink.appendChild(abimg); | |
td.insertBefore(ablink, td.firstChild); | |
} | |
} | |
} | |
function getParent(obj, tag, cls) { | |
var cur = obj; | |
if (cur.parentNode) { | |
cur = cur.parentNode; | |
if (cur.tagName == tag.toUpperCase() && (!cls || cls && cur.className.match(new RegExp("\\W*"+cls+"\\W*")))) { | |
return cur; | |
} else { | |
return getParent(cur, tag, cls); | |
} | |
} else { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment