diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-23 10:43:33 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 10:43:33 +0000 |
commit | ccc81312a1d4d9a5cea7d7451c26ec25b2172aa8 (patch) | |
tree | 96ae119fb5e7939547284f72fc12cd9cc6c717d5 /src/content/components/top-content | |
parent | 7639e99b755e372712dca36e077a85d9a025cd9f (diff) | |
parent | b9f2668ceab3d786ce3e587803ff30ec5c781ee3 (diff) |
Merge pull request #90 from ueokande/11-url-blacklist
URL blacklist
Diffstat (limited to 'src/content/components/top-content')
-rw-r--r-- | src/content/components/top-content/index.js | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js index c318901..c4a8461 100644 --- a/src/content/components/top-content/index.js +++ b/src/content/components/top-content/index.js @@ -1,7 +1,9 @@ import CommonComponent from '../common'; import FollowController from './follow-controller'; import * as consoleFrames from '../../console-frames'; +import * as addonActions from '../../actions/addon'; import messages from 'shared/messages'; +import * as re from 'shared/utils/re'; export default class TopContent { @@ -11,17 +13,39 @@ export default class TopContent { new CommonComponent(win, store), new FollowController(win, store), ]; + this.store = store; + this.prevBlacklist = undefined; // TODO make component - consoleFrames.initialize(window.document); + consoleFrames.initialize(this.win.document); messages.onMessage(this.onMessage.bind(this)); } update() { + let blacklist = this.store.getState().setting.blacklist; + if (JSON.stringify(this.prevBlacklist) !== JSON.stringify(blacklist)) { + this.disableIfBlack(blacklist); + this.prevBlacklist = blacklist; + } + this.children.forEach(c => c.update()); } + disableIfBlack(blacklist) { + let loc = this.win.location; + let partial = loc.host + loc.pathname; + let matched = blacklist + .map((item) => { + let pattern = item.includes('/') ? item : item + '/*'; + return re.fromWildcard(pattern); + }) + .some(regex => regex.test(partial)); + if (matched) { + this.store.dispatch(addonActions.disable()); + } + } + onMessage(message) { switch (message.type) { case messages.CONSOLE_HIDE_COMMAND: |