Jump to content

User:Þjarkur/CleanDiffURLs.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Þjarkur (talk | contribs) at 15:09, 31 July 2019 (Created page with '/* Gives clean diff URLs Turns this: /w/index.php?title=Main_Page&diff=864711889&oldid=864629150&diffmode=source Into this: /wiki/Special:Diff/864629150/86...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
  Gives clean diff URLs
  Turns this: /w/index.php?title=Main_Page&diff=864711889&oldid=864629150&diffmode=source
  Into this: /wiki/Special:Diff/864629150/864711889
*/
(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 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)
    }
  }, 200)
})()