Welcome Guest.   Make a donation to an author on the site August 02, 2014, 03:36:43 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
View the new Member Awards and Badges page.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: CurrencyConverterMini (plugin) [renamed thread]  (Read 14196 times)
Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« on: March 07, 2008, 02:29:32 AM »

edit 080813: thread renamed to "CurrencyConverterMini (plugin)" from "google dollar exchange rate plugin -- sketch" /nod5

While the donationcoder server was down I tried to put together a plugin based on the javascript SDK that takes a number as an input and queries google what that amount of dollars exchanges to in swedish kronor. In the finished plugin that swedish kronor part should of course be customizable to whatever currency the user prefers. Below is the fscript.js I've put together so far. It works, but is a bit messy and lacks some things. To try it, make a copy of the Ninjawords plugin folder (for example) and replace the fscript.js script code with the one below. type "ex ___ " to run it, where ___ is some amount . Example: "ex 50 " . The plugin currently treats "ex 50.10 " and "ex 50,10 " as identical (50 dollars and 10 cents).

This is only a sketch version of the script. I'd love some assistance on a few things:

help1: How do I most easily let the user choose the output currency and make the plugin remember that?

help2: I want the plugin to go through these three steps: First, if there is a cached daily exchange rate, use that to calculate and display output. Second, if not, query google, parse, display output and cache exchange rate. Third, if the google query failed (i.e. offline), see if there's a cached older exchange rate, use that to calculate and display output plus a note that N days old rate was used. Now, how do I best do I best cache the exchange rate through javascript in the plugin? I basically need to read and write to a text file I guess but I don't even know how to do that I'm afraid ohmy

help3: I used "ex" as alias only because I couldn't get "$" to work (I wanted "$50 " to run the script for example). Is there some way to use "$" as an alias?


Quote
// plugin script :
displayname="Google exchange rate";
versionstring="1.01.01";
releasedatestring="5.3.2008";
author="nod5";
updateurl="";
homepageurl="";
shortdescription="Google exchange rate";
longdescription="the plugin queries google how many swedish kronor you get for the inputted amount of US dollars";
advconfigstring="Google exchange rate";
readmestring="Google exchange rate";
iconfilename="favicon.ico";

aliasstr="ex";
regexstr="^ex ((?:\d|\.|\,)*?) $";
scriptregex=/^ex ((?:\d|\.|\,)*?) $/;
regexfilterstr="";
keywordstr="";
scorestr="300";

// type
UNKNOWN=0; FILE=1; FOLDER=2; ALIAS=3; URL=4; PLUGIN=5; CLIP=5;
// Postprocessing
IMMEDIATE_DISPLAY=0; ADDSCORE=1; MATCH_AGAINST_SEARCH=2;
// search state
STOPPED=0; SEARCHING=1;

var pre_string = "{\\rtf1\\ansi\\ansicpg1250\\deff0\\deftab709{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}{\\colortbl ;\\red255\\green0\\blue0;}{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard\\lang2057\\f0\\fs18 ";
var post_string = "\\par\n}";
var history = "";

function doQuery(querykey,querynokeyword){

      querynokeyword = querynokeyword.replace(/,/g,'.');

  var url = "http://www.google.com/search?hl=en&q="+querynokeyword+"$+in+sek";
  var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");
  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4) {
      var string = xmlhttp.responseText;
      string = string.replace(/\\n|\\t/g,'');
      string = string.replace(/<font size=-2> <\/font>/g,'');
      string = string.replace(/.+US(\$ = (?:\d|\.|\,)*?) Swedish kronor.*$/g,'US$1');
      xpos = string.search(/US(\$ = .*)/g);
      string = querynokeyword+" "+string.slice(xpos)+" SEK"
      FARR.setStrValue("statusbar","Define");
      history = string;
      FARR.setStrValue("window.richeditmode",pre_string+history+post_string);
      }
    }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function onSearchBegin(querykey, explicit, queryraw, querynokeyword) {
  if(!explicit) {
    if(aliasstr.indexOf(querynokeyword)!=-1) {
      FARR.setState(querykey,1);
      FARR.emitResult(querykey,aliasstr, aliasstr, iconfilename,ALIAS,IMMEDIATE_DISPLAY,300);
      FARR.setState(querykey,0);
    }
    return;
  }
  FARR.setStrValue("statusbar","$ to SEK google converter");
    display = pre_string+"Type $ amount and hit \\b space\\b0"+post_string;
  FARR.setStrValue("window.richeditmode",display);
}

