// ==UserScript== // @name MusicBrainz: Set recording comments for a release // @version 2014-11-11 // @author Michael Wiencek // @namespace 790382e7-8714-47a7-bfbd-528d0caa2333 // @include *://musicbrainz.org/release/* // @include *://beta.musicbrainz.org/release/* // @include *://*.mbsandbox.org/release/* // @match *://musicbrainz.org/release/* // @match *://beta.musicbrainz.org/release/* // @match *://*.mbsandbox.org/release/* // @grant none // ==/UserScript== var scr = document.createElement("script"); scr.textContent = "$(" + setRecordingComments + ");"; document.body.appendChild(scr); function setRecordingComments() { _.each(["/static/lib/sha1/sha1.js", "/static/scripts/edit/MB/edit.js"], function (src) { var script = document.createElement("script"); script.src = src; document.head.appendChild(script); }); var $tracks, $inputs = $(), nameColumn = 1; $("head").append($("").text("input.recording-comment { background: inherit; border: 1px #999 solid; width: 32em; margin-left: 0.5em; }")); var delay = setInterval(function () { if ($("th.video").length > 0) { nameColumn = 2; } $tracks = $(".tbl tbody tr[data-bind*='even:']"); if ($tracks.length) { clearInterval(delay); } else { return; } $tracks.each(function () { var $td = $(this).children("td").eq(nameColumn), node = ($td.find(".mp")[0] || $td.find(".name-variation")[0] || $td.find("a[href^=\\/recording\\/]")[0]), $input = $("").addClass("recording-comment").insertAfter(node); if (!editing) { $input.hide(); } $inputs = $inputs.add($input); }); var release = location.match(MBID_REGEX)[0]; $.get("/ws/2/release/" + release + "?inc=recordings&fmt=json", function (data) { var comments = _.pluck(_.pluck(_.flatten(_.pluck(data.media, "tracks")), "recording"), "disambiguation"); for (var i = 0, len = comments.length; i < len; i++) { var comment = comments[i]; $inputs.eq(i).val(comment).data("old", comment); } }); }, 1000); var location = window.location.pathname; if (!location.match(/\/release\/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$/)) { return; } var MBID_REGEX = /[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/, editing = false, activeRequest = null; $("body").on("input.rc", ".recording-comment", function () { $(this).css("border-color", this.value === $(this).data("old") ? "#999" : "red"); }); var $container = $("
").insertBefore("table.tbl"); $("") .addClass("styled-button") .on("click", function () { editing = !editing; $("#set-recording-comments").add($inputs).toggle(editing); $(this).text((editing ? "Hide" : "Edit") + " recording comments"); }) .appendTo($container); $container.append('\\ | \ |
\ | \ |
\ \ | \