User:Kiteretsu/CleanDiffURLs.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
+ created
Tags: Mobile edit Mobile web edit
 
Amos (talk | contribs)
m Tsukushi moved page User:Infinityboy7/CleanDiffURLs.js to User:Kiteretsu/CleanDiffURLs.js without leaving a redirect: Uncontroversial move: User renamed.
 
(One intermediate revision by one other user not shown)
(No difference)

Latest revision as of 02:04, 30 August 2024

/*
  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 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
    } 

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