function onRegexSearchMatch(querykey,querynokeyword) {
  var match_reg = querynokeyword.match(scriptregex);
  doQuery(querykey,match_reg[1]);
}
« Last Edit: August 12, 2008, 06:48:13 PM by Nod5 » Logged
mouser
First Author
Administrator
*****
Posts: 33,185



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: March 08, 2008, 02:06:06 AM »

this is a nice idea.  i hope our resident farr javascript sdk experts (chezchboy and ecaradec) can help.  actually the answers to your question might make for some functions that could be useful for future plugins (caching support for example).

$ has a special meaning in regular expressions.  try \$ to match the $ character.
Logged
czb
Moderator
*****
Posts: 335



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: March 09, 2008, 01:07:37 AM »

Hi,
just shortly because I am in Netherlands for one week, so I dont have much time:

As to 1: You can put it in advanced setting, or you can try it similar way how I do it in google dictionary etc.
As to 2: I would recommend you to use JSON since it is very simple. You can read more about it here: http://www.json.org/js.html or you may also use XML. Take a look at delicious plugin how advanced setting is saved into a xml file.
Logged

My open-source online piano game: http://musicope.com/
ecaradec
Honorary Member
**
Posts: 408



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: March 11, 2008, 07:42:44 AM »

Quote
help2: I want the plugin to go through these three steps: First, if there is a cached daily exchange rate, use that to calculate and display output. Second, if not, query google, parse, display output and cache exchange rate. Third, if the google query failed (i.e. offline), see if there's a cached older exchange rate, use that to calculate and display output plus a note that N days old rate was used. Now, how do I best do I best cache the exchange rate through javascript in the plugin?
In the delicious plugin I stored the bookmarks in an xml files.
If you need to read and write text files : search for Scripting.FileSystemObject. It is an activex you can use to read and write files.
If you need to read and write xml files, you can use MSXML.DOMDocument.

Quote
help3: I used "ex" as alias only because I couldn't get "$" to work (I wanted "$50 " to run the script for example). Is there some way to use "$" as an alias?
You can try \$ as mouser tell you.
You can also set regexstr and scriptregex to empty,  set aliasstr to $, delete the onRegexSearchMatch function and only use the explicit match. You can then use javascript regexes only to match params. Regexes are useful when you need FARR to filter results based on a pattern when you use FARR.emitResult() to report results.

I'm very pleased to see all your work around javascript plugins.
Logged

Blog & Projects : Blog | Qatapult | SwiffOut | FScript
Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« Reply #4 on: March 11, 2008, 01:26:35 PM »

