User:Suffusion of Yellow/AnonSettings.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.
// DO NOT INSTALL THIS IN YOUR common.js!
(function() {
	if (!("serviceWorker" in navigator)) {
		alert("Unsupported browser or settings.");
		return;
	}

	if (window.location.host !== "en.wikipedia.org") {
		alert("AnonSettings is only supported on the English Wikipedia desktop site.");
		return;
	}

	if (mw.config.get('wgUserId') !== null) {
		alert("AnonSettings is not intended for logged-in use. Please log out.");
		return;
	}

	if (!confirm("You are about to install AnonSettings. This script is experimental and may disrupt your ability to use this site. It is not recommended for logged-in use. Be sure you have read the uninstallation instructions."))
		return;

	navigator.serviceWorker.register("/?title=User:Suffusion_of_Yellow/AnonSettings/sw.js&action=raw&ctype=text/javascript")
		.then(() => {
			mw.notify("AnonSettings installed. Redirecting to configuration page...");
			setTimeout(() => window.location = "/wiki/User:Suffusion_of_Yellow/AnonSettings/Setup", 3000);
		})
		.catch(e => alert("AnonSettings setup failed: " + e));

})();
// DO NOT INSTALL THIS IN YOUR common.js!