User:BethNaught/exportUserOptions.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:BethNaught/exportUserOptions. |
/* global mw */
mw.loader.using(['mediawiki.user'], function () {
"use strict";
// List of options which will be not output in restricted mode. Add options containing personal data to this list.
// Testing! Not all options which should be here are.
var blacklist = ["watchlisttoken", "pagetriage-lastuse", "rcfilters-saved-queries", "rcfilters-wl-saved-queries"];
// Alternative whitelist-based system:
/**
var whitelist = ["monobook-responsive", "globaluserpage", "minordefault"];
*/
var config = mw.config.get(['wgNamespaceNumber', 'wgTitle', 'skin']);
function filterBlacklist(key, value) {
if (blacklist.includes(key)) {
return undefined;
} else {
return value;
}
}
function exportOptionsForm() {
var bodyContent = (config.skin === "cologneblue" ? "article" : "bodyContent");
document.getElementsByTagName("h1")[0].textContent = "Export user options";
document.title = "Export user options";
document.getElementById(bodyContent).innerHTML = '<div>' +
'<form id="wpExportUserOptions" name="wpExportUserOptions">' +
'<p>This page allows convenient export of your user preferences in JSON format.</p>' +
'<p>You can choose whether to export a restricted set of preferences (unlikely to contain personal data) or all preferences. ' +
'Before sharing the output of this page you should check that no data you do not wish to share is included.</p>' +
'<input type="radio" name="personalchoice" value="restricted" id="wpExportUserOptionsRadioRestricted" checked="true">' +
'<label for="wpExportUserOptionsRadioRestricted">Restricted</label>' +
'<br>' +
'<input type="radio" name="personalchoice" value="all" id="wpExportUserOptionsRadioAll">' +
'<label for="wpExportUserOptionsRadioAll">All</label>' +
'<br>' +
'<input type="submit" value="Export">' +
'</form>' +
'</div>' +
'<br><hr>' +
'<div id="wpExportUserOptionsOutput">' +
'<p>Output will appear here.</p>' +
'</div>';
document.getElementById("wpExportUserOptions").addEventListener("submit", function(f) {
f.preventDefault();
if (document.getElementById("wpExportUserOptionsRadioAll").checked) {
document.getElementById("wpExportUserOptionsOutput").innerHTML = '<pre>' +
JSON.stringify(mw.user.options.values, null, '\t') + '</pre>';
} else if (document.getElementById("wpExportUserOptionsRadioRestricted").checked) {
document.getElementById("wpExportUserOptionsOutput").innerHTML = '<pre>' +
JSON.stringify(mw.user.options.values, filterBlacklist, '\t') + '</pre>';
// Alternative whitelist-based system:
/**
document.getElementById("wpExportUserOptionsOutput").innerHTML = '<pre>' +
JSON.stringify(mw.user.options.values, whitelist, '\t') + '</pre>';
*/
}
});
}
if (config.wgNamespaceNumber === -1 &&
config.wgTitle.toLowerCase() === "exportuseroptions"
) {
exportOptionsForm();
}
});