From 1f89464e4285936bdd509e2607aa70e93d5383a4 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 9 Dec 2018 10:19:08 +0900 Subject: Add gh/gH to open home page --- src/shared/urls.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/shared/urls.js') diff --git a/src/shared/urls.js b/src/shared/urls.js index d6c31e6..efdbcdb 100644 --- a/src/shared/urls.js +++ b/src/shared/urls.js @@ -5,7 +5,7 @@ const trimStart = (str) => { const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:']; -const normalizeUrl = (keywords, searchSettings) => { +const searchUrl = (keywords, searchSettings) => { try { let u = new URL(keywords); if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) { @@ -28,4 +28,20 @@ const normalizeUrl = (keywords, searchSettings) => { return template.replace('{}', encodeURIComponent(query)); }; -export { normalizeUrl }; +const normalizeUrl = (url) => { + try { + let u = new URL(url); + if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) { + return u.href; + } + } catch (e) { + // fallthrough + } + return 'http://' + url; +}; + +const homepageUrls = (value) => { + return value.split('|').map(normalizeUrl); +}; + +export { searchUrl, normalizeUrl, homepageUrls }; -- cgit v1.2.3