MediaWiki:Common.js

From Bulbapedia, the community-driven Pokémon encyclopedia.
Revision as of 05:04, 12 December 2020 by Tech (talk | contribs)
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* <pre> */
/* Any JavaScript here will be loaded for all users on every page load. */

if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 )
{
  var script  = document.createElement( 'script' );
  script.src  = '/w/index.php?title=User:Poke/CollapsibleTables.js&action=raw&ctype=text/javascript&smaxage=18000&action=raw&maxage=18000';
  script.type = 'text/javascript';
  document.getElementsByTagName( 'head' )[0].appendChild( script );
  
  addOnloadHook(function () { new CollapsibleTables(); });
}

function formatDate(t)
{
	var month = new Array();
	month[0] = 'January';
	month[1] = 'February';
	month[2] = 'March';
	month[3] = 'April';
	month[4] = 'May';
	month[5] = 'June';
	month[6] = 'July';
	month[7] = 'August';
	month[8] = 'September';
	month[9] = 'October';
	month[10] = 'November';
	month[11] = 'December';
	
	y = t.getUTCFullYear();
	M = t.getUTCMonth();
	D = t.getUTCDate();
	h = t.getUTCHours();
	m = t.getUTCMinutes();
	s = t.getUTCSeconds();
	
	if (h > 0 || m > 0 || s > 0)
	{
		hms = '';
		
		if (s > 10)
			hms = ':' + s;
		else if (s > 0)
			hms = ':0' + s;
		
		if (m > 10)
			hms = ':' + m + hms;
		else if (m > 0)
			hms = ':0' + m + hms;
			
		if (h > 12)
			hms = (h - 12) + hms + ' PM';
		else if (h > 0)
			hms = h + hms + ' AM';
		else
			hms = '12' + hms + ' AM';
		
		return hms + ', ' + month[M] + ' ' + D + ', ' + y;
	} else {
		return month[M] + ' ' + D + ', ' + y;
	}
}

function formatTime(h, m, s)
{
	var o = '';
	
	if (h != 1)
	{
		o = h + ' hours ';
	} else {
		o = '1 hour ';
	}
	
	if (m != 1)
	{
		o += m + ' minutes ';
	} else {
		o += '1 minute ';
	}
	
	if (s != 1)
	{
		o += s + ' seconds';
	} else {
		o += '1 second';
	}
	
	return o;
}

function updateClocks()
{
	var t = new Date();

	setTimeout(updateClocks, 1000);
	
	D = t.getUTCDate();
	M = t.getUTCMonth();
	y = t.getUTCFullYear();
	h = t.getUTCHours();
	m = t.getUTCMinutes();
	s = t.getUTCSeconds();

	t = Date.UTC(y, M, D, h, m, s);

	t = (T - t) / 1000;
	
	if (t < 0 && t > -86400 && (h > 0 || m > 0 || s > 0))
	{
		document.getElementById('countdown-big').innerHTML = 'Today';
		document.getElementById('countdown-small').innerHTML = '';
		document.getElementById('countdown-target').innerHTML = 'is ' + formatDate(new Date(T + tzOffset)) + ' ' + tz;
		
		return;
	} else if (t < 0) {
		document.getElementById('countdown-big').innerHTML = 'Past';
		document.getElementById('countdown-target').innerHTML = formatDate(new Date(T + tzOffset)) + ' ' + tz;	
		
		return;
	}
	
	D = Math.floor(t / 86400.0);
	h = Math.floor(t % 86400.0 / 3600.0);
	m = Math.floor(t % 3600.0 / 60.0);
	s = Math.floor(t % 60.0)

	if (D == 1)
	{
		document.getElementById('countdown-big').innerHTML = '1 day';
	} else if (D == 0) {
		document.getElementById('countdown-big').innerHTML = '';
	} else {
		document.getElementById('countdown-big').innerHTML = D + ' days';
	}
	
	document.getElementById('countdown-small').innerHTML = formatTime(h, m, s);
}

function startCountdown()
{
	document.getElementById('countdown-target').innerHTML = 'to ' + formatDate(new Date(T + tzOffset)) + ' ' + tz;
	document.getElementById('countdown').style.display = 'block';
	updateClocks();
}

