User:Suffusion of Yellow/AnonSettings/config.js

// DO NOT INSTALL THIS IN YOUR common.js! (function {	function uninstall {		navigator.serviceWorker.getRegistrations			.then(regs => regs.forEach(reg => reg.unregister.then( => window.location = "/")));	}

function update { let settings = { skin : document.getElementById('anonsettings-skin').value, lang : document.getElementById('anonsettings-lang').value, gadget : document.getElementById('anonsettings-gadget').value, nologin : document.getElementById('anonsettings-nologin').checked };		navigator.serviceWorker.controller.postMessage({ settings });

window.location.reload; }

function setup(r) { if (r.query.userinfo.id !== 0) { document.getElementById("anonsettings-status").textContent = "Whoa there! You seem to be logged in! You probably want to uninstall this, and change your preferences instead."; } else document.getElementById("anonsettings-status").textContent = "Welcome non-logged-in user!";

let skinSelect = document.getElementById("anonsettings-skin"); for(let item of r.query.skins) if (!item.unusable) { let option = document.createElement("option"); option.value = item.code; option.textContent = item.name; skinSelect.appendChild(option); }		let langSelect = document.getElementById("anonsettings-lang"); for(let item of r.query.languages) { let option = document.createElement("option"); option.value = item.code; option.textContent = item.code + " - " + item.name; langSelect.appendChild(option); }		let gadgetSelect = document.getElementById("anonsettings-gadget"); for(let item of r.query.gadgets) if (item.metadata.settings.supportsUrlLoad && !item.metadata.settings.hidden && !item.metadata.settings.default) { let option = document.createElement("option"); option.value = item.id; option.textContent = item.id; gadgetSelect.appendChild(option); }

let settings = ANON_SETTINGS;

if (settings.skin) document.getElementById('anonsettings-skin').value = settings.skin; if (settings.lang) document.getElementById('anonsettings-lang').value = settings.lang; if (settings.gadget) document.getElementById('anonsettings-gadget').value = settings.gadget;

document.getElementById('anonsettings-nologin').checked = settings.nologin;

document.getElementById('anonsettings-settings').style = "display:block;"; document.getElementById('anonsettings-uninstall') .addEventListener('click', uninstall);

document.getElementById('anonsettings-save') .addEventListener('click', update);

}

document.title = "AnonSettings setup"; (document.getElementById("content") || document.body).innerHTML = ` AnonSettings setup Fetching site information...      Uninstall Uninstall AnonSettings Settings  (default) Skin  (default) qqx - (system messages) Interface language  (none) Gadget  Automatically uninstall on attempted login (recommended) Save settings `;

fetch("/w/api.php?action=query&list=gadgets&meta=userinfo|siteinfo&siprop=skins|languages&format=json&formatversion=2") .then(r => r.json) .then(setup); }); // DO NOT INSTALL THIS IN YOUR common.js!