Thanks for the feedback mouser & czechboy & ecaradec!  Thmbsup
Here is a new version with these improvements:
- the user chooses the input and output currency (stored in options.xml ). If the input/output phrase works in google, it should work in this plugin.
- the plugin uses google only once after each FARR restart, thereafter it uses the cached exchange rate which means lightning fast results. (I'll look into writing the exchange rate to a file later, but I suspect the current in memory cache is enough for most usage)

code for fscript.js :
[copy or print]
// plugin script :
displayname="Currency Converter Mini";
versionstring="1.02.01";
releasedatestring="11.3.2008";
author="nod5";
updateurl="";
homepageurl="";
shortdescription="Convert from one currency to another via google.";
longdescription="To run the plugin, type \"ex 50 \" but replace 50 with the amount you want converted.\nSet input/output currency in advanced plugin options. (examples: $ £ GBP SEK canadian money )\nTest your input/output first by googling \"1 __ in __\", where _ is your input/output.\nAfter a FARR restart the first conversion uses google. Later conversions use the cached exchange rate.\nThe alias \"ex\" stands for exchange rate. The plugin converts one way, between two fixed currencies.\nFor other conversion needs just use google.";
advconfigstring="Currency Converter Mini";
readmestring="Currency Converter Mini";
iconfilename="favicon.ico";

aliasstr="ex";
regexstr="^ex ((?:\d|\.|\,)*?) $";
scriptregex=/^ex ((?:\d|\.|\,)*?) $/;
regexfilterstr="";
keywordstr="";
scorestr="300";

// type
UNKNOWN=0; FILE=1; FOLDER=2; ALIAS=3; URL=4; PLUGIN=5; CLIP=5;
// Postprocessing
IMMEDIATE_DISPLAY=0; ADDSCORE=1; MATCH_AGAINST_SEARCH=2;
// search state
STOPPED=0; SEARCHING=1;

var pre_string = "{\\rtf1\\ansi\\ansicpg1250\\deff0\\deftab709{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}{\\colortbl ;\\red255\\green0\\blue0;}{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard\\lang2057\\f0\\fs18 ";
var post_string = "\\par\n}";
var history = "";
var exrate = "";

function doQuery(querykey,querynokeyword){

querynokeyword = querynokeyword.replace(/,/g,'.');

if(exrate == ""){
  var url = "http://www.google.com/search?hl=en&q=1"+myinputcurrency+"+in+"+myoutputcurrency;
  var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");

  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4) {
      var string = xmlhttp.responseText;
      string = string.match(/<b>1 .* = (?:\d|\.|\,)*? /g);
      var splitstring = string[0].split("=");
      var exrate = splitstring[1].slice(1,-1);
      string = exrate * querynokeyword;
      string = Math.round(string);
      string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
      FARR.setStrValue("statusbar","Currency Converter Mini");
      FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
      }
    }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}
else {
var string = exrate * querynokeyword;
string = Math.round(string);
string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
FARR.setStrValue("statusbar","Currency Convert Mini");
FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
}

}

myinputcurrency="";
myoutputcurrency="";
function onOptionsChanged() {
    var options=new ActiveXObject("MSXML2.DOMDocument");
    options.load(currentDirectory+"\\options.xml")
    myinputcurrency=options.selectSingleNode("options/myinputcurrency").getAttribute("value");
    myoutputcurrency=options.selectSingleNode("options/myoutputcurrency").getAttribute("value");
}

function onInit(c) {
    currentDirectory=c;

    var options=new ActiveXObject("MSXML2.DOMDocument");
    if(!options.load(currentDirectory+"\\options.xml") ||
        options.selectSingleNode("options/myinputcurrency").getAttribute("value")=='' ||
        options.selectSingleNode("options/myoutputcurrency").getAttribute("value")=='') {
        options.loadXML("<options>\n"+
                        "<myinputcurrency label='exchange from :' value=''/>\n"+
                        "<myoutputcurrency label='exchange to :' value=''/>\n"+
                        "</options>");

        options.save(currentDirectory+"\\options.xml");
        options=null;
        FARR.showOptions();
    } else {
        onOptionsChanged();
    }
}



function onSearchBegin(querykey, explicit, queryraw, querynokeyword) {
  if(!explicit) {
    if(aliasstr.indexOf(querynokeyword)!=-1) {
      FARR.setState(querykey,1);
      FARR.emitResult(querykey,aliasstr, aliasstr, iconfilename,ALIAS,IMMEDIATE_DISPLAY,300);
      FARR.setState(querykey,0);
    }
    return;
  }
  FARR.setStrValue("statusbar","Currency Converter Mini");
    display = pre_string+"Type amount and hit \\b space\\b0"+post_string;
  FARR.setStrValue("window.richeditmode",display);
}

function onRegexSearchMatch(querykey,querynokeyword) {
  var match_reg = querynokeyword.match(scriptregex);
  doQuery(querykey,match_reg[1]);
}

edit:
- Can I add a title or description to the settings popup? (the one that stores the input/output in options.xml)
- I tried using escaping $ to \$ but still couldn't get it to work as an alias. Are you sure that it is possible in FARR?
« Last Edit: March 11, 2008, 01:32:23 PM by Nod5 » Logged
TucknDar
Charter Member
***
Posts: 1,094


Advanced coder of Nowt

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #5 on: June 22, 2008, 03:44:45 AM »

