Skip to content

Instantly share code, notes, and snippets.

@tonis2
Created April 23, 2019 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonis2/72c334f19c38753df0d0cc0864ec72b1 to your computer and use it in GitHub Desktop.
Save tonis2/72c334f19c38753df0d0cc0864ec72b1 to your computer and use it in GitHub Desktop.
Detect website url changes
/* These are the modifications: */
history.pushState = (f =>
function pushState() {
var ret = f.apply(this, arguments)
window.dispatchEvent(new Event("pushState"))
window.dispatchEvent(new Event("locationchange"))
return ret
})(history.pushState)
history.replaceState = (f =>
function replaceState() {
var ret = f.apply(this, arguments)
window.dispatchEvent(new Event("replaceState"))
window.dispatchEvent(new Event("locationchange"))
return ret
})(history.replaceState)
window.addEventListener("popstate", () => {
window.dispatchEvent(new Event("locationchange"))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment