Set the cookies and automatically refresh the page, once.

This allows the user to enable the April Fools mode, if they want.
@run-at document-start, so TM & VM users don't need to wait for the
page to load for the auto-refresh.
Change to using vanilla JavaScript, as Greasemonkey 4 doesn't obey
any @run-at settings and will have this run anywhere from
document-start (i.e. prior to jQuery loading) to document-end.
This commit is contained in:
Makyen 2019-03-31 15:19:53 -07:00
parent 748f595aac
commit 0df8a88318

View file

@ -11,6 +11,7 @@
// @match *://*.serverfault.com/*
// @match *://*.askubuntu.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @exclude *://api.stackexchange.com/*
// @exclude *://blog.*.com/*
// @exclude *://chat.*.com/*
@ -18,12 +19,22 @@
// @exclude *://elections.stackexchange.com/*
// @exclude *://openid.stackexchange.com/*
// @exclude *://stackexchange.com/*
// @run-at document-start
// @grant none
// @version 0.2
// @version 0.3
// ==/UserScript==
(function () {
"use strict";
$.cookie("tm2019", "1", { expires: 2, path: '/' });
$.cookie("tm2019d", "1", { expires: 2, path: '/' });
if (Date.now() < 1554335999000) {
//Don't do anything if April Fools 2019 is past.
if (document.cookie.indexOf('glorObeyUserPref') === -1 && (document.cookie.indexOf('tm2019') === -1 || document.cookie.indexOf('tm2019d') === -1)) {
//We only want to set these once, so the user can turn the 2019 April Fools theme on for a site, if they want.
//Using a cookie for our own flag automatically cleans up for us after April Fools Day.
document.cookie = 'glorObeyUserPref=1;path=/;expires=Wed, 03 Apr 2019 23:59:59 GMT';
document.cookie = 'tm2019=1;path=/;expires=Wed, 03 Apr 2019 23:59:59 GMT';
document.cookie = 'tm2019d=1;path=/;expires=Wed, 03 Apr 2019 23:59:59 GMT';
window.location.reload(false);
}
}
})()