let icon = await fetch_image_as_base_64 'google.com'
let icon = await fetch_image_as_base_64 'google.com'
config.search_engine = { url, icon, frequency }
config.search_engine = { url, icon, frequency }
@ -123,14 +125,14 @@ tag app
def use_search_engine
def use_search_engine
increment_search_engine_frequency!
increment_search_engine_frequency!
window.location.href = "//{encoded_search_query}"
window.location.href = encoded_search_query
def fetch_image_as_base_64 url
def fetch_image_as_base_64 host
let fallback = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAH0lEQVR42mO8seXffwYqAsZRA0cNHDVw1MBRA0eqgQCDRkbJSQHxEQAAAABJRU5ErkJggg=='
let fallback = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAH0lEQVR42mO8seXffwYqAsZRA0cNHDVw1MBRA0eqgQCDRkbJSQHxEQAAAABJRU5ErkJggg=='
return new Promise! do |resolve|
return new Promise! do |resolve|
let res
let res
try
try
res = await global.fetch("https://icon.horse/icon/{url}")
res = await global.fetch("https://icon.horse/icon/{host}")
catch
catch
p "Failed to get icon from icon horse."
p "Failed to get icon from icon horse."
resolve fallback
resolve fallback
@ -154,13 +156,14 @@ tag app
let name = split_text.join(" ")
let name = split_text.join(" ")
{ name, url }
{ name, url }
def strip_url url
url.trim!.replace(/(^\w+:|^)\/\//, '')
def add_link { url, name, frequency=0 }
def add_link { url, name, frequency=0 }
name = name.trim!
name = name.trim!
url = strip_url url
let host
let img = await fetch_image_as_base_64(url)
try
{ href:url, host } = parse_url url
catch e
return err "parsing url", e
let img = await fetch_image_as_base_64 host
let id = nanoid!
let id = nanoid!
let link = { id, name, url, frequency, img }
let link = { id, name, url, frequency, img }
try
try
@ -172,7 +175,7 @@ tag app
def handle_click_link link
def handle_click_link link
await increment_link_frequency link
await increment_link_frequency link
window.location.href = "//{link.url}"
window.location.href = link.url
def handle_click_search
def handle_click_search
increment_search_engine_frequency!
increment_search_engine_frequency!
@ -183,7 +186,7 @@ tag app
else
else
let link = state.scored_links[selection_index]
let link = state.scored_links[selection_index]
await increment_link_frequency link
await increment_link_frequency link
window.location.href = "//{link.url}"
window.location.href = link.url
def handle_click_add
def handle_click_add
loading = yes
loading = yes
@ -240,20 +243,19 @@ tag app
settings_active = no
settings_active = no
loading = no
loading = no
def set_search_engine url
let icon = await fetch_image_as_base_64 url
config.search_engine = { url, icon }
save_config!
def handle_click_config
def handle_click_config
loading = yes
loading = yes
let input = window.prompt("Please enter the URL of your search engine.")
let set_search_engine = do
return unless input
let input = window.prompt "Please enter the URL of your search engine."
let url = input.trim!.replace(/(^\w+:|^)\/\//, '')