diff options
Diffstat (limited to 'src/content/components')
-rw-r--r-- | src/content/components/common/index.js | 4 | ||||
-rw-r--r-- | src/content/components/common/keymapper.js | 15 | ||||
-rw-r--r-- | src/content/components/top-content/index.js | 26 |
3 files changed, 35 insertions, 10 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index db0ac43..5f5531b 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -1,7 +1,7 @@ import InputComponent from './input'; import KeymapperComponent from './keymapper'; import FollowComponent from './follow'; -import * as inputActions from 'content/actions/input'; +import * as settingActions from 'content/actions/setting'; import messages from 'shared/messages'; export default class Common { @@ -40,7 +40,7 @@ export default class Common { browser.runtime.sendMessage({ type: messages.SETTINGS_QUERY, }).then((settings) => { - this.store.dispatch(inputActions.setKeymaps(settings.keymaps)); + this.store.dispatch(settingActions.set(settings)); }); } } diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index 5070cd8..44d8212 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -11,19 +11,20 @@ export default class KeymapperComponent { } key(key) { - let enabled = this.store.getState().addon.enabled; - this.store.dispatch(inputActions.keyPress(key)); - let input = this.store.getState().input; - let matched = Object.keys(input.keymaps).filter((keyStr) => { + let state = this.store.getState(); + let input = state.input; + let keymaps = state.setting.keymaps; + + let matched = Object.keys(keymaps).filter((keyStr) => { return keyStr.startsWith(input.keys); }); - if (!enabled) { + if (!state.addon.enabled) { // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if // the addon disabled matched = matched.filter((keys) => { - let type = input.keymaps[keys].type; + let type = keymaps[keys].type; return type === operations.ADDON_ENABLE || type === operations.ADDON_TOGGLE_ENABLED; }); @@ -35,7 +36,7 @@ export default class KeymapperComponent { matched.length === 1 && input.keys !== matched[0]) { return true; } - let operation = input.keymaps[matched]; + let operation = keymaps[matched]; this.store.dispatch(operationActions.exec(operation)); this.store.dispatch(inputActions.clearKeys()); return true; 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: |