User:Acagastya/sanitaryCheck.js
Jump to navigation
Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
const sheet = (function() {
// Create the <style> tag
var style = document.createElement('style');
// WebKit hack
style.appendChild(document.createTextNode(''));
// Add the <style> element to the page
document.head.appendChild(style);
return style.sheet;
})();
(function sanitaryCheck() {
if(mw.config.get('wgNamespaceNumber') != 0) return; // only for mainspace
const div = [...document.getElementsByClassName('mw-parser-output')][0];
const input = document.createElement('input');
input.setAttribute('type', 'checkbox');
input.setAttribute('id', 'sanitary-check');
input.setAttribute('name', 'sanitary-check');
const label = document.createElement('label');
label.setAttribute('for', 'sanitary-check');
label.innerText = 'Sanitary check';
input.setAttribute(
'onchange',
`this.checked ? sheet.addRule('.mw-body-content p', 'font-family: "Comic Sans MS", fancy') : sheet.removeRule()`
);
// div.append(input);
// div.append(label);
div.parentElement.prepend(label);
div.parentElement.prepend(input);
})();