User:Bobogoobo/wikia.js

// wish list: //*Maybe (not really necessary): hide blogs and comments in RC with some option (query string?) to show them, so I don't waste time with that stuff //*put a ?action=edit&section=0 link somewhere in the page header. The removal of that is one of the most annoying things. //*Re-collapse things like the user avatar log on RecentChanges //*fix file usage links - subpages don't get put on the link //*tons more to do with API stuff //*Etc. :P

// http://dev.wikia.com/wiki/RevealAnonIP importArticles({   type: "script",    articles: [        "w:c:dev:RevealAnonIP/usercode.js"    ] });

// Disable redirects when visiting from special pages if (wgCanonicalNamespace == "Special" && wgTitle != "ListRedirects") { $("[class*='redirect'] a").each(function{   var asdf = $(this).attr("href");    $(this).attr("href", asdf + "?redirect=no");  }); }

// Keep Maintenance reports columns somewhat sorted if (wgPageName == "Special:SpecialPages") { $('a[title="Special:UncategorizedCategories"]').parent.prependTo($("table.mw-specialpages-table:eq(0) td:eq(2) ul")); }

// Swap collapsed states on RecentChanges if (wgPageName == "Special:RecentChanges") { var collapsedOnes = $('[class="mw-collapsible-toggle mw-collapsible-toggle-collapsed"]'); $('[class="mw-collapsible-toggle"]').addClass("mw-collapsible-toggle-collapsed"); collapsedOnes.removeClass("mw-collapsible-toggle-collapsed"); }

// Disable autoplay on all embedded YouTube videos // (works on both user pages and file pages) $("iframe[src^='http://www.youtube.com']").each(function{ var source = $(this).attr("src");  if (source.indexOf("autoplay=1") != -1) {    $(this).attr("src", source.replace("autoplay=1", "autoplay=0"));  } });

//Make the author displayed for a comment in lists of file links actually // say the author, not the last editor (darn it Wikia) // (and replace underscores with spaces in the page name too while I'm here) if (wgCanonicalNamespace == "File") { $("ul.mw-imagepage-linkstoimage li a:first-child").each(function{   var href = $(this).attr("href");    if (href.indexOf("/@comment-") != -1) {      var authorstart = href.lastIndexOf("/@comment-") + 10;      var authorend = href.lastIndexOf("-");      var author = href.substring(authorstart, authorend).replace(/_/g, " ");      $(this).html($(this).html.substring(0, 13) + decodeURIComponent(author));    }  }); $("ul.mw-imagepage-linkstoimage li a:last-child").each(function{   $(this).html($(this).html.replace(/_/g, " "));  }); }

//Make document titles more concise (I get under ten characters with my tab width) var titleHead = document.title.substring(0, 8); var titleTail = document.title.substring(8); switch (titleHead) { case "Editing ": titleHead = "e."; break; case "Image - ": titleHead = "f."; break; case "Video - ": titleHead = "v."; break; case "Revision": if (document.title.length > 21 && document.title.indexOf("\"") != -1) {     titleHead = document.title.substring(0, 21);      titleTail = document.title.substring(21, document.title.lastIndexOf("\"")); }   if (titleHead == "Revision history of \"") { titleHead = "h."; }    break; } if (titleHead.length < 8) {  document.title = titleHead + titleTail; }

//Convenience for deleting pages if (document.URL.indexOf("action=delete") != -1) { document.getElementById("wpReason").focus; $("#wpDeleteReasonList option").click(function{   document.getElementById("wpReason").focus;  }); }

//This thing keeps tricking me if (wgCanonicalNamespace == "File") { $("a#ca-replace-file").html("Reupload"); }

//Display contribution count for anonymous users! // Plus a deleted contributions count for everyone // (requires being a member of a group with the right to view deleted contributions) //Bug me to make it a Gadget if you like, but I think making it common would be against the ToU. //To do: //   improve formatting based on what other elements of the masthead are present (at that point, it's going on dev :P), //   code the padding for if delcon is longer than actual contribs (got other stuff to do atm) (make it a function?) //   test it all with non-admin account (function{   var username = $("h1[itemprop='name']").html; var contribs = 0;

if ($(".masthead-info").length) { $(' ' +        '  ').insertAfter("div.masthead-info-lower .tally"); } //reserve space while ajax does its thing

if ($("div.masthead-info h2:first").html == " aka A Wikia Contributor") { var editString = "edits"; $.getJSON("/api.php?action=query&list=usercontribs&ucuser=" + username +        "&uclimit=5000&format=json", function(response){            contribs = response.query.usercontribs.length;            if (contribs == 5000) {                contribs = "5000+";            } else if (contribs == 1) {                editString = "edit";            }            $("div.masthead-info-lower .tally:first").html(" " + contribs + " " + editString + " from this IP ");           delcontribs;        }); } else { delcontribs; } function delcontribs{ var contribString = "contributions", padding = ""; contribs = 0; if ($(".masthead-info").length) { $.getJSON("/api.php?action=query&list=deletedrevs&druser=" + username +        "&drlimit=5000&format=json", function(response){

if (response.error) { return; } // if no access, blow this popsicle stand

response = response.query.deletedrevs; for (revisionset in response) { contribs += revisionset[0].length; }

if (contribs == 5000) { //could also just check for a continue value contribs = "5,000+"; } else if (contribs == 1) { contribString = "contribution"; } else if (contribs > 999) { contribs = contribs.toString; var overDigits = contribs.length - 3; // if anyone has 1mil deleted contribs...tell me (and call for help) contribs = contribs.substr(0, overDigits) + ',' + contribs.substr(overDigits); }           contribs = contribs.toString; //do in any case

var Contribs = $("div.masthead-info-lower .tally:first em").html; for (var i = 0; i < Contribs.length - contribs.length; i++) { padding += "0"; }           if (Contribs.indexOf(",") != -1 && contribs.indexOf(",") == -1) { padding = padding.replace("0", ",").split("").reverse.join(""); //OCD } //again the million contribs thing if (padding != "") { padding = ' ' + padding + ' '; }

$("div.masthead-info-lower .tally:last").html(' ' + padding +            contribs + ' deleted ' + contribString + '  '); });       $("div.masthead-info-lower .tally:last em").each(function{ if ($(this).html == " ") { $(this).remove; //well this is annoying and also bad }       });    }} });