Great idea for a plugin, but it doesn't work for me... The screenshot explains a bit more:


both USD and NOK are valid values, but 'NaN NOK' isn't too helpful Wink

Also there is a crash whenever I open the plugin configuration dialog in FARR. I've saved the script as fscript.js in plugins/FARRCurrency along with a copy of the latest fscript.dll I could find.

any help appreciated smiley
Logged
Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« Reply #6 on: June 22, 2008, 05:58:02 AM »

Yes, this doesn't work at the moment. It did work previously so something must have changed (at google or in the FARR update).

Here is the problem:

The plugin uses javascript to extract a part of the google search results page. Here is an example snippet from google:
Quote
<tr><td><img src=/images/calc_img.gif width=40 height=30 alt=""></td><td>&nbsp;</td><td nowrap><h2 class=r><font size=+1>1 US$ = 0.506303478 British pounds</td></tr><tr><td>
The plugin tries to extract "<b>1 US$ = 0.506303478 " from the snippet through this code:
[copy or print]
string = string.match(/<b>1 .* = (?:\d|\.|\,)*? /g);
But somehow that does not stop at "0.506303478 " anymore but grabs a longer string. I can't see the error here. The last ? is supposed to make the search ungreedy (and I think it ought to work even without it). I just now also tried to use /gU but that doesn't work either. I'm sure there is some other way to do it but I'm bad at regexp in javascript and will have to look it up some more. If anyone spots a solution right away, please post it here.
« Last Edit: June 22, 2008, 06:04:07 AM by Nod5 » Logged
czb
Moderator
*****
Posts: 335



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: June 22, 2008, 06:01:51 AM »

what about to try?:
string = string.match(/1 .*? = (?:\d|\.|\,)*? /g);
Logged

My open-source online piano game: http://musicope.com/
Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« Reply #8 on: June 22, 2008, 06:04:40 AM »

Thanks! Will try it now.
Logged
Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« Reply #9 on: June 22, 2008, 06:56:01 AM »

That indeed solves it. Thank you czechboy! smiley I was focusing so intensively on finding the problem with the second * that I didn't notice that it was the first * was the real culprit. Doh!    huh Grin embarassed

TucknDar, I can't reproduce that plugin configuration dialog crash. What currencies have you entered (if any)? What version of fscript.dll ? My config works fine with fscript.dll v1.0.0.7 (MD5 86b830da7611128f97b6b4b63b18f53e )

[copy or print]
// plugin script :
displayname="Currency Converter Mini";
versionstring="1.02.02";
releasedatestring="22.6.2008";
author="nod5";
updateurl="";
homepageurl="";
shortdescription="Convert from one currency to another via google.";
longdescription="To run the plugin, type \"ex 50 \" but replace 50 with the amount you want converted.\nSet input/output currency in advanced plugin options. (examples: $ £ GBP SEK canadian money )\nTest your input/output first by googling \"1 __ in __\", where _ is your input/output.\nAfter a FARR restart the first conversion uses google. Later conversions use the cached exchange rate.\nThe alias \"ex\" stands for exchange rate. The plugin converts one way, between two fixed currencies.\nFor other conversion needs just use google.";
advconfigstring="Currency Converter Mini";
readmestring="Currency Converter Mini";
iconfilename="favicon.ico";

aliasstr="ex";
regexstr="^ex ((?:\d|\.|\,)*?) $";
scriptregex=/^ex ((?:\d|\.|\,)*?) $/;
regexfilterstr="";
keywordstr="";
scorestr="300";

// type
UNKNOWN=0; FILE=1; FOLDER=2; ALIAS=3; URL=4; PLUGIN=5; CLIP=5;
// Postprocessing
IMMEDIATE_DISPLAY=0; ADDSCORE=1; MATCH_AGAINST_SEARCH=2;
// search state
STOPPED=0; SEARCHING=1;

var pre_string = "{\\rtf1\\ansi\\ansicpg1250\\deff0\\deftab709{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}{\\colortbl ;\\red255\\green0\\blue0;}{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard\\lang2057\\f0\\fs18 ";
var post_string = "\\par\n}";
var history = "";
var exrate = "";

