MediaWiki:Gadget-QuickUndo.js
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
function undoEdit(event) {
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
return;
}
event.preventDefault();
const url = new URL(event.currentTarget.href);
const undo = url.searchParams.get('undo');
const undoafter = url.searchParams.get('undoafter');
const editPath = mw.config.get('wgActionPaths').edit.replace('$1', '');
const title = decodeURIComponent(url.pathname.replace(editPath, ''));
OO.ui.prompt('Provide your undo summary, or leave blank to use default.').then(summary => {
if (summary === null) {
return;
}
summary = summary || undefined;
(new mw.Api()).postWithToken('csrf', {
action: 'edit',
title,
undo,
undoafter,
bot: true,
summary,
tags: ['quickundo']
}).then(data => {
if (data.edit.result === 'Success') {
mw.notify('Undo successful!', {
type: 'success'
});
} else {
mw.notify('Undo failed! Result: ' + data.edit.result, {
type: 'error'
});
}
}).fail(code => {
mw.notify('Undo failed! Error code: ' + code, {
type: 'error'
});
});
});
}
function addListenerToSelector(selector) {
for (const element of document.querySelectorAll(selector)) {
element.addEventListener('click', undoEdit);
}
}
addListenerToSelector('.mw-diff-undo a, .mw-history-undo a');
mw.hook('quickdiff.ready').add(() => {
addListenerToSelector('#quickdiff-modal .mw-diff-undo a');
});