aboutsummaryrefslogtreecommitdiff
path: root/src/content/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/components')
-rw-r--r--src/content/components/common/index.js29
-rw-r--r--src/content/components/common/keymapper.js7
-rw-r--r--src/content/components/top-content/index.js29
3 files changed, 16 insertions, 49 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js
index 6437011..a1e71a1 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 blacklists from 'shared/blacklists';
export default class Common {
constructor(win, store) {
@@ -14,42 +15,34 @@ 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();
messages.onMessage(this.onMessage.bind(this));
- store.subscribe(() => this.update());
}
onMessage(message) {
+ let { enabled } = this.store.getState().addon;
switch (message.type) {
case messages.SETTINGS_CHANGED:
return this.reloadSettings();
case messages.ADDON_TOGGLE_ENABLED:
- return this.store.dispatch(addonActions.toggleEnabled());
+ this.store.dispatch(addonActions.setEnabled(!enabled));
}
}
- update() {
- let enabled = this.store.getState().addon.enabled;
- if (enabled !== this.prevEnabled) {
- this.prevEnabled = enabled;
-
- browser.runtime.sendMessage({
- type: messages.ADDON_ENABLED_RESPONSE,
- enabled,
- });
- }
- }
-
- async reloadSettings() {
+ reloadSettings() {
try {
- let settings = await browser.runtime.sendMessage({
- type: messages.SETTINGS_QUERY,
+ this.store.dispatch(settingActions.load()).then(({ value: settings }) => {
+ let enabled = !blacklists.includes(
+ settings.blacklist, this.win.location.href
+ );
+ this.store.dispatch(addonActions.setEnabled(enabled));
});
- this.store.dispatch(settingActions.set(settings));
} catch (e) {
// Sometime sendMessage fails when background script is not ready.
console.warn(e);
diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js
index d9d1b2f..4c294b4 100644
--- a/src/content/components/common/keymapper.js
+++ b/src/content/components/common/keymapper.js
@@ -20,6 +20,7 @@ export default class KeymapperComponent {
this.store = store;
}
+ // eslint-disable-next-line max-statements
key(key) {
this.store.dispatch(inputActions.keyPress(key));
@@ -47,8 +48,10 @@ export default class KeymapperComponent {
return true;
}
let operation = keymaps.get(matched[0]);
- this.store.dispatch(operationActions.exec(
- operation, key.repeat, state.setting));
+ let act = operationActions.exec(
+ operation, key.repeat, state.setting, state.addon.enabled
+ );
+ this.store.dispatch(act);
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 a0d0480..e22e957 100644
--- a/src/content/components/top-content/index.js
+++ b/src/content/components/top-content/index.js
@@ -2,16 +2,13 @@ import CommonComponent from '../common';
import FollowController from './follow-controller';
import FindComponent from './find';
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 {
constructor(win, store) {
this.win = win;
this.store = store;
- this.prevBlacklist = undefined;
new CommonComponent(win, store); // eslint-disable-line no-new
new FollowController(win, store); // eslint-disable-line no-new
@@ -21,32 +18,6 @@ export default class TopContent {
consoleFrames.initialize(this.win.document);
messages.onMessage(this.onMessage.bind(this));
-
- this.store.subscribe(() => this.update());
- }
-
- update() {
- let blacklist = this.store.getState().setting.blacklist;
- if (JSON.stringify(this.prevBlacklist) !== JSON.stringify(blacklist)) {
- this.disableIfBlack(blacklist);
- this.prevBlacklist = blacklist;
- }
- }
-
- 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());
- }
}
onMessage(message) {