Difference between revisions of "MediaWiki:Common.js"

From SgWiki
Jump to navigation Jump to search
m
m
Line 46: Line 46:
/* GE Elections */
/* GE Elections */
try {
try {
console.log($('#n-mainpage-description').length);
$('#n-mainpage-description').after("<li id='n-election'><a href='/wiki/2020_General_Election' title='General Election 2020'>GE2020</a></li>");
$('#n-mainpage-description').after("<li id='n-election'><a href='/wiki/2020_General_Election' title='General Election 2020'>GE2020</a></li>");
} catch (e) {};
} catch (e) {};

Revision as of 16:08, 4 July 2020

/* Any JavaScript here will be loaded for all users on every page load. */

try {
var d = new Date();
var hour = d.getHours();
if (hour <= 4) { d.setTime(d.getTime() - 7200000); }

var x = ('00' + d.getDate()).substr(-2) + ('00' + (d.getMonth() + 1)).substr(-2) + ('00' + d.getFullYear()).substr(-2);

$('span.Advisory,td.Advisory,th.Advisory').each(function () {
	if (!$(this).hasClass(x)) {
		if (($(this).hasClass('train') || $(this).hasClass('event')) && !$(this).hasClass('not')) $(this).remove();
	} else {
		if (($(this).hasClass('train') || $(this).hasClass('event')) && $(this).hasClass('not')) $(this).remove();
	};
})
if ($('table#TravelAdvisory span.showonly').length != 0 || $('table#TravelAdvisory').hasClass('partial')) $('table#TravelAdvisory span.Advisory:not(.showonly)').remove();
$('span.Advisory:last-of-type').find('hr').remove();
if ($('table#TravelAdvisory span.Advisory').length == 0) $('table#TravelAdvisory').remove();
$('table#TravelAdvisory u>span').html(' (' + d.getDate() + '/' + (d.getMonth() + 1) + '/' + d.getFullYear() + ')');
} catch (e) {};

/* Custom Auto Redirect */
try {
if ($('#mw-content-text span.redirect').length == 1 && $('table.diff').length == 0) setTimeout(function () { location.href = $('#mw-content-text span.redirect a').attr('href'); }, 5000); //auto-redirect in 5s
} catch (e) {};

/* Infobox */
try {
if ($('.infobox tr:first-of-type img').length == 0) $('.infobox .img-alt').remove();
} catch (e) {};

/*Partial Hide*/
try {
$('.exc').on('click', function () { $(this).nextUntil('.exc').find('.ex').toggle(); })
$('.ex').hide();
} catch (e) {};

/*Hidden Removal*/
try {
$('.hide').remove();
if ($('#mw-content-text>p:first-child').html().indexOf('<br>') === 0) $('#mw-content-text>p:first-child').remove();
} catch (e) {};

/* Customised sgWiki Theme */
/* GE Elections */
try {
$('#n-mainpage-description').after("<li id='n-election'><a href='/wiki/2020_General_Election' title='General Election 2020'>GE2020</a></li>");
} catch (e) {};

/*Christmas
if (d.getMinutes() >= 0 && d.getMinutes() <= 10) $('div#bodyContent').append('<div id="snowflakes"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div>');*/