-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
document.head.appendChild(document.createElement('script')).text = `(${ | ||
function () { | ||
// injected DOM script is not a content script anymore, | ||
// it can modify objects and functions of the page | ||
const _pushState = history.pushState; | ||
history.pushState = function (state, title, url) { | ||
_pushState.call(this, state, title, url); | ||
window.dispatchEvent(new CustomEvent('pushstate-changed', { detail: state })); | ||
}; | ||
// repeat the above for replaceState too | ||
}})();`; // remove the DOM script element | ||
const _script = document.createElement('script'); | ||
_script.text = `(${ | ||
function () { | ||
// injected DOM script is not a content script anymore, | ||
// it can modify objects and functions of the page | ||
const _pushState = history.pushState; | ||
history.pushState = function (state, title, url) { | ||
_pushState.call(this, state, title, url); | ||
window.dispatchEvent(new CustomEvent('pushstate-changed', { detail: state })); | ||
}; | ||
// repeat the above for replaceState too | ||
}})();`; | ||
|
||
document.head.appendChild(_script); | ||
document.head.removeChild(_script); |