İçeriğe atla

MediaWiki:Gadget-QuickUndo.js

Deltarune Wiki sitesinden

Not: Yayımladıktan sonra değişiklikleri görmeniz için tarayıcınızın önbelleğini temizlemeniz gerekebilir.

  • Firefox / Safari: Shift tuşuna basılıyken Yeniden Yükle'ye tıklayın ya da Ctrl-F5 ya da Ctrl-R tıklayın (Mac için ⌘-R)
  • Google Chrome: Ctrl-Shift-R'ye basın. (Mac için ⌘-Shift-R)
  • Edge: Ctrl basılıyken Yenile'ye tıklayın ya da Ctrl-F5'e basın.
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');
});
Konu ekle