diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-07 16:58:09 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-08 11:44:37 +0900 |
commit | 327144a3aa962b51d9b143941be4e626abbc7ee7 (patch) | |
tree | a29069d9aac9085d1dbaa02ad64111f95ef94765 /src/content/components/common/index.js | |
parent | 85b4bd5b073af729ff325e90fa3c9078f90277ac (diff) |
[wip] content
Diffstat (limited to 'src/content/components/common/index.js')
-rw-r--r-- | src/content/components/common/index.js | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 6437011..3a23956 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -4,6 +4,7 @@ import FollowComponent from './follow'; import * as settingActions from 'content/actions/setting'; import messages from 'shared/messages'; import * as addonActions from '../../actions/addon'; +import * as re from 'shared/utils/re'; export default class Common { constructor(win, store) { @@ -14,8 +15,10 @@ export default class Common { input.onKey(key => follow.key(key)); input.onKey(key => keymapper.key(key)); + this.win = win; this.store = store; this.prevEnabled = undefined; + this.prevBlacklist = undefined; this.reloadSettings(); @@ -42,14 +45,34 @@ export default class Common { enabled, }); } + + let blacklist = JSON.stringify(this.store.getState().setting.blacklist); + if (blacklist !== this.prevBlacklist) { + this.prevBlacklist = blacklist; + + this.disableIfBlack(this.store.getState().setting.blacklist); + } } - async reloadSettings() { + 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()); + } else { + this.store.dispatch(addonActions.enable()); + } + } + + reloadSettings() { try { - let settings = await browser.runtime.sendMessage({ - type: messages.SETTINGS_QUERY, - }); - this.store.dispatch(settingActions.set(settings)); + this.store.dispatch(settingActions.load()); } catch (e) { // Sometime sendMessage fails when background script is not ready. console.warn(e); |