ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > FARR Plugins and Aliases

Definr.com plugin - closed

<< < (3/5) > >>

mouser:
enter would be best i think, ive got a stack of todo items for FARR that i really need to get working on.

Nod5:
czechboy,
I've now testdriven the plugin some more. The searches are not always incredibly fast, despite what definr.com claim. Pretty often they take several seconds.

I found a similarly clean site, http://ninjawords.com/ , that seems faster (at least from my location). We're only talking slightly faster, but still. So I tried to learn from your fscript.js to grab definitions from ninjawords.com instead. The resulting code follows below. Do you spot any errors? It at least seems to run ok but I don't really know javascript or the FARR javascript SDK so there might be errors. The many replace functions look very messy but I'm not sure how to simplify them.

Also, a general question (maybe mouser or someone else can answer this too): is it possible to make some phrases in the grabbed text into hyperlinks when displayed in FARR?

edit: I tweaked it some more so that it now supports multiple lookups at once. Just type "nw word1,word2 " (see http://ninjawords.com/info/about/ for more on that)


--- ---// plugin script :
displayname="ninjawords.com";
versionstring="1.0.0";
releasedatestring="21.2.2008";
author="nod5 (based on Definr plugin by Oldrich Svec)";
updateurl="";
homepageurl="";
shortdescription="ninjawords.com";
longdescription="defines words through http://ninjawords.com";
advconfigstring="ninjawords.com";
readmestring="ninjawords.com";
iconfilename="";

aliasstr="nw";
regexstr="^nw (.*?) $";
scriptregex=/^nw (.*?) $/;
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}";

function doQuery(querykey,querynokeyword){
    var url = "http://ninjawords.com/"+querynokeyword;
    var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");
    xmlhttp.onreadystatechange = function(){
      if (xmlhttp.readyState == 4) {
        var string = xmlhttp.responseText;
string = string.replace(/\n/g,'\\par');
var splitString = string.split('<dt class="title-word">');
       
        var string ="";

for ( var i=1, len=splitString.length; i<len; ++i ){

    if (i > 1) {
               string +="\\par -----------------------------\\par ";
               }
        splitString[i] = splitString[i].replace(/<\/dl>.*?$/,"");
splitString[i] = splitString[i].replace(/<dd.*?>/g,'\\doublepar ');
        splitString[i] = splitString[i].replace(/ :<\/span>/g,": ");
splitString[i] = splitString[i].replace(/more&raquo;/g,'');
splitString[i] = splitString[i].replace(/&mdash;/g,'-');
        splitString[i] = splitString[i].replace(/<.*?>/g,"");
splitString[i] = splitString[i].replace(/\t/g,'');
splitString[i] = splitString[i].replace(/\\par\s*?(\S)/g,'\\par$1');
splitString[i] = splitString[i].replace(/\\par/g,'');
splitString[i] = splitString[i].replace(/\\doublepar/g,'\\par\\par');
string += splitString[i];
}
         
        FARR.setStrValue("statusbar","Define");
        FARR.setStrValue("window.richeditmode",pre_string+string+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","Define");
  FARR.setStrValue("window.richeditmode",pre_string+"Type what you want to search and hit Space"+post_string);
}

function onRegexSearchMatch(querykey,querynokeyword) {
  FARR.setStrValue("statusbar","Define");
  FARR.setStrValue("window.richeditmode",pre_string+"Please wait..."+post_string);
  var match_reg = querynokeyword.match(scriptregex);
  doQuery(querykey,match_reg[1]);
}

czb:
Hi,
realy cool ;) I will use this website instead :up:
I have also tried to write my own script (for comparative reasons, so that we can learn from each other) and here it is:
function doQuery(querykey,querynokeyword){
    var output="";
    var url = "http://ninjawords.com/"+querynokeyword;
    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.match(/<dl class="word" id="word-.*?">.*?<\/dl>/g);
         for(k=0;k<string.length;k++){
          heading = string[k].match(/<dt class="title-word">.*?<a href=.*?>(.*?)<\/a>.*?<\/dt>/);
          if(heading && heading[1])
            output += "\\b "+heading[1]+"\\b0\\par\\par\n";
          var body = string[k].match(/<dd class="entry.*?">.*?<\/dd>/g);
          if(body)
            for(i = 0;i<body.length;i++){
              body = body.replace(/<a title="synonyms">more&raquo;<\/a>/g,"");
              output += body.replace(/<.*?>/g,"")+"\\par\\par\n";
            }
          else output = "Nothing found";
        }
        FARR.setStrValue("statusbar","Define");
        FARR.setStrValue("window.richeditmode",pre_string+output+post_string);
      }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}
--- End quote ---

I must say, that I am NOT coder either. FARR JS plugins are nearly my first touch of JS ;) So I am not the right person to revise your code :-[ But it works perfectly :Thmbsup:

As to hyperlinks: I have tried to use hyperlinks in RTF but it does not display them as hyperlinks. So I guess we have to wait till there will be HTML support in FARR ;)

EDIT: just one remark. Are you goining to publish this ninjawords plugin (so that others can use it too), or shall I do it?

Nod5:
czechboy,
It's better that you do it since I based my version on your code and you have a page set up already.

I'm myself more and more convinced that ninjawords is better than definr. It is noticeably faster from my location. It also gives definitions that are shorter and more to the point (which is almost always enough). It also allows multiple lookups in one search. The only drawback I can find with ninjawords is that it gives errors when the search phrase contains dots (try searching for "i.e."). I'll email the ninjawords dev about that.

Perhaps in the future your plugin could be expanded with some option where the user can choose what definition site to use (Definr, ninjawords, possibly others...)? Since some might still prefer definr.

I also must make a general exclamation: these javascript plugins (and the underlying javascript SDK) has really opened up my eyes to how great FARR can be at interacting with the web (doing queries, grabbing content...).  :Thmbsup:

czb:
Ok, I will do it. I also think that in JS there is a huge potential. It is easy to learn and you can do anything :)
I also thought about making a plugin which would extract from any site content according to provided XML. You would provide URL and XML like that:

--- Code: Text ---<?xml version="1.0" encoding="windows-1250"?><feed>  <match what="<span style="font-size:1\.2em">(.*?)<\/span>">    <couple>      <first>          <match what="<strong>(.*?)</strong>">          </match>      </first>      <second>          <match what="</b>(.*?)<b>" modifiers="g">            <replace what="<.*?>" with="">            </replace>          </match>      </second>    </couple>  </match>  <match what="<table cellpadding=0 cellspacing=0 border=0>(.*?)</table>">    <match what="<td align=left valign="top" width="30%">(.*?)</td>" modifiers="g">      <couple>        <first what="<strong>(.*?)</strong>">        </first>        <second what="</b>(.*?)<b>" list="list">          <replace what="<.*?>" with="">          </replace>        </second>      </couple>    </match>  </match></feed>and it would display a content to you. But it seams as complex problem and I am not sure, I have enough skills to code it...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version