From e979c3b84699ba6caf6e9f2ea24352699c7b6f88 Mon Sep 17 00:00:00 2001 From: Kees Kluskens Date: Mon, 19 Dec 2016 17:00:03 +0100 Subject: [PATCH] properly remove history hack script --- src/history-hack.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/history-hack.js b/src/history-hack.js index 84bcbb5..aa8ab86 100644 --- a/src/history-hack.js +++ b/src/history-hack.js @@ -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);