One function of Quix that made me instantly want it in Opera custom search is ability to use current URL as parameter. This can greatly simplify some searches, which I often do and find very annoying to type out every time.
So I hit some Opera blogs, took deep look on how Quix does that and after figured out how to set up custom search engine that is aware of site you run query on with bit of JavaScript.
Custom search limitation
Search engines in Opera can only process single parameter in query – whatever you type, even if that is multiply words. It is represented in engine settings as %s. Whatever you input after engine shortcut will replace %s in resulting URL (even if there are several %s used).
So natively there is no way to use such things as current site as search parameter. At best you can edit URL or copy/paste what is needed.
Inline JavaScript
My starting point was to search if there is a way to make it work with multiply parameters at all. Unsurprisingly I found a post at Tamil’s blog (best blog on Opera configuration and tweaks) that shows how to use JavaScript for split search query in multiply parameters.
Basically Opera executes search engine URL literally. That means it can easily be inline JavaScript command and it will be executed perfectly.
Use current URL
After few test I got this line to use as search engine (should be use in single line):
javascript:window.location.href='http://www.google.com/search?q=%s
site:'+document.location;
This will run Google search with your query as usual, but also append filter that limits results to site you are currently on.
Use selection from page
JavaScript can just as easy use text, selected in current page. Overall command will be same and JavaScript function to fetch selection is window.getSelection().
However I hit another roadblock here – you can’t run custom search with selection alone. You need to type something in as query or it won’t be recognized as search attempt.
I will brood on this some more, but for now I used this code for some simple bookmarklets. For example I often check URLs in comments for moderation with BackType. So bookmarklet to run such check on selection will be:
javascript:window.location.href='http://www.backtype.com/www/'
+window.getSelection();
Overall
JavaScript is more tricky to use for custom search engines comparing to regular URL commands. But it greatly increases number of possible parameters and their combinations to allow much more complex searches.
What would you like to use as search in Opera, but currently can’t? Share your ideas in the comments.
Saurabh #
Rarst #
Saurabh #
Saurabh #
Rarst #
purestmagic #
Rarst #