function doQuery(querykey,querynokeyword){

querynokeyword = querynokeyword.replace(/,/g,'.');

if(exrate == ""){
  var url = "http://www.google.com/search?hl=en&q=1"+myinputcurrency+"+in+"+myoutputcurrency;
  var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");

  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4) {
      var string = xmlhttp.responseText;
      string = string.match(/<b>1 .*? = (?:\d|\.|\,)*? /g);
      var splitstring = string[0].split("=");
      var exrate = splitstring[1].slice(1,-1);
      string = exrate * querynokeyword;
      string = Math.round(string);
      string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
      FARR.setStrValue("statusbar","Currency Converter Mini");
      FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
      }
    }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}
else {
var string = exrate * querynokeyword;
string = Math.round(string);
string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
FARR.setStrValue("statusbar","Currency Convert Mini");
FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
}

}

myinputcurrency="";
myoutputcurrency="";
function onOptionsChanged() {
    var options=new ActiveXObject("MSXML2.DOMDocument");
    options.load(currentDirectory+"\\options.xml")
    myinputcurrency=options.selectSingleNode("options/myinputcurrency").getAttribute("value");
    myoutputcurrency=options.selectSingleNode("options/myoutputcurrency").getAttribute("value");
}

function onInit(c) {
    currentDirectory=c;

    var options=new ActiveXObject("MSXML2.DOMDocument");
    if(!options.load(currentDirectory+"\\options.xml") ||
        options.selectSingleNode("options/myinputcurrency").getAttribute("value")=='' ||
        options.selectSingleNode("options/myoutputcurrency").getAttribute("value")=='') {
        options.loadXML("<options>\n"+
                        "<myinputcurrency label='exchange from :' value=''/>\n"+
                        "<myoutputcurrency label='exchange to :' value=''/>\n"+
                        "</options>");

        options.save(currentDirectory+"\\options.xml");
        options=null;
        FARR.showOptions();
    } else {
        onOptionsChanged();
    }
}



function onSearchBegin(querykey, explicit, queryraw, querynokeyword) {
  if(!explicit) {
    if(aliasstr.indexOf(querynokeyword)!=-1) {
      FARR.setState(querykey,1);
      FARR.emitResult(querykey,aliasstr, aliasstr, iconfilename,ALIAS,IMMEDIATE_DISPLAY,300);
      FARR.setState(querykey,0);
    }
    return;
  }
  FARR.setStrValue("statusbar","Currency Converter Mini");
    display = pre_string+"Type amount and hit \\b space\\b0"+post_string;
  FARR.setStrValue("window.richeditmode",display);
}

function onRegexSearchMatch(querykey,querynokeyword) {
  var match_reg = querynokeyword.match(scriptregex);
  doQuery(querykey,match_reg[1]);
}

I will put this in a proper plugin package later.
Logged
TucknDar
Charter Member
***
Posts: 1,094


Advanced coder of Nowt

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #10 on: June 22, 2008, 09:05:45 AM »

thanks, works now! very useful, but a request would be to be able to write 'ex 10 gbp usd' to change which currencies to use.

about the crash, I'll look into it a little more. It's been a while since I actually opened the plugins dialog, so maybe there's another culprit. I'll reply about it later
Logged
Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« Reply #11 on: June 22, 2008, 10:08:04 AM »

I'm glad it works!

On custom currencies, see this and the post after.

I earlier considered adding modifiers for other currencies. But in the end I just aimed for the slimmest and quickest possible conversion from one specific currency to another. Adding modifiers could conflict with that somewhat. I could parse the string after "ex" for space separated substrings ("111 aaa bbb ") an if so treat the latter as modifiers. But then a users that wants "111 aaa bbb " would see results for "ex 111 " and "ex 111 aaa " on the way, which is ugly. (Using format "111aaa bbb" might work though). I'll think about it but at the moment I think complex conversions is well handled by the igo method ("igo 200 $ in €") or czechboys Google Calculator plugin (see link above).
Logged
lanux128
Global Moderator
*****
Posts: 6,087



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #12 on: June 22, 2008, 07:49:03 PM »

