Jump to content

User:Zcricket01/common.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*** BEGIN WIKIBREAK ENFORCER ***/
(function() {

    /*** Start editing here ***/
    // When you want to end your break?
	// no leading zeroes. (example: 9 - correct, 09 - incorrect)
	// Set your break end date and time (UTC) below
    var date = { year: 2025, month: 5, day: 17 };
    var time = { hours: 04, minutes: 51, seconds: 0 };
    /*** Stop editing here ***/

    // Combine into a UTC Date object
    var breakEnd = new Date(Date.UTC(
        date.year,
        date.month - 1, 
        date.day,
        time.hours,
        time.minutes,
        time.seconds
    ));

    // Fetch server time from MediaWiki API
    $.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) {
            // Format dates for readability
            var options = {
                weekday: 'long', year: 'numeric', month: 'long',
                day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit',
                timeZone: 'UTC', timeZoneName: 'short'
            };
            var breakEndStr = breakEnd.toLocaleString(undefined, options);
            var serverTimeStrFormatted = serverTime.toLocaleString(undefined, options);

            alert(
                "🚫 Wikibreak in effect! 🚫\n\n" +
                "You are on a break until:\n" + breakEndStr +
                "\n\nCurrent Wikipedia server time:\n" + serverTimeStrFormatted +
                "\n\nYou will now be logged out."
            );

            mw.loader.using(["mediawiki.api", "mediawiki.user"]).then(function () {
                new mw.Api().post({
                    action: 'logout',
                    token: mw.user.tokens.get('csrfToken')
                }).done(function () {
                    location = "//" + location.host + "/w/index.php?title=Special:Userlogin&returnto=Main_Page";
                });
            });
        }
    });
})();
/*** END WIKIBREAK ENFORCER ***/