aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-11 17:45:58 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-11 17:45:58 +0900
commit8cef5981b808bc1713170627c88dc26ca81063c1 (patch)
tree6e1af4a4888bfcd9dcb64df00438ad97c5e5c392 /src/shared
parentc6288f19d93a05f96274dd172450b8350389c39f (diff)
Clipbaord as a clean architecture
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/urls.ts10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/shared/urls.ts b/src/shared/urls.ts
index 18349c8..bbdb1ea 100644
--- a/src/shared/urls.ts
+++ b/src/shared/urls.ts
@@ -1,3 +1,5 @@
+import { Search } from './Settings';
+
const trimStart = (str: string): string => {
// NOTE String.trimStart is available on Firefox 61
return str.replace(/^\s+/, '');
@@ -5,7 +7,7 @@ const trimStart = (str: string): string => {
const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:', 'about:'];
-const searchUrl = (keywords: string, searchSettings: any): string => {
+const searchUrl = (keywords: string, search: Search): string => {
try {
let u = new URL(keywords);
if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) {
@@ -17,12 +19,12 @@ const searchUrl = (keywords: string, searchSettings: any): string => {
if (keywords.includes('.') && !keywords.includes(' ')) {
return 'http://' + keywords;
}
- let template = searchSettings.engines[searchSettings.default];
+ let template = search.engines[search.default];
let query = keywords;
let first = trimStart(keywords).split(' ')[0];
- if (Object.keys(searchSettings.engines).includes(first)) {
- template = searchSettings.engines[first];
+ if (Object.keys(search.engines).includes(first)) {
+ template = search.engines[first];
query = trimStart(trimStart(keywords).slice(first.length));
}
return template.replace('{}', encodeURIComponent(query));