summaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
authorhackademix2018-10-13 10:08:37 +0200
committerhackademix2018-10-13 10:08:37 +0200
commit808fd652be324098b3083302bc3218e47a11aba5 (patch)
treee6c53d53ad578f871c0cbca8126921045b4d5e07 /src/content
parente44fce3ebd6c348b9e09304d8b79e90f3867bd60 (diff)
downloadnoscript-808fd652be324098b3083302bc3218e47a11aba5.tar.gz
noscript-808fd652be324098b3083302bc3218e47a11aba5.tar.xz
noscript-808fd652be324098b3083302bc3218e47a11aba5.zip
Use cookie instead of window.name as a tab-configuration hack.
Diffstat (limited to 'src/content')
-rw-r--r--src/content/staticNS.js29
1 files changed, 9 insertions, 20 deletions
diff --git a/src/content/staticNS.js b/src/content/staticNS.js
index 429814c..c746180 100644
--- a/src/content/staticNS.js
+++ b/src/content/staticNS.js
@@ -47,33 +47,22 @@
this.config.permissions = permissions;
// ugly hack: since now we use registerContentScript instead of the
- // filterRequest dynamic script injection hack, we use window.name
- // to store per-tab information. We don't want web content to
- // mess with it, though, so we wrap it around auto-hiding accessors
+ // filterRequest dynamic script injection hack, we use a session cookie
+ // to store per-tab information, erasing it as soon as we see it
+ // (before any content can access it)
if (this.config.MARKER = MARKER) {
- let splitter = `${MARKER},`;
- this.getWindowName = () => window.name.split(splitter).pop();
-
- let tabInfoRx = new RegExp(`^${MARKER}\\[([^]*?)\\]${MARKER},`);
-
- let tabInfoMatch = window.name.match(tabInfoRx);
- if (tabInfoMatch) {
+ let cookieRx = new RegExp(`(?:^|;\\s*)${MARKER}=([^;]*)`);
+ let match = document.cookie.match(cookieRx);
+ if (match) {
+ // delete cookie NOW
+ document.cookie = `${MARKER}=;expires=${new Date(Date.now() - 31536000000).toGMTString()}`;
try {
- this.config.tabInfo = JSON.parse(tabInfoMatch[1]);
+ this.config.tabInfo = JSON.parse(decodeURIComponent(match[1]));
} catch (e) {
error(e);
}
}
-
- Reflect.defineProperty(window.wrappedJSObject, "name", {
- get: exportFunction(() => this.getWindowName(), window.wrappedJSObject),
- set: exportFunction(value => {
- let tabInfoMatch = window.name.match(tabInfoRx);
- window.name = tabInfoMatch ? `${tabInfoMatch[0]}${value}` : value;
- return value;
- }, window.wrappedJSObject)
- });
}
if (!this.config.permissions || this.config.tabInfo.unrestricted) {
debug("%s is loading unrestricted by user's choice (%o).", document.URL, this.config);