thanks again Nod5 & czechboy but it is possible to use another source such as RatesFx? i have an off-site page of the website's currency calculator and currently view it through 'igo'. if this can be somewhat piped through Farr like the 'gcal', then it would be a great time-saver.

P.S. remove the 'txt' extension before viewing it. i put it there since the forum wouldn't allow me to attach 'html' files.

* ratesfx_html.txt (21.17 KB - downloaded 341 times.)
Logged

Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« Reply #13 on: June 23, 2008, 06:38:03 AM »

I added the more complex google syntax after all. Please testdrive it for bugs TucknDar and others  smiley

Currency Converter Mini now has two modes: default and advanced.
To use default, enter your default input/output currency to options once and after that just type "ex 100 "
To use advanced, type in a way that google currency converter understands: "ex 100$ in € " ("ex 100 $ in €" also works but does an extra search at "ex 100 ")






I also noticed that the plugin uses google for every default search now so the cache is not working. I'll try to fix that too.
[copy or print]
// plugin script :
displayname="Currency Converter Mini";
versionstring="1.03.01";
releasedatestring="23.6.2008";
author="nod5";
updateurl="";
homepageurl="";
shortdescription="Convert from one currency to another via google.";
longdescription="Set default input/output currency in options (examples: $ £ GBP SEK canadian money or anything google accepts).\nDefault mode: \"ex 50 \".  Advanced mode: \"ex 50$ in € \" where $ and € are currency names. \"ex\" means exchange rate.";
advconfigstring="Currency Converter Mini";
readmestring="Currency Converter Mini";
iconfilename="favicon.ico";

aliasstr="ex";
regexstr="^ex ((?:\d|\.|\,|\w|€|£|\$| )*) $";
scriptregex=/^ex (\d(?:\d|\.|\,|\w|€|£|\$| )*) $/;
regexfilterstr="";
keywordstr="";
scorestr="300";

// type
UNKNOWN=0; FILE=1; FOLDER=2; ALIAS=3; URL=4; PLUGIN=5; CLIP=5;
// Postprocessing
IMMEDIATE_DISPLAY=0; ADDSCORE=1; MATCH_AGAINST_SEARCH=2;
// search state
STOPPED=0; SEARCHING=1;

var pre_string = "{\\rtf1\\ansi\\ansicpg1250\\deff0\\deftab709{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}{\\colortbl ;\\red255\\green0\\blue0;}{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard\\lang2057\\f0\\fs18 ";
var post_string = "\\par\n}";

var exrate = "";

function doQuery(querykey,querynokeyword){

querynokeyword = querynokeyword.replace(/,/g,'.');

// if non-digit, then assume custom currency input
// so google entire string if structured "111aaa in bbb "
//    else do nothing

var xtest = querynokeyword.search(/\D/g);
if (xtest != -1) {

var xtest = querynokeyword.search(/\d[^ ]*? (?:|[^ 0-9]*? )(?:|[^ 0-9]*? )in [^ 0-9]*?(?: [^ 0-9]*?|)/g);
// finds matches for:
// "ex 10$ in € "
// "ex 10 $ in € "
// "ex 10 swedish money in american money "

if (xtest == -1) {
  FARR.setStrValue("window.richeditmode",display);
 return;
}

  var url = "http://www.google.com/search?hl=en&q="+querynokeyword;
  var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");

  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4) {
      var string = xmlhttp.responseText;
      string = string.match(/><b>\d.*?[^<(?:f|b)]*? = \d.*?<\/b>/g);
      string = string[0].replace(/<[^>]*?>/g,"");
      string = string.replace(/>/g,"");
      string = string.replace(/&#215;/g,"x");

      FARR.setStrValue("statusbar","Currency Converter Mini");
      FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
      }
    }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);

return;
}
//-----------------------------------


FARR.setStrValue("window.richeditmode","");

if(exrate == ""){
  var url = "http://www.google.com/search?hl=en&q=1"+myinputcurrency+"+in+"+myoutputcurrency;
  var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");

  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4) {
      var string = xmlhttp.responseText;
      string = string.match(/<b>1 .*? = (?:\d|\.|\,)*? /g);
      var splitstring = string[0].split("=");
      var exrate = splitstring[1].slice(1,-1);
      string = exrate * querynokeyword;
      string = Math.round(string);
      string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
      FARR.setStrValue("statusbar","Currency Converter Mini");
      FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
      }
    }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}