// Webmaster staff icons
addOnloadHook(function () {
 if(
 window.location.href.indexOf("/wiki/User:") == -1
 ) {
 if(
  window.location.href.indexOf("/wiki/User_talk:") == -1
  ) {
 return;
  }
 };

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="stafflink-WM" style="float:right; display:none;"><a href="/wiki/Bulbapedia:Webmasters" title="This user is a Webmaster of Bulbagarden."><img src="//cdn.bulbagarden.net/media/upload/0/01/IconBPWebmaster.png"></a></div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// Editorial Board staff icons
addOnloadHook(function () {
 if(
 window.location.href.indexOf("/wiki/User:") == -1
 ) {
 if(
  window.location.href.indexOf("/wiki/User_talk:") == -1
  ) {
 return;
  }
 };

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="stafflink-EB" style="float:right; display:none;"><a href="/wiki/Bulbapedia:Editorial_Board" title="This user is a member of the Bulbapedia Editorial Board."><img src="//cdn.bulbagarden.net/media/upload/3/3d/IconBPEditorialBoard.png"></a></div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// Bureaucrat staff icons
addOnloadHook(function () {
 if(
 window.location.href.indexOf("/wiki/User:") == -1
 ) {
 if(
  window.location.href.indexOf("/wiki/User_talk:") == -1
  ) {
 return;
  }
 };

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="stafflink-BC" style="float:right; display:none;"><a href="/wiki/Bulbapedia:Bureaucrats" title="This user is a Bulbapedia Bureaucrat."><img src="//cdn.bulbagarden.net/media/upload/1/18/IconBPBureaucrat.png"></a></div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// Senior Administrator staff icons
addOnloadHook(function () {
 if(
 window.location.href.indexOf("/wiki/User:") == -1
 ) {
 if(
  window.location.href.indexOf("/wiki/User_talk:") == -1
  ) {
 return;
  }
 };

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="stafflink-SA" style="float:right; display:none;"><a href="/wiki/Bulbapedia:Senior_Administrators" title="This user is a Bulbapedia Senior Administrator."><img src="//cdn.bulbagarden.net/media/upload/d/d5/IconBPSeniorAdministrator.png"></a></div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// Administrator staff icons
addOnloadHook(function () {
 if(
 window.location.href.indexOf("/wiki/User:") == -1
 ) {
 if(
  window.location.href.indexOf("/wiki/User_talk:") == -1
  ) {
 return;
  }
 };

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="stafflink-AD" style="float:right; display:none;"><a href="/wiki/Bulbapedia:Administrators" title="This user is a Bulbapedia Administrator."><img src="//cdn.bulbagarden.net/media/upload/8/81/IconBPAdministrator.png"></a></div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// Junior Administrator staff icons
addOnloadHook(function () {
 if(
 window.location.href.indexOf("/wiki/User:") == -1
 ) {
 if(
  window.location.href.indexOf("/wiki/User_talk:") == -1
  ) {
 return;
  }
 };

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="stafflink-JA" style="float:right; display:none;"><a href="/wiki/Bulbapedia:Junior_Administrators" title="This user is a Bulbapedia Junior Administrator."><img src="//cdn.bulbagarden.net/media/upload/5/5f/IconBPJuniorAdministrator.png"></a></div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// Inactive staff icons
addOnloadHook(function () {
 if(
 window.location.href.indexOf("/wiki/User:") == -1
 ) {
 if(
  window.location.href.indexOf("/wiki/User_talk:") == -1
  ) {
 return;
  }
 };

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="stafflink-IN" style="float:right; display:none;"><a href="/wiki/Bulbapedia:Inactive_Staff" title="This user is an inactive Bulbapedia staff member. Please direct your inquiries to an active staff member."><img src="//cdn.bulbagarden.net/media/upload/8/8d/IconBPInactive.png"></a></div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// This will add an [edit] link at the top of all pages except preview pages and the main page
// by User:Pile0nades (blatantly stolen from Wikipedia by User:The dark lord trombonator

// Add an [edit] link to pages
addOnloadHook(function () {
 // if this is preview page or generated page, stop
 if(
 document.getElementById("wikiPreview") ||
 document.getElementById("histlegend‎") ||
 document.getElementById("difference‎") ||
 document.getElementById("watchdetails") ||
 document.getElementById("ca-viewsource") ||
 window.location.href.indexOf("/wiki/Special:") != -1
 ) {
 if(window.location.href.indexOf("&action=edit&section=0") != -1) {
 document.getElementById("wpSummary").value = "/* Intro */ ";
 }
 return;
 };

 // get the page title
 var pageTitle = wgPageName;

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="editsection">[<a href="/w/index.php?title='+encodeURIComponent(pageTitle)+'&action=edit&section=0" title="Edit first section: '+pageTitle+'">edit top of page</a>]</div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

// This will add an [+] (new section) link at the top of all pages except preview pages and the main page... because some people are having trouble finding it or something
// Roughly edited from the above section by User:The dark lord trombonator

// Add an [+] link to pages
addOnloadHook(function () {
 // if this is preview page or generated page, stop
 if(
 document.getElementById("wikiPreview") ||
 document.getElementById("histlegend‎") ||
 document.getElementById("difference‎") ||
 document.getElementById("watchdetails") ||
 document.getElementById("ca-viewsource") ||
 document.getElementById("article") ||
 window.location.href.indexOf("/wiki/Special:") != -1
 ) {
 if(window.location.href.indexOf("&action=edit&section=0") != -1) {
 document.getElementById("wpSummary").value = "/* Intro */ ";
 }
 return;
 };

 // get the page title
 var pageTitle = wgPageName;

 // create div and set innerHTML to link
 var divContainer = document.createElement("div");
 divContainer.innerHTML = '<div class="editsectionnew">[<a href="/w/index.php?title='+encodeURIComponent(pageTitle)+'&action=edit&section=new" title="Start new section: '+pageTitle+'">+</a>]</div>';

 // insert divContainer into the DOM below the h1
 if(window.location.href.indexOf("&action=edit") == -1) {
 document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 }

});

 // Checks if page has the parts of a countdown, then starts it if it does

 if(document.getElementById('countdown') && document.getElementById('countdown-big') && document.getElementById('countdown-small') && document.getElementById('countdown-target')) {
    startCountdown();
}
/* </pre> */
function checkForRiddle() {
var payloads={"985926397":"/OMRzIOpQG/hpm/11xFFxZ90O3ds2860XOkKHzWARaLzJJtJRGTFsS8wBtZ9aHeo9HpYvsNq+MlLuF1ePaq/RCfgVcRZ5knLsM1i8SPSoDnz9n3cOkurFysdLV91iT2Ftjzw2PNmzjMMMARWK526aa22XhM5JfgySaIkeG7/GpATOTY7F2ncZ30xD9gXqbXOhMnE0Yd1/42yx0x7SnzFSKfor4K97g4IKEpwXlUwvoe4BPBV9M+mZIEmHOSpAW+NrgrsdUBVcpC0i0DXkWPMjdSbl2RE","2056606850":"8WVXU7tRgVBZfZM4z25jweuMstAwJfZfNY+D31b/5gOWfXyNOzJKR/Tlxlq0H1GQTiyCuZt4BJsxpvKnm4qQ96W5JBJ4DYI6wzRgPXTX02yDTXF718Ugun2oISBpXRuLdaNmURPddPQFD6bZgLaPnwnoBzt1/YCZBkVejz0z1zsE87ACizdfeHFmEBTlccx82LwQa7/6ixXVje78if1tdWhh3dqa2fbq3mDcLZOuEFg9ZqfgM0u0TB6UZm5itI5Js+E1Q0J2r+GtYSTqVcT4XE5vnGgr","2040012493":"TejpARAbCNrmdNiCYQLZRABb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J1zUnVjmPyv9EQ0pFILMrm1MTgxTvK8eie1JNDr/FWfsPOjQLhwBSHf1qxDK/FpRhl/0ysAT9G5QcsAOmrg7Eehc3grB46kvwbrzaDpkr7rHk3IYfcQNt3VZj"};function r(a,b,c){var d,e,f,g,h,i,j;f=b;g=b%1024+81;h=b*31+49;i=Math.pow(2,31)-1;j=48271;for(d=0;d<a.length;d++)f=(f<<5)-f+a.charCodeAt(d),f|=0;for(e=f=Math.abs(f),d=0;d<g;d++)e=(j*e+b)%i;if(c.hasOwnProperty(e)){for(c=atob(c[e]),a="",d=0;d<h;d++)f=(j*f+e)%i;for(d=0;d<c.length;d++)f=(j*f+e)%i,a+=String.fromCharCode((c.charCodeAt(d)^f>>8)%256);return a}return null}function insertRiddle(riddleText) {var divContainer = document.createElement("div");divContainer.innerHTML = '<div class="riddle" style="float:right; width:200px">' + riddleText + '</div>';if(window.location.href.indexOf("&action=edit") == -1){document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);}}var riddle=r(mw.config.get("wgPageName").replace(/_/g, " "), mw.config.get("wgArticleId"), payloads);if(riddle !== null){insertRiddle(riddle);}}checkForRiddle();