Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 10, 2016, 08:50:49 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FarSubScript : GoogleSearch  (Read 1906 times)

verszipo

  • Member
  • Joined in 2009
  • **
  • Posts: 26
    • View Profile
    • Donate to Member
FarSubScript : GoogleSearch
« on: May 27, 2013, 08:22:14 AM »
I needed a way to do money/unit conversions in FARR and since I usually use Google Search for that i thought I'd make a script to call GoogleSearch inside FARR.

Here's the script
Spoiler
Code: Javascript [Select]
  1. plugins["GoogleSearch"] =
  2. {
  3.         version: "1.0",
  4.         lastChange: new Date(fso.GetFile(currentDirectory+"\\fsubscript.js").DateLastModified).toDateString(),
  5.         displayName: "GoogleSearch",
  6.         directory: currentDirectory,
  7.         icon: currentDirectory + "\\favicon.ico",
  8.         aliasstr: "gs",
  9.         description: "Search using Google (usefull for online conversions)"
  10. };
  11.  
  12. (function ()
  13. {
  14.         var js = plugins["GoogleSearch"];
  15.         var loaded = false;
  16.         var match = false;
  17.         var match2 = false;
  18.         var loadurl = "";
  19.         js.search = function search(querykey, explicit, queryraw, querynokeyword,modifierstring,triggermethod)
  20.         {
  21.                 if(!explicit) return;
  22.  
  23.                 idletime = 0;
  24.                 // first : match when a space is at the end of the string
  25.                 match = queryraw.match(new RegExp("^"+js.aliasstr+" (.+)  $"));
  26.                 // second : match when the user presses enter
  27.                 match2= queryraw.match(new RegExp("^"+js.aliasstr+" (.+)$"));
  28.  
  29.                 if((match && match[1])||
  30.                   (triggermethod && match2 && match2[1]))
  31.                 {
  32.                         loaded = true;
  33.                         // formated HTML must be like this :
  34.                         // http://www.google.ro/search?q=query string
  35.                         // Example : http://www.google.ro/search?q=10$ in euro
  36.                         if (match)
  37.                                 loadurl = "http://www.google.ro/search?q="+match[1];
  38.                         else if (match2)
  39.                                 loadurl = "http://www.google.ro/search?q="+match2[1];
  40.                         else
  41.                                 loadurl = "";
  42.                         htmlViewURL(loadurl);
  43.                         showPleaseWait("Loading..");
  44.                 }
  45.                 else
  46.                 {
  47.                         showHTML("<b>GoogleSearch</b>\
  48.                                 <br>Search using the power of the Google Search service\
  49.                                 <br><br>\
  50.                                 <br>Syntax : <b>"+js.aliasstr+" search string</b>\
  51.                                 <br>(either press ENTER or twice SPACE at the end of the search string)\
  52.                                 <br><br>You can use the special search options of google\
  53.                                 <br><br>Example: <b><br>"+js.aliasstr+" 10$ in euro</b>\
  54.                                 <br>this will show you how much 10$ are in euros\
  55.                                 <br><br>\
  56.                                 <br>For a complete set of supported values look at\
  57.                                 <br><a href=http://www.google.com/insidesearch/tipstricks/all.html>http://www.google.com/insidesearch/tipstricks/all.html</a>\
  58.                         ");
  59.                 }
  60.         };
  61.         js.setStrValue = function onSetStrValue(varname,value)
  62.         {
  63.                 if(varname == "EmbeddedWb.DocumentComplete")
  64.                 {
  65.                         var pl = pluginInCharge();
  66.                         if(pl == "GoogleSearch" && loaded)
  67.                         {
  68.                                 loaded = false;
  69.                                 // hide the "Chrome browser" advertisment
  70.                                 execSafeJS("\
  71. //                                      document.getElementById('gt-bbar').style.display='none';\n\
  72.                                 ");
  73.                                 hidePleaseWait();
  74.                         }
  75.                 }
  76.         }
  77. }());


Usage :
gs search string<space><space>
or
gs search string<enter>

Note : since i usually search for things that contains spaces i made the script to autosearch only when i enter 2 consecutive spaces (otherwise when entering "10$ in euro" it would autosearch after the 10$ and also after in)

There are still some bugs in it, the most notable ones are :
- cannot open the search results in the browser that you set in FARR (the alternate browser setting), the workaround is to copy the link's address and paste it in FARR and press enter (that will open the browser)

Note : this script requires FarSubScript, make sure you have it installed and working in FARR.

Install :
extract the content of the archive into a subfolder under the Scripts folder of FARR (for example : plugins\GoogleSearch) and either write "goreload" in FARR (this will reload all plugins) or restart FARR.

If anybody wants to improve the script feel free to do so.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,434
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: FarSubScript : GoogleSearch
« Reply #1 on: May 27, 2013, 05:09:32 PM »
Thanks for sharing this!!  :Thmbsup: