MediaWiki:Gadget-CleanDiffURLs.js

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
(function () {
  setTimeout(function () { // Timeout to remove "&diffmode=source" which is added later
    var url = new URL(window.location.href)
    var oldid = url.searchParams.get("oldid")
    var diff = url.searchParams.get("diff")
    var hash = window.location.hash.substr(1) ? '#'+window.location.hash.substr(1) : ''
    var output

    if (oldid && !diff) {
      output = 'Special:Permalink/' + oldid
    } else if (oldid && diff === 'prev') {
      output = 'Special:Diff/' + oldid
    } else if (diff && oldid) {
      output = 'Special:Diff/' + oldid + '/' + diff
    } else if (diff) {
      output = 'Special:Diff/' + diff
    }

    if (output) {
      window.history.replaceState({}, '', '/wiki/' + output + hash)
    }
  }, 50)
})()