18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/searchlink/searches/popup.rb', line 18
def search(type, search_terms, link_text)
return [false, false, link_text] unless workflow_exist?
term = search_terms.url_encode
url = case type
when /g$/
"https://www.google.com/search?hl=en&q=#{term}"
when /a$/
"https://www.amazon.com/s?k=#{term}"
when /b$/
"https://www.bing.com/search?q=#{term}"
when /w$/
"https://en.wikipedia.org/w/index.php?search=#{term}&title=Special%3ASearch&ns0=1"
else
"https://duckduckgo.com/?q=#{term}&ia=web"
end
res = `automator -i "#{url}" "#{SL::Util.}"`.strip
begin
if res.empty?
SL.add_error("Canceled", "Popup Search Cancelled")
return [false, false, link_text]
end
title = SL::URL.title(res)
link_text = title if link_text == "" && !SL.titleize
[res, title, link_text]
rescue StandardError
false
end
end
|