Class: SL::PopupSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/searchlink/searches/popup.rb

Class Method Summary collapse

Class Method Details

.search(type, search_terms, link_text) ⇒ Object



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.popup_path}"`.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

.settingsObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/searchlink/searches/popup.rb', line 6

def settings
  {
    trigger: "pop(up)?[gaw]?",
    searches: [
      ["pop", "Popup DuckDuckGo Search"],
      ["popa", "Popup Amazon Search"],
      ["popg", "Popup Google Search"],
      ["popw", "Popup Wikipedia Search"]
    ]
  }
end