@@ -3,11 +3,16 @@ import { encodeSource, decodeSource, getHosts, setHosts } from 'libs'
33import isEqual from 'lodash.isequal'
44import sizeof from 'object-sizeof'
55import { js } from 'js-beautify'
6+ import Store from 'stores'
7+
8+ type Host = { isRegex : boolean ; pattern : string } | string
69
710const key = 'popup'
811const defaultSource = '// Here You can type your custom JavaScript...'
912
1013export default class AppStore {
14+ store : Store
15+
1116 constructor ( store ) {
1217 this . store = store
1318 }
@@ -20,7 +25,7 @@ export default class AppStore {
2025
2126 @observable saved = false
2227
23- @observable hosts = [ ]
28+ @observable hosts : Host [ ] = [ ]
2429
2530 @observable enable = false
2631
@@ -36,7 +41,7 @@ export default class AppStore {
3641
3742 @observable protocol = ''
3843
39- @observable matchedHost = ''
44+ @observable matchedHost : Host = ''
4045
4146 @observable loadError = null
4247
@@ -61,17 +66,12 @@ export default class AppStore {
6166
6267 @computed
6368 get target ( ) {
64- if ( this . isRegex ) {
69+ if ( typeof this . matchedHost === 'object' && this . matchedHost . isRegex ) {
6570 return this . matchedHost . pattern
6671 }
6772 return this . domain
6873 }
6974
70- @computed
71- get isRegex ( ) {
72- return this . matchedHost && this . matchedHost . isRegex
73- }
74-
7575 @computed
7676 get differentURL ( ) {
7777 return ! this . tab . url . startsWith ( this . domain )
@@ -101,7 +101,7 @@ export default class AppStore {
101101
102102 @computed
103103 get domainKey ( ) {
104- if ( this . isRegex ) {
104+ if ( typeof this . matchedHost === 'object' && this . matchedHost . isRegex ) {
105105 return `${ key } -${ this . matchedHost . pattern } `
106106 }
107107 return `${ key } -${ this . domain } `
@@ -257,8 +257,9 @@ export default class AppStore {
257257 newHosts = this . hosts . filter ( x => x !== this . domain )
258258 } else {
259259 Object . assign ( message , this . matchedHost )
260+ const { pattern } = this . matchedHost
260261 newHosts = this . hosts . filter (
261- x => ! x . isRegex || x . pattern !== this . matchedHost . pattern
262+ x => typeof x === 'string' || ( ! x . isRegex || x . pattern !== pattern )
262263 )
263264 }
264265 this . saveHosts ( newHosts )
0 commit comments