diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-07 17:52:01 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-08 11:44:37 +0900 |
commit | cf0dcf25226611590d76d263b5a4acdc89510d09 (patch) | |
tree | 93710555c22a088fbdc4ed64c25f5f9f593f8e0a /src/content | |
parent | 327144a3aa962b51d9b143941be4e626abbc7ee7 (diff) |
blacklist as an util
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/components/common/index.js | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 3a23956..e81bf1f 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -5,6 +5,7 @@ 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'; +import * as blacklists from 'shared/blacklists'; export default class Common { constructor(win, store) { @@ -46,27 +47,15 @@ export default class Common { }); } - let blacklist = JSON.stringify(this.store.getState().setting.blacklist); - if (blacklist !== this.prevBlacklist) { - this.prevBlacklist = blacklist; - - this.disableIfBlack(this.store.getState().setting.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()); + let blacklist = this.store.getState().setting.blacklist; + let str = JSON.stringify(blacklist) + if (blacklist !== str) { + this.prevBlacklist = str; + if (blacklists.includes(blacklist, this.win.location)) { + this.store.dispatch(addonActions.disable()); + } else { + this.store.dispatch(addonActions.enable()); + } } } |