Jump to content

Wikipedia:WikiProject User scripts/Scripts/WikiBreak Enforcer/script.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 19:55, 18 May 2025 (Use server time rather than local time per request). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
/*** BEGIN WIKIBREAK ENFORCER ***/
$(document).ready(function() 
{

	/*** Start editing here ***/

	// When you want to end your break?
	// no leading zeroes. (example: 9 - correct, 09 - incorrect)

	var date = { year: 2020, month: 2, day: 11};
	var time = { hours: 20, minutes: 22, seconds: 0 };

	/*** Stop editing here ***/
	
	var currentDate = new Date();
	var enforcedBreakEnd = new Date(
		date.year,date.month-1,date.day,time.hours,time.minutes,time.seconds);
	$.getJSON("/w/api.php?action=query&meta=siteinfo&siprop=general&format=json", function(data) {
        var serverTimeStr = data.query.general.time; // ISO 8601 string
        var serverTime = new Date(serverTimeStr);

        if (serverTime < breakEnd) {
			alert("Enforced wikibreak until "+enforcedBreakEnd.toLocaleString()
				+ "\n(now is "+currentDate.toLocaleString()+")\n\nBye!");
			mw.loader.using(["mediawiki.api", "mediawiki.user"]).then(function ()
			{
				new mw.Api().post(
				{
					action: 'logout',
					token: mw.user.tokens.get('csrfToken')
				}).done(function (data)
				{
					location = "//" + location.host + "/w/index.php?title="
						 + "Special:Userlogin&returnto=Main_Page";
				}).fail(function ()
				{
					console.log("logout failed");
				});
			});
        }
	});
});
/*** END WIKIBREAK ENFORCER ***/