Jump to content

User:Nardog/DiffUndo

From Wikipedia, the free encyclopedia
DiffUndo
DescriptionAdds an undo button to each line on the diff while editing
UpdatedOctober 9, 2024
    (57 days ago)
BrowsersChrome, Firefox, etc. (ES2020+ needed)
SourceUser:Nardog/DiffUndo.js

This script adds an undo button to each line on the diff between the current version of the page and yours while editing ("Show changes"). Though inspired by a similar feature in AutoWikiBrowser, it also allows you to redo an undone change by clicking the button again.

It comes in handy especially when reverting edits. If you want to revert only part of an edit, you can click "undo" on page history or a diff and keep certain changes by undoing on the diff. If you want to revert an old edit but MediaWiki's native undo feature doesn't work because later edits interfere, you can go to the editing page of the previous revision, click "Show changes", and restore all the non-problematic edits by undoing the lines.

Installation

[edit]

Add the following to your common.js or global.js:

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Nardog/DiffUndo.js&action=raw&ctype=text/javascript');

Or you may enable the script installer in Preferences → Gadgets and click "Install" in the infobox on this page.

How it works

[edit]

You can undo a change as long as the line in the current source (deduced from the closest line number on the diff) matches the line in the "Your text" column of the diff. In case of a removed line (i.e. the cell in the "Your text" column is empty), the preceding line is compared. A redo works just like that except the columns are reversed.

Limitations

[edit]
  • Undoing a change may clear the browser's native undo cache (Ctrl+Z).
  • VisualEditor and the 2017 wikitext editor are not supported.