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 //*tons more to do with API stuff //*Something that can be enabled globally for a wiki and fixes edit summaries // and post-edit positioning when editing sections that are duplicate headings. //*Figure out how best to order this and other best practices //*Etc. :P

importArticles({   type: "script",    articles: [        "w:dev:RevealAnonIP/usercode.js", // http://dev.wikia.com/wiki/RevealAnonIP        "l:User:Bobogoobo/OldFilePages.js" // http://mlp.wikia.com/wiki/User:Bobogoobo/OldFilePages.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"); }

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

//Convenience for deleting pages //todo: make it stop getting interrupted by other loading if (document.URL.indexOf("action=delete") != -1) { document.getElementById("wpReason").focus; $("#wpDeleteReasonList option").click(function{   document.getElementById("wpReason").focus;  }); }

//Add "show bots only" link on RecentChanges //todo: change the link and href (before adding it) if already showing this // - should retain limit if present but remove the rest // (clicking links puts their queries at the beginning, so I'll just ignore them) if (wgPageName == "Special:RecentChanges") { $('fieldset.rcoptions br:first').before(' | ' +       'Show bots only'); if (window.location.search.indexOf('hidebots=&hideanons=1&hideliu=1') != -1) { $('#botsonly').css('font-weight', 'bold'); } }

//Make redlinked user talk pages link to the page, not editing it $('a.new').each(function {   if ($(this).attr('title').substring(0, 10) == "User talk:") {        var t_href = $(this).attr('href');        $(this).attr('href', t_href.substring(0, t_href.indexOf('?')));    } });

//Add a tab linking to a user's Editcount page next to Contributions if ($('.masthead-info').length && !($('div.masthead-info h2:first').html == " aka A Wikia Contributor")) { var username = $('h1[itemprop="name"]').html; $('ul.tabs').append('Editcount'); }

// Disable autoplay on embedded YouTube videos if (wgNamespaceNumber == 2 || wgNamespaceNumber == 3) { //user 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"));        }    }); } else if (wgNamespaceNumber == 6) { //file pages //Alternate method: http://mlp.wikia.com/wiki/User:C%C3%A5m/wikia.js?oldid=806383 if (window.location.search.indexOf("keepplayer=1") == -1) { $("iframe[src^='http://www.youtube.com']").remove; if ($('.video-page-caption p:last a').html == "Youtube") { $('.fullImageLink').html('Click to reload' +               ' with video').css('padding', '2em'); }       //There shouldn't already be a query string on a file page, right? } }

//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;  default:    if (titleHead.substring(0, 6) == "Forum:") {      titleHead = "F:";      titleTail = document.title.substring(6);    }    break; } if (titleHead.length < 8) {  document.title = titleHead + titleTail; }

//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 //   could make it apply to all user pages, so that on registered accounts it gets the live value rather than cached :P //   need to find out how to get dynamic element width - for example, 12131 and 683 can't be lined up exactly. (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) { $(".masthead-info-lower .tally:last").remove; return; } // if no access, blow this popsicle stand

response = response.query.deletedrevs; for (var 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(""); //last part for OCD } //again the million contribs thing for (var i = 0; i < (Contribs.match(/1/g) || []).length -              (contribs.match(/1/g) || []).length; i++) { padding = padding.replace('0', '1'); // need to do this part the other way around too }           if (padding != "") { padding = ' ' + padding + ' '; }

$("div.masthead-info-lower .tally:last").html(' ' + padding +              contribs + ' deleted ' + contribString + '  '); });   }} });