diff options
author | hackademix | 2018-08-17 09:07:11 +0200 |
---|---|---|
committer | hackademix | 2018-08-17 09:07:11 +0200 |
commit | e959accb70ea00f99fa611c9f1af40e1be5bde92 (patch) | |
tree | 7d09dac1c3016c0cbec6a91b66bb8cf5f601ad70 /src/content/content.js | |
parent | 50d71ca3819723439985cad4f40a095fb5f91f11 (diff) | |
download | noscript-e959accb70ea00f99fa611c9f1af40e1be5bde92.tar.gz noscript-e959accb70ea00f99fa611c9f1af40e1be5bde92.tar.xz noscript-e959accb70ea00f99fa611c9f1af40e1be5bde92.zip |
Hack: use top.name to store per-tab content-side configuration (e.g. unrestricted tab status).
Diffstat (limited to 'src/content/content.js')
-rw-r--r-- | src/content/content.js | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/content/content.js b/src/content/content.js index 37d0d32..2f10d5a 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -21,7 +21,47 @@ } } }, - perms: { DEFAULT: null, CURRENT: null }, + setup(DEFAULT, MARKER) { + this.perms.DEFAULT = DEFAULT; + if(!this.perms.CURRENT) this.perms.CURRENT = DEFAULT; + + // ugly hack: since now we use registerContentScript instead of the + // filterRequest dynamic script injection hack, we use top.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 + this.perms.MARKER = MARKER; + let eraseTabInfoRx = new RegExp(`[^]*${MARKER},?`); + if (eraseTabInfoRx.test(top.name)) { + let _name = top.name; + let tabInfoRx = new RegExp(`^${MARKER}\\[([^]*?)\\]${MARKER},`); + if (top === window) { // wrap to hide + Reflect.defineProperty(top.wrappedJSObject, "name", { + get: exportFunction(() => _name.replace(eraseTabInfoRx, ""), top.wrappedJSObject), + set: exportFunction(value => { + let preamble = _name.match(tabInfoRx); + _name = `${preamble && preamble[0] || ""}${value}`; + return value; + }, top.wrappedJSObject) + }); + } + let tabInfoMatch = _name.match(tabInfoRx); + if (tabInfoMatch) try { + this.perms.tabInfo = JSON.parse(tabInfoMatch[1]); + } catch (e) { + error(e); + } + } + + if (!this.perms.DEFAULT || this.perms.tabInfo.unrestricted) { + this.allows = () => true; + } + ns.fire("perms"); + }, + storeTabInfo(info) { + let {MARKER} = this.perms; + window.name = `${MARKER}${JSON.stringify([info])}${MARKER},${window.name.split(marker).pop()}`; + }, + perms: { DEFAULT: null, CURRENT: null, tabInfo: {} }, allows(cap) { let perms = this.perms.CURRENT; return perms && perms.capabilities.includes(cap); |