else {
var string = exrate * querynokeyword;
string = Math.round(string);
string = querynokeyword+" "+myinputcurrency+" = "+string+" "+myoutputcurrency;
FARR.setStrValue("statusbar","Currency Convert Mini");
FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
}

}

myinputcurrency="";
myoutputcurrency="";
function onOptionsChanged() {
    var options=new ActiveXObject("MSXML2.DOMDocument");
    options.load(currentDirectory+"\\options.xml")
    myinputcurrency=options.selectSingleNode("options/myinputcurrency").getAttribute("value");
    myoutputcurrency=options.selectSingleNode("options/myoutputcurrency").getAttribute("value");
}

function onInit(c) {
    currentDirectory=c;

    var options=new ActiveXObject("MSXML2.DOMDocument");
    if(!options.load(currentDirectory+"\\options.xml") ||
        options.selectSingleNode("options/myinputcurrency").getAttribute("value")=='' ||
        options.selectSingleNode("options/myoutputcurrency").getAttribute("value")=='') {
        options.loadXML("<options>\n"+
                        "<myinputcurrency label='exchange from :' value=''/>\n"+
                        "<myoutputcurrency label='exchange to :' value=''/>\n"+
                        "</options>");

        options.save(currentDirectory+"\\options.xml");
        options=null;
        FARR.showOptions();
    } else {
        onOptionsChanged();
    }
}



function onSearchBegin(querykey, explicit, queryraw, querynokeyword) {
  if(!explicit) {
    if(aliasstr.indexOf(querynokeyword)!=-1) {
      FARR.setState(querykey,1);
      FARR.emitResult(querykey,aliasstr, aliasstr, iconfilename,ALIAS,IMMEDIATE_DISPLAY,300);
      FARR.setState(querykey,0);
    }
    return;
  }
  FARR.setStrValue("statusbar","Currency Converter Mini");

    display = pre_string+"Type amount and hit \\b space\\b0"+post_string;

var xtest = queryraw.search(/(?:\d\D| \D)/g)
if (xtest != -1)
    display = pre_string+"use google syntax:  ex 100$ in € "+post_string;
  FARR.setStrValue("window.richeditmode",display);
}

function onRegexSearchMatch(querykey,querynokeyword) {
  var match_reg = querynokeyword.match(scriptregex);
  doQuery(querykey,match_reg[1]);
}

lanux128, I don't really have time to add the RatesFx at the moment. Hopefully someone else does.
« Last Edit: June 23, 2008, 06:47:50 AM by Nod5 » Logged
Enzomaticus
Supporting Member
**
Posts: 12

View Profile Give some DonationCredits to this forum member
« Reply #14 on: July 22, 2008, 09:27:53 AM »

Did this ever get put into a proper plugin package? Or am I just to dumb to find it?
Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #15 on: July 22, 2008, 04:37:13 PM »

You're right, Enzomaticus, it didn't.
But you can use Google Calculator to do exactly the same.
For example, to get dollar to euro, just type the following in farr:
gcal 1euro in usd
Logged

Enzomaticus
Supporting Member
**
Posts: 12

View Profile Give some DonationCredits to this forum member
« Reply #16 on: July 22, 2008, 06:30:44 PM »

Brilliant! Thank you.
Logged
Nod5
Supporting Member
**
Posts: 725



View Profile Give some DonationCredits to this forum member
« Reply #17 on: August 10, 2008, 08:07:40 PM »

CurrencyConverterMini v1.03.01
http://nod5.dcmembers.com...urrencyconvertermini.html
Changelog:
fixed error with , or . in search.
removed conversion rate cache.

I hope I did a correct plugin pack. If not, let me know.
Also, is it ok if I rename this thread to "CurrencyConverterMini (plugin)"?
Logged
mouser
First Author
Administrator
*****
Posts: 33,185



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #18 on: October 21, 2008, 06:05:29 AM »

sorry for the late reply, nice work  thumbs up
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.08s | Server load: 0.01 ]