There are 27 previous versions of this script.
// ==UserScript==
// @name MB. check all votes (dblclick to vote single edit)
// @description Adds some buttons to check all unvoted edits (Yes/No/Abs/None) at once in the edit search page. Use shift+click to force all votes, a vote reset button is also available to cancel shift+click (musicbrainz) + Double click radio to vote single edit.
// @version 2011-12-28_1102
// @author Tristan DANIEL (jesus2099)
// @contact http://miaou.ions.fr
// @licence GPL (http://www.gnu.org/copyleft/gpl.html)
// @namespace http://userscripts.org/scripts/show/57765
//
// @include http://*musicbrainz.org/*
// ==/UserScript==
(function () {
/* - --- - --- - --- - START OF CONFIGURATION - --- - --- - --- - */
var showtop = true;
var showbottom = true;
var hide_MBS_2944_bug = false; /* http://tickets.musicbrainz.org/browse/MBS-2944 seems to be fixed now server side */
var border = "thin dashed red"; /*leave "" for defaults*/
var submitButtonOnTopToo = true;
var onlySubmitTabIndexed = true; /*hit tab after typed text or voted directly goes to a submit button*/
var text = " // Check all unvoted edits (shift+click to force all votes) \u2192 ";
var canceltext = "Reset votes";
var scrollToEdits = true;
/* - --- - --- - --- - END OF CONFIGURATION - --- - --- - --- - */
var editform = document.getElementById("edits");
if (editform) {
if (hide_MBS_2944_bug) {
var mbs2944bug = document.getElementsByClassName("overall-vote");
if (mbs2944bug.length == 1) { mbs2944bug[0].style.display = "none"; }
}
editform = editform.getElementsByTagName("form")[0];
var radios = new Array();
var radiosafe = new Array();
var inputs = editform.getElementsByTagName("input");
for (i = 0; i < inputs.length; i++) {
if (inputs[i].getAttribute("type") == "radio") {
if (onlySubmitTabIndexed) { inputs[i].setAttribute("tabindex", "-1"); }
radios.push(inputs[i]);
inputs[i].setAttribute("title", "double-click to vote this single edit");
inputs[i].addEventListener("dblclick", function (e) {
var ed = getParent(this, "div", "edit-list");
if (ed) {
var id;
var vote = this.value;
var note;
var url = self.location.href;
var is = ed.getElementsByTagName("input");
for (var iis=0; iis < is.length; iis++) {
if (is[iis].getAttribute("name").match(/edit_id$/)) {
id = is[iis].value;
}
}
var ta = ed.getElementsByTagName("textarea");
if (ta && ta[0]) {
note = ta[0].value;
}
if (id, vote) {
var form = document.createElement("form");
form.setAttribute("action", "/edit/enter_votes");
form.setAttribute("method", "post");
form.appendChild(createInput("hidden", "enter-vote.vote.0.edit_id", id));
form.appendChild(createInput("hidden", "enter-vote.vote.0.vote", vote));
if (note) { form.appendChild(createInput("hidden", "enter-vote.vote.0.edit_note", note)); }
form.appendChild(createInput("hidden", "url", url));
ed.appendChild(form);
form.submit();
}
}
}, false);
if (inputs[i].checked) { radiosafe.push(inputs[i]); }
}
}
if (radios.length > 4) {
if (showtop) { editform.insertBefore( shortcutsRow(), editform.firstChild ); }
if (showbottom) { editform.insertBefore( shortcutsRow(), editform.lastChild.previousSibling ); }
}
if (submitButtonOnTopToo) {
var submitButton = editform.getElementsByTagName("button")[0];
var submitClone = editform.insertBefore(submitButton.parentNode.parentNode.cloneNode(true), editform.firstChild);
submitClone.addEventListener("click", function (e) { editform.submit(); }, false);
}
if (scrollToEdits) {
var foundcount = document.getElementById("page").getElementsByTagName("strong")[0];
var navpages = document.getElementById("edits").getElementsByTagName("em")[0];
var addedStuff;
if (navpages && navpages.parentNode.className == "pageselector") {
navpages.appendChild(document.createTextNode(" \u2014 "));
addedStuff = navpages.appendChild(foundcount.cloneNode(true));
} else if (submitClone) {
addedStuff = submitClone.appendChild(foundcount.cloneNode(true));
addedStuff.style.cssFloat= "left";
} else {
addedStuff = editform.insertBefore(foundcount.parentNode.parentNode.cloneNode(true), editform.firstChild);
}
foundcount.parentNode.parentNode.parentNode.removeChild(foundcount.parentNode.parentNode);
var artistlnk = document.getElementsByClassName("artistheader");
if (addedStuff && artistlnk && artistlnk[0] && artistlnk[0].getElementsByTagName("a") && artistlnk[0].getElementsByTagName("a")[0]) {
addedStuff.appendChild(document.createTextNode(" for "));
artistlnk = artistlnk[0].getElementsByTagName("a")[0].cloneNode(true);
addedStuff.appendChild(artistlnk);
artistlnk.style.border = artistlnk.style.padding = artistlnk.style.margin = "0";
artistlnk.style.fontSize = "1.2em";
artistlnk.style.fontWeight = "normal";
artistlnk.style.color = "black";
}
self.addEventListener("load", function(e) {
self.scrollTo(0, findPos(document.getElementById("edits"))["y"]);
}, false);
}
}
function shortcutsRow() {
var editlist, editactions, voteopts, editdetails;
editlist = mkElt("div", "edit-list");
editlist.style.border = border;
editactions = mkElt("div", "edit-actions c applied");
voteopts = mkElt("div", "voteopts");
voteopts.style.width = "175px";
voteopts.style.margin = 0;
voteopts.appendChild(shortcut("1", "Yes"));
voteopts.appendChild(shortcut("0", "No"));
voteopts.appendChild(shortcut("-1", "Abstain"));
voteopts.appendChild(shortcut("-2", "None"));
editactions.appendChild(voteopts);
editlist.appendChild(editactions);
editdetails = mkElt("div", "edit-details");
editdetails.style.textAlign = "right";
editdetails.style.margin = 0;
editdetails.appendChild(shortcut("omgcancel", canceltext));
editdetails.appendChild(document.createTextNode(text));
editlist.appendChild(editdetails)
return editlist;
}
function mkElt(typ, cls) {
var obj = document.createElement(typ);
obj.className = cls;
return obj;
}
function shortcut(vote, txt) {
var button = document.createElement("input");
button.setAttribute("type", "button");
if (onlySubmitTabIndexed) { button.setAttribute("tabindex", "-1"); }
button.style.padding = "0 1px";
button.style.margin = "0 1px";
button.appendChild( document.createTextNode(txt) );
button.setAttribute("value", txt);
button.addEventListener("click", function (e) { doitdoit(e, vote); }, false);
return button;
}
function doitdoit(e, vote) {
if (vote != "omgcancel") {
for (i = 0; i < radios.length; i++) {
if (radios[i].getAttribute("value") == vote) {
if (e.shiftKey || isOkToVote(radios[i])) {
radios[i].click();
}
}
}
}
else { for (i = 0; i < radiosafe.length; i++) { radiosafe[i].click(); } }
}
function isOkToVote(radiox) {
return radiox.parentNode.parentNode.getElementsByTagName("input")[3].checked;
}
function createInput(type, name, value) {
var input;
if (type == "textarea") {
input = document.createElement("textarea");
input.appendChild(document.createTextNode(value));
} else {
input = document.createElement("input");
input.setAttribute("type", type);
input.setAttribute("value", value);
}
input.setAttribute("name", name);
return input;
}
function getParent(obj, tag, cls) {
var cur = obj;
if (cur.parentNode) {
cur = cur.parentNode;
if (cur.tagName == tag.toUpperCase() && cur.className == cls) {
return cur;
} else {
return getParent(cur, tag, cls);
}
} else {
return null;
}
}
function findPos(obj) { /* http://www.quirksmode.org/js/findpos.html */
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return {"x":curleft, "y":curtop};
}
})();