User:Beep21/global.js

// COPIERS: If you wish to copy any of the scripts found here, copy the entire text between the empty lines. Do not forget to have the script run. To do this add a newline with the name of the function from the first line between "$(" and ")" after the rest of the script. For example, if the first line is the following, // function bpHello // then you should add the following at the end. // $(bpHello)

// check "Watch this page" when necessary // by Wikia user "Beep21" function bpWatchifnecessary { if (wgAction == "edit") {   if (wgNamespaceNumber == 110) {     bpWatch }    else if (wgNamespaceNumber / 2 == Math.floor(wgNamespaceNumber / 2) && wgCurRevisionId == false) {      bpWatch }    else if (wgNamespaceNumber / 2 != Math.floor(wgNamespaceNumber / 2)) {      bpWatch }  }  if (wgPageName == "Special:Upload") {   bpWatch } } function bpWatch { $("#wpWatchthis").attr("checked","checked") } function bpWatchifunanswered(bpData) { if(!$(bpData).find("error").length && !$(bpData).find("api query pages page categories").length) {   $(bpWatch) } } if(skin == "answers" && wgAction == "edit") { $.ajax({data:"action=query&pageids=" + encodeURIComponent(wgArticleId) + "&prop=categories&clcategories=Category:" + encodeURIComponent(wgAnsweredCategory) + "&format=xml&maxlag=5",success:bpWatchifunanswered,timeout:20000,url:wgServer + "/api.php"}) }

// change the "More" link in the "Latest activity" widget to go to the Recent changes // by Wikia user "Beep21" function bpLatestactmorechange { if(skin == "monaco") {   $("#community-widget-action-button").attr("href",wgServer + "/wiki/Special:RecentChanges") } }

// make the sidebar smaller by removing Wiki page in Widgets that do not have pages // by Wikia user "Beep21" // based on a script by Wikia users "Najevi" and "Uberfuzzy" found at  used with permission function bpSmsidebar { $('.WidgetWikiPage .widget-error-wikipage-missing').closest('dd').parent('dl').hide }

// fix up search results on answers // This does not work well. // To be used with a style at "User:Beep21/global.css" // by Wikia user "Beep21" var bpSearchresults = [] var bpData__ function bpAnswersearch { if(skin == "answers" && wgCanonicalSpecialPageName == "Search") {   $(".mw-search-results li").each(bpListresults) $.ajax({data:"action=query&titles=" + bpSearchresults.join("|") + "&prop=categories&clcategories=Category:" + encodeURIComponent(wgAnsweredCategory) + "|Category:" + encodeURIComponent(wgUnAnsweredCategory) + "&format=xml&maxlag=5",success:bpChecksearchresults,timeout:20000,url:wgServer + "/api.php"}) } } function bpListresults(bpNone,bpResultcontainer) { bpSearchresults[bpSearchresults.length] = encodeURIComponent($(bpResultcontainer).find(".mw-search-result-title").text) } function bpChecksearchresults(bpData) { if(!$(bpData).find("error").length) {   bpData__ = bpData $(".mw-search-results li").each(bpCorrectresults) } } function bpCorrectresults(bpNone,bpElement) { $(bpElement).find(".mw-search-result-title").wrap($(document.createElement("div")).addClass("bpSearchfirstline")) if($(bpData__).find("api query pages page[title=\"" + $(bpElement).find(".mw-search-result-title").text + "\"] categories cl[title=\"Category:" + wgUnAnsweredCategory + "\"]").length) {   $(bpElement).find(".bpSearchfirstline").addClass("bpSearchquestionline").append(" &mdash;  Unanswered ").find(".mw-search-result-title").html("" + $(bpElement).find(".mw-search-result-title").html + " ? ") $(bpElement).find(".searchresult").hide }  else if($(bpData__).find("api query pages page[title=\"" + $(bpElement).find(".mw-search-result-title").text + "\"] categories cl[title=\"Category:" + wgAnsweredCategory + "\"]").length) {    $(bpElement).find(".bpSearchfirstline").addClass("bpSearchquestionline").append(" &mdash;  Answered ").find(".mw-search-result-title").html("" + $(bpElement).find(".mw-search-result-title").html + " ? ") }  else {    $(bpElement).find(".bpSearchfirstline").append(" &mdash;  Not a question ") } }

// do not load pages from autocreated wikis if(wgDBname != "wikiaglobal" && wgDBname != "thedailyedit") { $.ajax({success:bpStopautocreatedwikis,url:wgServer + "/api.php?action=query&titles=" + encodeURIComponent(wgMainpage) + "&prop=revisions&rvlimit=1&rvdir=newer&format=xml"}) } function bpStopautocreatedwikis(bpData) { if(new Date($(bpData).find("api query pages page revisions rev").attr("timestamp")) > new Date("2009-03-25T15:51:35Z")) {   location.assign("http://community.wikia.com/wiki/Community_Central:Not_a_valid_Wikia#wikia_corporate_footer") } }

//run the above functions on DOM ready function bpOnload { bpWatchifnecessary bpSmsidebar bpLatestactmorechange bpAnswersearch } $(bpOnload)