User:Michael von Preußen/wikia.js

/************************************************************************************
 * THE CONTENTS OF THIS FILE HAVE BEEN COMMENTED OUT!                       *****
 * To make use of this file, be sure to remove this notice, as well as the  *****
 * asterisk and slash at the end of the file.                               *****
 * Some of the contents of this file WILL NOT WORK when loaded into one's   *****
 * /wikia.js file. Furthermore, none of the contents will work on special   *****
 * pages or pages with an action such as edit, history, diff, or purge.     *****
 * For best results, load this script into a user JS file with access to the *****
 * jQuery library, place the load portions in a .ready container, and     *****
 * configure your browser to load the script. Examples of capable browsers  *****
 * include Opera (User JS), Chrome and Chromium (Extensions) and Firefox    *****
 * (Greasemonkey).                                                          *****
 * The jQuery library can be downloaded for use with this file from the     *****
 * jQuery website at .                                  *****
 * configure your browser to load the script. Examples of capable browsers  *****
 * include Opera (User JS), Chrome and Chromium (Extensions) and Firefox    *****
 * (Greasemonkey).                                                          *****
 * The jQuery library can be downloaded for use with this file from the     *****
 * jQuery website at .                                  *****
 * jQuery website at .                                  *****

// Add a watchlist link to the drop-down menu from username in top right var wtchlst = $('').attr('href','/wiki/Special:Watchlist').text('My watchlist').wrap(''); $('ul#AccountNavigation li ul.subnav li:nth-child(2)').after(wtchlst);

// Change the 'following' link to a 'watchlist' link on my userpage $('li[data-id="following"] a').attr('href','/wiki/Special:Watchlist').attr('title','Special:Watchlist').text('Watchlist');

// Automatically fix Wikipedia links that are appearing as external links $('a[href*="wikipedia.org/wiki/"].external.exitstitial').removeClass('external exitstitial').addClass('text');

// Make images link to the image page rather than the file itself $('a.image[href*="/clannad/"]').each(function { var url = $(this).attr('href').split('/');    url = url[url.length-1];     url = '/wiki/File:'+url; $(this).attr('href',url); });

// Stop popup $('a.image').click(function { location.href = $(this).attr('href'); });

// Wiki Activity --> RecentChanges $('a[data-id="wikiactivity"]').attr('href','/wiki/Special:RecentChanges').attr('title','Recent Changes').html(' Recent Changes');

// Remove Edit Link on Talk Archives $('#talk-archive').each(function{ $('.wikia-menu-button a[data-id="addtopic"] img').each(function{ $(this).addClass('sprite-small close').width('12').unbind('click'); // $(this).parent.parent.css({'background-color':'#444','border-color':'#444'}); var linktxt = $(this).parent.html.replace('Add topic','Archive'); $(this).parent.css({'font-style':'italic','cursor':'default','border':'none'}).html(linktxt).removeAttr('href').hover(function{ //  $(this).css('background-color','#444');  }); }); });

// Reverse title and text on lbs/st mass values $('.weight-title').each(function{ var wttl = $(this).attr('title'); var wtxt = $(this).text; $(this).attr('title',wtxt).text(wttl); });

// Show all language links and alphabetize $('nav.WikiaArticleInterlang li.more-link').remove; $('nav.WikiaArticleInterlang li.more').removeClass('more'); var langarr = []; $('nav.WikiaArticleInterlang').append(' '); $('nav.WikiaArticleInterlang li').each(function{	var iso = $('a',$(this)).attr('href').match(/\/\w{2}\./)[0].match(/\w{2}/)[0];	langarr.push(iso);	$(this).attr('id',iso).wrap(' '); }); langarr.sort; for(var i = 0;iedit]').css('float','right'); });

// Italicize appropriate article titles, and parts thereof $('#WikiaArticle :contains("'+wgTitle+'")').each(function{	if($(this).html === wgTitle) {		if($(this).css('font-style') === 'italic') {			$('#WikiaMainContent h1:first').css('font-style','italic');		}		return false;	} }); var regexp = /(Clannad(?! Wiki)( ~After Story~)?|Shining in the Sky|.+(?= \(song\)))/; if($('#WikiaMainContent h1:first').text.match(regexp)) { $('#WikiaMainContent h1:first').html($('#WikiaMainContent h1:first').text.replace(regexp,' '+$('#WikiaMainContent h1:first').text.match(regexp)[0]+' ')); }

// START OF AJAX AUTOREFRESH CODE

ajaxPages = ["Special:RecentChanges","Special:Watchlist"];

function setCookie(c_name,value,expiredays) { var exdate=new Date; exdate.setDate(exdate.getDate+expiredays); document.cookie=c_name+ "=" +escape(value) + ((expiredays===null) ? "" : ";expires="+exdate.toGMTString); }

function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) {c_end=document.cookie.length;} return unescape(document.cookie.substring(c_start,c_end)); } } return "" }

function getXmlHttpRequestObject { if (window.XMLHttpRequest) { return new XMLHttpRequest; //Not Internet Explorer } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); //Internet Explorer } else { //fail silently } } getRCDataRO = getXmlHttpRequestObject; var cr = new RegExp("\r", "gm"); var lf = new RegExp("\n", "gm"); var endText = new RegExp(' [\t\s]*? ', "mi"); var rcTimer; var rcRefresh = 60000; function preloadAJAXRC { ajaxRCCookie = (getCookie("ajaxload-"+wgPageName)=="on") ? true:false; document.getElementsByTagName("h2")[0].innerHTML += ' Automatically refresh '; document.getElementById("ajaxRCtoggle").checked = ajaxRCCookie; if (getCookie("ajaxload-"+wgPageName)=="on") { loadRCData; } }

function toggleRC { if (document.getElementById("ajaxRCtoggle").checked == true) { setCookie("ajaxload-"+wgPageName, "on", 30); loadRCData; } else { setCookie("ajaxload-"+wgPageName, "off", 30); clearTimeout(rcTimer); } }

function loadRCData { if (getRCDataRO.readyState == 4 || getRCDataRO.readyState == 0) { if (location.href.indexOf("/wiki/")) { rcURL = "http://" + location.hostname + "/wiki/" + wgPageName + location.search; } else { rcURL = "http://" + location.hostname + "/" + wgPageName + location.search; } getRCDataRO.open("GET", rcURL, true); getRCDataRO.onreadystatechange = parseRCdata; getRCDataRO.send(null); } }

function parseRCdata { if (getRCDataRO.readyState == 4) { rawRCdata = getRCDataRO.responseText.replace(cr, "").replace(lf, ""); filteredRCdata = rawRCdata.match(/ .*?<\/div>[\t\s]*? /i); //[\t\s]*?[\t\s]*? updatedText = filteredRCdata[0].replace(' ', "").replace(endText, ""); document.getElementById("WikiaArticle").innerHTML = updatedText; rcTimer = setTimeout(function{loadRCData;}, rcRefresh); } }

for (x in ajaxPages) { if (wgPageName == ajaxPages[x]) {addOnloadHook(preloadAJAXRC);} }

// END OF AJAX AUTOREFRESH CODE


 * / // REMOVE THIS LINE TO REMOVE COMMENT

/* PIKACHURIN: From here until the comment ends is the original, measurements-only code.

function setCookie(c_name,value,expiredays) { var exdate=new Date; exdate.setDate(exdate.getDate+expiredays); document.cookie=c_name+ "=" +escape(value) + ((expiredays===null) ? "" : ";expires="+exdate.toGMTString); }

function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) {c_end=document.cookie.length;} return unescape(document.cookie.substring(c_start,c_end)); } } return ""; }

function setup { var meas = getCookie('measurements'); if(meas !== null && meas !== "") { $('.measurements-selector input[value="'+meas+'"]').attr('checked','on'); $('.measurements').each(function{  $('.measurements-'+meas,$(this)).show;   $(this).hide;   $(this).parent.find('.measurements-container').text($('.measurements-'+meas,$(this)).text);  }); } }

$(function{ var measid = 0; $('.measurements-selector').each(function{ $(this).css('margin-left','-6px').html(' Metric  US Customary  Imperial'); $('input[name="measurements-selector-'+measid+'"]').change(function {  setCookie('measurements',$(this).val,'365');   setup;  }); measid++; }); $('.measurements').each(function{ $(this).before($(' ')); }); setup; });

$('#WikiaSearch input[name="search"]').attr('tabindex','1'); $('#WikiaSearch button.secondary').attr('tabindex','2');

function makeDate(fmt,fulldate) { if(fulldate.match(/[a-z]+, [0-9]+ [a-z]+ [0-9]{4}/gi)) { // dddd dd mmmm yyyy var day = fulldate.match(/[a-z]+/gi)[0], date = fulldate.match(/[0-9]+/)[0], month = fulldate.match(/[a-z]+/gi)[1], year = fulldate.match(/[0-9]{4}/)[0]; if(fmt === "dmy") { return day+", "+date+" "+month+" "+year; } else if(fmt === "mdy") { return day+", "+month+" "+date+", "+year; } else if(fmt === "ymd") { return year+" "+month+" "+date+" ("+day+")"; } } else if(fulldate.match(/[0-9]+ [a-z]+ [0-9]{4}/i)) { // dd mmmm yyyy var date = fulldate.match(/[0-9]+/)[0], month = fulldate.match(/[a-z]+/i)[0], year = fulldate.match(/[0-9]{4}/)[0]; if(fmt === "dmy") { return date+" "+month+" "+year; } else if(fmt === "mdy") { return month+" "+date+", "+year; } else if(fmt === "ymd") { return year+" "+month+" "+date; } } else if(fulldate.match(/[0-9]+ [a-z]+/i)) { // dd mmmm var date = fulldate.match(/[0-9]+/)[0], month = fulldate.match(/[a-z]+/i)[0]; if(fmt === "dmy") { return date+" "+month; } else if(fmt === "mdy" || fmt === "ymd") { return month+" "+date; } } else if(fulldate.match(/[a-z]+ [0-9]{4}/i)) { // mmmm yyyy var month = fulldate.match(/[a-z]+/i)[0], year = fulldate.match(/[0-9]{4}/)[0]; if(fmt === "dmy" || fmt === "mdy") { return month+" "+year; } else if(fmt === "ymd") { return year+" "+month; } } else { return fulldate; } }

function toDate(fmt) { var d = new Date, date = d.getDate, mname = ["January","February","March","April","May","June","July","August","September","October","November","December"], month = mname[d.getMonth], year = d.getFullYear; if(fmt === "dmy") { return date+" "+month+" "+year; } else if(fmt === "mdy") { return month+" "+date+", "+year; } else if(fmt === "ymd") { return year+" "+month+" "+date; } } function setCookie(c_name,value,expiredays) { var exdate=new Date; exdate.setDate(exdate.getDate+expiredays); document.cookie=c_name+ "=" +escape(value) + ((expiredays===null) ? "" : ";expires="+exdate.toGMTString); } function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) {c_end=document.cookie.length;} return unescape(document.cookie.substring(c_start,c_end)); } } return ""; } function msetup { var meas = getCookie('measurements'); if(meas !== null && meas !== "" && meas !== "label") { $('select[name="measurements-selector"] option[value="'+meas+'"]').attr('selected','selected'); $('.measurements').each(function{  $(this).hide;   $(this).parent.find('.measurements-container').text($('.measurements-'+meas,$(this)).text);  }); } else if(meas === "label") { $('.measurements').each(function{  $(this).parent.find('.measurements-container').empty;   $(this).show;  }); } } function dsetup { var dat = getCookie('dateformat'); if(dat !== null && dat !== "" && dat !== "label") { $('select[name="date-selector"] option[value="'+dat+'"]').attr('selected','selected'); $('.date').each(function{  $(this).hide;   $(this).parent.find('.date-container').text(makeDate(dat,$(this).text));  }); } else if(dat === "label") { $('.date').each(function{  $(this).parent.find('.date-container').empty;   $(this).show;  }); } } $(function{ $('section.WikiaPagesOnWikiModule').after('<section class="module" style="padding-top:8px;"><h1 style="margin:0 0 7px 0;">Display Options '); $('select[name="measurements-selector"]').bind('change keyup',function { setCookie('measurements',$(this).val,'365'); msetup; }); $('.measurements').each(function{ $(this).before($(' ')); }); msetup; $('select[name="date-selector"]').bind('change keyup',function { setCookie('dateformat',$(this).val,'365'); dsetup; }); $('.date').each(function{ $(this).before($(' ')); }); dsetup; });

// Fix Search $('#WikiaSearch').attr('action','/index.php?title=Special:Search'); $('#WikiaSearch input[name="fulltext"]').val('0');