Code Monkey home page Code Monkey logo

safarikeywordsearch's Introduction

SafariKeywordSearch

http://safarikeywordsearch.aurlien.net

Download on the App Store

Safari Keyword Search is a simple extension for Safari on macOS amd iOS that enables keyword searching from the address bar. This is a simple but powerful feature that gives you access to several search engines using simple keywords. For example, you can search Wikipedia for information on monkeys by typing w monkeys in the address bar.

The following searches are included in the default set:

  • a: amazon.com
  • ao: archive.org waybackmachine
  • d: duckduckgo.com
  • down: downforeveryoneorjustme.com
  • e: ebay.com
  • g: google search
  • gm: google maps
  • i: google image search
  • imdb: imdb.com
  • so: stackoverflow.com
  • w: en.wikipedia.org
  • wa: wolframalpha.com
  • y: youtube.com

You can also add your own searches in the extension settings, which live inside Safari.

If you want to contribute a PR, feel free. Let me warn you, the source code is a lot like a garbage fire at a spaghetti factory.

Did the extension disappear from Safari on macOS?

There is a bug in Safari on macOS where extensions sometimes disappear. To fix it, quit Safari then copy this command and run it in the Terminal:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f -R /Applications/Safari.app

Thanks to Jeff Johnson for figuring that out!

Weird details/limitations etc

This is how the extension works:

  1. Listening for the beforeNavigate event
  2. Checking the URL to see if the domain matches one of the default search domains in Safari (Google, Bing, Yahoo, DuckDuckGo or Ecosia
  3. Extracting the search string from the URL
  4. Checking if the search string includes one of the keywords
  5. Quickly replacing the URL of the tab with the new search URL

Parsing the URL to get the search string is not optimal, but it’s the only way with the current APIs. These edge cases/bugs can occur:

  • In some cases, the default search engine will load in the tab before the extension is triggered, especially if the search engine you are using is slightly slow to respond (Wikipedia I'm lookin at you).
  • If you have more than one keyword the extension can in rare cases trigger multiple times (i.e. if you enter ddg g w monkey) (there are workarounds for this in place but it can happen anyway).

The previous previous Safari Extension API had a beforeSearch event that was a lot more convenient. To any Safari developers who might be reading this: hello!

safarikeywordsearch's People

Contributors

arnemart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.