User:Azu-nyan/wikia.js

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{ try { $('section.WikiaPagesOnWikiModule').after('Display Options '); } catch(err) {alert(err);} $('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; });