User:Polygnotus/Scripts/WikiTypoInterface.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:Polygnotus/Scripts/WikiTypoInterface. |
(function() {
function removeElements() {
const elementsToRemove = [
'#mw-head', '#mw-page-base', '#mw-panel',
'#editpage-specialchars', '#mw-userconfigdangerous', '.editpage-head-copywarn'
];
elementsToRemove.forEach(selector => {
const element = document.querySelector(selector);
if (element) element.remove();
});
}
function addCustomCSS() {
const style = document.createElement('style');
style.textContent = `
body {
padding-top: 0 !important;
}
.mw-body {
margin-left: 0 !important;
padding-top: 0 !important;
}
#content {
margin-top: 0 !important;
}
#bodyContent {
margin-top: 1em;
}
#custom-top-buttons {
margin-bottom: 15px;
}
#custom-top-buttons .oo-ui-buttonElement {
margin-right: 8px;
}
`;
document.head.appendChild(style);
}
function addCustomButtons() {
const buttonContainer = document.createElement('div');
buttonContainer.id = 'custom-top-buttons';
buttonContainer.className = 'editButtons';
const buttons = [
{ text: 'Publish changes', id: 'wpSave', className: 'oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-flaggedElement-primary oo-ui-buttonInputWidget' },
{ text: 'Show preview', id: 'wpPreview', className: 'oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget' },
{ text: 'Show changes', id: 'wpDiff', className: 'oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget' }
];
buttons.forEach(btn => {
const buttonSpan = document.createElement('span');
buttonSpan.className = btn.className;
const button = document.createElement('input');
button.type = 'button';
button.value = btn.text;
button.className = 'oo-ui-inputWidget-input oo-ui-buttonElement-button';
button.addEventListener('click', () => {
document.getElementById(btn.id).click();
});
buttonSpan.appendChild(button);
buttonContainer.appendChild(buttonSpan);
});
const bodyContent = document.getElementById('bodyContent');
const currentAction = mw.config.get('wgAction');
if (['edit', 'submit', 'diff'].includes(currentAction) && bodyContent) {
bodyContent.insertBefore(buttonContainer, bodyContent.firstChild);
}
}
function init() {
removeElements();
addCustomCSS();
addCustomButtons();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();