Skip to content

Commit

Permalink
properly remove history hack script
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceK33z committed Dec 19, 2016
1 parent 2f2f4cf commit e979c3b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/history-hack.js
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);

0 comments on commit e979c3b

Please sign in to comment.