User:HarJIT/votesymbols.js

// User:HarJIT/votesymbols.js branch from User:Ais523/votesymbols.js // Code to cause icons to appear before emboldened markers in discussions, makes no changes to the page itself. // Some images used subject to attribution requirements, click them once inserted to view their info pages.

// Three modes: // - override: will replace existing icons and add additional ones (default). // - replace-only: will only replace existing icons. // - supplement: will only add additional icons.

// You can define these before importing this script: // // VOTESYMBOLS_THEMES = {"myicontheme": [...], ...}; // "norro-one" is builtin, cannot be customised. // VOTESYMBOLS_THEME = "myicontheme"; // defaults to "norro-one" // VOTESYMBOLS_MODE = "override"; // or "supplement", "replace-only"

var wgNamespaceNumber = mw.config.get('wgNamespaceNumber'); $( function {    if (wgNamespaceNumber === 0){        return; //avoid article space, generally speaking    };    var lowerNoPunct = function(s) {        return s.toLowerCase.split('.').join().split(',').join().split(':').join().split(';').join().split('+').join('');    };    var mode = (typeof VOTESYMBOLS_MODE != "undefined")?(VOTESYMBOLS_MODE):("override");    var themes = (typeof VOTESYMBOLS_THEMES != "undefined")?(VOTESYMBOLS_THEMES):({});    themes["norro-one"] = [        "//upload.wikimedia.org/wikipedia/commons/thumb/9/94/Symbol_support_vote.svg/15px-Symbol_support_vote.svg.png",        "//upload.wikimedia.org/wikipedia/commons/thumb/d/d0/Symbol_keep_vote.svg/15px-Symbol_keep_vote.svg.png",        "//upload.wikimedia.org/wikipedia/commons/thumb/7/7f/Symbol_oppose_vote.svg/15px-Symbol_oppose_vote.svg.png",        "//upload.wikimedia.org/wikipedia/commons/thumb/8/89/Symbol_delete_vote.svg/15px-Symbol_delete_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/8/89/Symbol_neutral_vote.svg/15px-Symbol_neutral_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Symbol_merge_vote.svg/15px-Symbol_merge_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/5/50/Symbol_move_vote.svg/15px-Symbol_move_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/0/0c/Symbol_redirect_vote.svg/15px-Symbol_redirect_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/b/ba/Symbol_opinion_vote.svg/15px-Symbol_opinion_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Symbol_comment_vote.svg/15px-Symbol_comment_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Symbol_unsupport_vote.svg/15px-Symbol_unsupport_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Symbol_question.svg/15px-Symbol_question.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Symbol_divide_vote.svg/15px-Symbol_divide_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/5/54/Symbol_wait.svg/15px-Symbol_wait.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Face-grin.svg/15px-Face-grin.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Symbol_support2_vote.svg/15px-Symbol_support2_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Symbol_no_support_vote.svg/15px-Symbol_no_support_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/9/90/Cancelled_process_mini.svg/22px-Cancelled_process_mini.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/4/41/Symbol_confirmed.svg/15px-Symbol_confirmed.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/8/85/Symbol_unrelated.svg/15px-Symbol_unrelated.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Symbol_Translate.svg/15px-Symbol_Translate.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Symbol_unsupport2_vote.svg/15px-Symbol_unsupport2_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/8/89/Symbol_redirect_vote2.svg/15px-Symbol_redirect_vote2.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/3/30/Symbol_deferred.svg/15px-Symbol_deferred.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Symbol_possible_vote.svg/15px-Symbol_possible_vote.svg.png", "//upload.wikimedia.org/wikipedia/commons/thumb/0/0f/Checkhalf.png/15px-Checkhalf.png", [] /* Allow the last actual item to end in a comma. */   ];    var la = { "support": 0, "endorse": 0, "added": 0, "posted": 0, "likely": 0, "works":0, "keep": 1, "allow": 1, "permit": 1, "fixed": 1, "semi-done": 1, "~done": 1, "block~tagged": 1, "block~exemption": 1, "block~proxy": 1, "block~range": 1, "block~proxies": 1, "oppose": 2, "overturn": 2, "object": 2, "disallow": 2, "disagree": 2, "denied": 2, "invalid": 2, "unnecessary": 2, "removed": 2, "!action": 2, "!comment": 2, "!approve": 2, "!approved": 2, "delete": 3, "neutral": 4, "merge": 5, "upmerge": 5, "assistance": 5, "move": 6, "rename": 6, "userfy": 6, "transwiki": 6, "listify": 6, "relisted": 6, "redirect": 7, "retarget": 7, "prority": 8, "opinion": 8, "relist": 8, "subst": 8, "salt": 8, "change": 8, "list": 8, "acknowledged": 8, "remind": 8, "priority": 8, "warning": 8, "comment": 9, "update": 9, "note": 9, "assigned": 9, "remark": 9, "delist": 10, "delisted": 10, "inconclusive": 10, "!applicable": 10, "question": 11, "investigating": 11, "feedback": 11, "suggestion": 11, "!sure": 11, "split": 12, "wait": 13, "pending": 13, "hold": 13, "reviewing": 13, "awaiting": 13, "later": 13, "ongoing": 13, "doing": 13, "progress": 13, "checking": 13, "started": 13, "bjaodn": 14, "undelete": 15, "restore": 15, "endorsed": 15, "close": 16, "!possible": 16, "closed": 16, "withdraw": 17, "withdrawn": 17, "cancel": 17, "cancelled": 17, "resolved": 18, "accepted": 18, "agree": 18, "approved": 18, "checked": 18, "verified": 18, "confirmed": 18, "helped": 18, "done": 18, "complete": 18, "answered": 18, "responded": 18, "pass": 18, "yes": 18, "implemented": 18, "indistinguishable": 18, "unrelated": 19, "expired": 19, "deleted": 19, "stale": 19, "rejected": 19, "fail": 19, "!bug": 19, "!done": 19, "!pass": 19, "!fixed": 19, "!fix": 19, "!evidence": 19, "block~user": 19, "sul": 20, "declined": 21, "duplicate": 22, "dupe": 22, "defer": 23, "deferred": 23, "possible": 24, "possibly": 24, "~implemented": 25, null: [] /* Allow the last actual item to end in a comma. */   };    var lowpriori = { /* Only if none of the above found. */       "block~ip": 1, "new": 4, "discussion": 9, "needed": 11, "block~blocked": 19, null: [] /* Allow the last actual item to end in a comma. */   }

var btc = document.getElementById("mw-content-text").getElementsByTagName("b"); for (var i = 0; i < btc.length; i += 1) { var j = (typeof btc[i].textContent != "undefined")?(btc[i].textContent):(btc[i].innerText); j = j.split(":").join(" ").split(";").join(" ").split(",").join(" ").split(".").join(" ").split(" "); var x = []; var negate = 0; var semi = 0; var block = 0; for (var k = 0; k < j.length; k += 1) { var lnp = lowerNoPunct(j[k]); if (lnp == "don't" || lnp == 'not' || lnp == 'no' || lnp == 'without' || lnp == "won't") { negate = 1; } else if (lnp == "half" || lnp == "partly" || lnp == "partially" || lnp == "semi" ||                      lnp == "almost" || lnp == "nearly") { semi = 1; } else if (lnp == "block" || lnp == "blocked") { block = 1; };       };        var add_to_x = function (imid, lnp) { var imurl = themes[(typeof VOTESYMBOLS_THEME != "undefined")?(VOTESYMBOLS_THEME):("norro-one")][imid]; var iminfo; if (imurl.split(".svg/").length - 1) { iminfo = imurl.split(".svg/")[1].split("px-")[1].slice(0,-4); } else { iminfo = imurl.split("px-")[1]; };           var infolink = document.createElement("a"); infolink.setAttribute("href", "https://commons.wikimedia.org/wiki/Image:" + iminfo); var image = document.createElement("img"); infolink.appendChild(image); image.setAttribute("src", imurl); image.setAttribute("alt", " "); image.setAttribute("title", lnp); image.style["margin-right"] = "0.8ex"; x[x.length] = infolink; };       for (var k = 0; k < j.length; k += 1) { var lnp = lowerNoPunct(j[k]); lnp = ((negate)?("!"):("")) + ((semi)?("~"):("")) + ((block)?("block~"):("")) + lnp; if (typeof la[lnp] != "undefined") { add_to_x(la[lnp], lnp); };       };        if (x.length == 0) { for (var k = 0; k < j.length; k += 1) { var lnp = lowerNoPunct(j[k]); lnp = ((negate)?("!"):("")) + ((semi)?("~"):("")) + ((block)?("block~"):("")) + lnp; if (typeof lowpriori[lnp] != "undefined") { add_to_x(lowpriori[lnp], lnp); };           };        };        if (x.length > 0) { /* NOT else if */ var curs = btc[i]; var pres = curs.previousSibling; var ifexists = function {}; if (curs.parentNode.nodeName.toLowerCase == "span" && curs.parentNode.childNodes.length == 1){ pres = curs.parentNode.previousSibling; if (mode == "override") { curs.parentNode.parentNode.insertBefore(curs, curs.parentNode); } else if (mode == "replace-only") { ifexists = function { curs.parentNode.parentNode.insertBefore(curs, curs.parentNode); }; };           };            var tmpres = null; var isexisting = 0; steps = 10; while (pres && steps--) { var itx = (typeof pres.textContent != "undefined")?(pres.textContent):(pres.innerText); if ( pres.nodeType == Node.TEXT_NODE &&                     ( pres.nodeValue.split(" ").join("").split(" ").join("").split("&#160;").join("") ).split("\u00A0").join("") == ""                   ) { tmpres = pres; pres = pres.previousSibling; if (mode == "override" || mode == "replace-only") pres.parentNode.removeChild(tmpres); } else if (pres.nodeName.toLowerCase == "img") { if (mode == "override" || mode == "replace-only") pres.parentNode.removeChild(pres); isexisting = 1; break; } else if (pres.nodeName.toLowerCase == "a" && pres.childNodes.length == 1 &&                           pres.childNodes[0].nodeName.toLowerCase == "img") { if (mode == "override" || mode == "replace-only") pres.parentNode.removeChild(pres); isexisting = 1; break; } else if ( (pres.nodeName.toLowerCase == "span" || pres.nodeName.toLowerCase == "big" || pres.nodeName.toLowerCase == "b") &&                           (itx == "\u2713" || itx == "\u2717" || itx == "ω") ) { if (mode == "override" || mode == "replace-only") pres.parentNode.removeChild(pres); isexisting = 1; break; } else if (pres.nodeName.toLowerCase == "span" && pres.style.display == "none") { pres = pres.previousSibling;  /* Ignore the hidden Y/N */ } else { break; };           };            if (isexisting) ifexists; if ( (mode == "replace-only" && isexisting) || (mode == "supplement" && !isexisting) || (mode == "override") ){ for (var y = 0; y < x.length; y += 1) { curs.insertBefore(x[y], curs.firstChild); };           };        } else { if ( typeof VOTESYMBOLS_SHOW_UNIDENTIFIED != "undefined" &&                VOTESYMBOLS_SHOW_UNIDENTIFIED ){ btc[i].insertBefore(document.createTextNode("(w) "), btc[i].firstChild); };       };    }; }); //