diff options
author | 2021-09-14 19:58:52 +0200 | |
---|---|---|
committer | 2021-09-14 19:58:52 +0200 | |
commit | 95df3522a15631abc51a4295cae0ea401a8d4e1e (patch) | |
tree | e5eb0f368c947683f01458e912f21756fb0d99cb /src/features/webControls | |
parent | docs: add sad270 as a contributor for bug, userTesting [skip ci] (#1941) (diff) | |
download | ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.gz ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.zst ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.zip |
feat: add eslint-plugin-unicorn (#1936)
Diffstat (limited to 'src/features/webControls')
-rw-r--r-- | src/features/webControls/containers/WebControlsScreen.js | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/features/webControls/containers/WebControlsScreen.js b/src/features/webControls/containers/WebControlsScreen.js index e1e1b9991..0273bb13e 100644 --- a/src/features/webControls/containers/WebControlsScreen.js +++ b/src/features/webControls/containers/WebControlsScreen.js | |||
@@ -16,7 +16,8 @@ const URL_EVENTS = [ | |||
16 | 'did-navigate-in-page', | 16 | 'did-navigate-in-page', |
17 | ]; | 17 | ]; |
18 | 18 | ||
19 | @inject('stores', 'actions') @observer | 19 | @inject('stores', 'actions') |
20 | @observer | ||
20 | class WebControlsScreen extends Component { | 21 | class WebControlsScreen extends Component { |
21 | @observable url = ''; | 22 | @observable url = ''; |
22 | 23 | ||
@@ -36,15 +37,15 @@ class WebControlsScreen extends Component { | |||
36 | this.webview = service.webview; | 37 | this.webview = service.webview; |
37 | this.url = this.webview.getURL(); | 38 | this.url = this.webview.getURL(); |
38 | 39 | ||
39 | URL_EVENTS.forEach((event) => { | 40 | for (const event of URL_EVENTS) { |
40 | this.webview.addEventListener(event, (e) => { | 41 | this.webview.addEventListener(event, e => { |
41 | if (!e.isMainFrame) return; | 42 | if (!e.isMainFrame) return; |
42 | 43 | ||
43 | this.url = e.url; | 44 | this.url = e.url; |
44 | this.canGoBack = this.webview.canGoBack(); | 45 | this.canGoBack = this.webview.canGoBack(); |
45 | this.canGoForward = this.webview.canGoForward(); | 46 | this.canGoForward = this.webview.canGoForward(); |
46 | }); | 47 | }); |
47 | }); | 48 | } |
48 | } | 49 | } |
49 | }); | 50 | }); |
50 | } | 51 | } |
@@ -83,13 +84,16 @@ class WebControlsScreen extends Component { | |||
83 | 84 | ||
84 | try { | 85 | try { |
85 | url = new URL(url).toString(); | 86 | url = new URL(url).toString(); |
86 | } catch (err) { | 87 | } catch { |
87 | // eslint-disable-next-line no-useless-escape | 88 | url = |
88 | if (url.match(/^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$/)) { | 89 | // eslint-disable-next-line no-useless-escape |
89 | url = `http://${url}`; | 90 | /^((?!-))(xn--)?[\da-z][\d_a-z-]{0,61}[\da-z]{0,1}\.(xn--)?([\da-z\-]{1,61}|[\da-z-]{1,30}\.[a-z]{2,})$/.test( |
90 | } else { | 91 | url, |
91 | url = SEARCH_ENGINE_URLS[this.settings.app.searchEngine]({ searchTerm: url }); | 92 | ) |
92 | } | 93 | ? `http://${url}` |
94 | : SEARCH_ENGINE_URLS[this.settings.app.searchEngine]({ | ||
95 | searchTerm: url, | ||
96 | }); | ||
93 | } | 97 | } |
94 | 98 | ||
95 | this.webview.loadURL(url); | 99 | this.webview.loadURL(url); |
@@ -114,7 +118,7 @@ class WebControlsScreen extends Component { | |||
114 | goBack={() => this.goBack()} | 118 | goBack={() => this.goBack()} |
115 | canGoForward={this.canGoForward} | 119 | canGoForward={this.canGoForward} |
116 | goForward={() => this.goForward()} | 120 | goForward={() => this.goForward()} |
117 | navigate={(url) => this.navigate(url)} | 121 | navigate={url => this.navigate(url)} |
118 | url={this.url} | 122 | url={this.url} |
119 | /> | 123 | /> |
120 | ); | 124 | ); |