topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Tuesday April 16, 2024, 4:59 pm
  • Proudly celebrating 15+ 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: Definr.com plugin - closed  (Read 28469 times)

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Definr.com plugin - closed
« on: February 18, 2008, 03:07 AM »
This topic has been discontinued.
See:
https://www.donation...ex.php?topic=17153.0
My open-source online piano game: https://github.com/musicope/game
« Last Edit: February 23, 2009, 09:49 AM by czb »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Definr.com plugin
« Reply #1 on: February 18, 2008, 03:15 AM »
nice!!!!!

ps. attention all plugin authors, please attach a screenshot when you post about your plugin, so i can more easily add it to the plugin list page:
https://www.donation...user/findrun/addons/
« Last Edit: February 18, 2008, 03:17 AM by mouser »

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #2 on: February 18, 2008, 03:30 AM »
Just an idea... could you please create any general CMS addons system (like firefox, miranda and others have)?
Now it is like that every coder has its own webpage.
My open-source online piano game: https://github.com/musicope/game

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #3 on: February 18, 2008, 03:37 AM »
This is very nice CMS for addons example:
http://extensions.se...ices.openoffice.org/
it is based on Drupal ;)
My open-source online piano game: https://github.com/musicope/game

Dr-Leech

  • Member
  • Joined in 2006
  • **
  • Posts: 151
  • Psychedelic Coder
    • View Profile
    • site
    • Donate to Member
Re: Definr.com plugin
« Reply #4 on: February 18, 2008, 08:27 AM »
Drupal projects is awesome.. also let you keep track of releases and issues.

taichimaster

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 160
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #5 on: February 19, 2008, 03:37 AM »
Cool!!!  I think this one is actually the most useful out of all your plugins!!!  Thanks.  *off to donate!*

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #6 on: February 20, 2008, 01:56 PM »
Nice work czechboy! Very useful plugin!  :Thmbsup:

A small suggestion: it takes me more time to find the "," key compared to the space key. I managed to tweak your fscript.js so that "df football " triggers the search instead of "df football,". The plugin can still look up definitions for space separated phrases: "df foul ball ". It starts to search for "foul" but interrupts that when new non-space characters are entered and then searches the whole phrase "foul ball" when the next space is entered. I hope you'll consider using space for triggering the search in your official version.

I just changed:
regexstr="^df (.*?),$";
scriptregex=/^df (.*?),$/;
To:
regexstr="^df (.*?) $";
scriptregex=/^df (.*?) $/;

edit: I also decreased the font size (from f26 to f18) to lessen the number of linebreaks in the definition texts

« Last Edit: February 20, 2008, 02:05 PM by Nod5 »

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #7 on: February 21, 2008, 03:37 AM »
Good idea ;) I will change it to the space as well :)
As to decreasing font size... I think, that each person might like different height. I will consider adding some option to the advanced plugin setting, but probably I will wait till new version of Javascript SDK is out where, hopefully, there will be more options for advanced plugin setting ;)
My open-source online piano game: https://github.com/musicope/game

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Definr.com plugin
« Reply #8 on: February 21, 2008, 10:24 AM »
 = character would be good since its same as used with calc maybe?

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #9 on: February 21, 2008, 12:22 PM »
I very much prefer using space as a final character, since on my keyboard, = is only accessible through a shift-combo :)
That's what i'm using with gcalc currently ;)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Definr.com plugin
« Reply #10 on: February 21, 2008, 02:32 PM »
enter would be best i think, ive got a stack of todo items for FARR that i really need to get working on.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #11 on: February 21, 2008, 04:20 PM »
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]);
}

« Last Edit: February 21, 2008, 05:37 PM by Nod5 »

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #12 on: February 22, 2008, 02:12 AM »
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);
}

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?
My open-source online piano game: https://github.com/musicope/game
« Last Edit: February 22, 2008, 02:17 AM by czechboy »

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #13 on: February 22, 2008, 04:08 AM »
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:
« Last Edit: February 22, 2008, 04:12 AM by Nod5 »

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #14 on: February 22, 2008, 04:36 AM »
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 [Select]
  1. <?xml version="1.0" encoding="windows-1250"?>
  2. <feed>
  3.   <match what="<span style="font-size:1\.2em">(.*?)<\/span>">
  4.     <couple>
  5.       <first>
  6.           <match what="<strong>(.*?)</strong>">
  7.           </match>
  8.       </first>
  9.       <second>
  10.           <match what="</b>(.*?)<b>" modifiers="g">
  11.             <replace what="<.*?>" with="">
  12.             </replace>
  13.           </match>
  14.       </second>
  15.     </couple>
  16.   </match>
  17.   <match what="<table cellpadding=0 cellspacing=0 border=0>(.*?)</table>">
  18.     <match what="<td align=left valign="top" width="30%">(.*?)</td>" modifiers="g">
  19.       <couple>
  20.         <first what="<strong>(.*?)</strong>">
  21.         </first>
  22.         <second what="</b>(.*?)<b>" list="list">
  23.           <replace what="<.*?>" with="">
  24.           </replace>
  25.         </second>
  26.       </couple>
  27.     </match>
  28.   </match>
  29. </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...
My open-source online piano game: https://github.com/musicope/game

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #15 on: February 22, 2008, 07:14 AM »
I just tried your version of the Ninjawords script. It did not run here. After entering the search string I get "please wait..." and then nothing happens. Not sure why. Does it work for you? I updated my version some more based on your code (simplified the replace steps, made each search phrase bold). Feel free to use it.
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|\t/g,'');
var splitString = string.split('<dt class="title-word">');
       
        var string ="";

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

    if (i > 1) {
               string +="\\par -----------------------------\\par ";
               }
splitString[i] = "\\b " + splitString[i]
        splitString[i] = splitString[i].replace(/<\/dl>.*?$/,"");
splitString[i] = splitString[i].replace(/<dd.*?>/g,'\\b0 \\par\\par ');
        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,"");
string += splitString[i];
}
         
        FARR.setStrValue("statusbar","Define");
        FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
      }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

I forgot to mention one more advantage with Ninjawords: if you spell a word wrong it automatically guesses the word and shows the definition - try "nw footbaall ". Definr on the other hand shows a list of terms and forces the users to choose one.

As for that XML thing I think I understand what you mean. Promising. I can already think of several websites that I'd want FARR to grab specific content from and display to me in an instant. But I'm not sure if people will prefer that over site specific plugins. And I don't know how to write XML so I can't help much I'm afraid.

edit: I now saw that you created a new thread ( https://www.donation...ex.php?topic=12421.0 ). The ninjawords version on your page does return definitions. But I think there is some error in the parsing code. Try "nw test,gone " and "nw gone,test ". In the first case, the bold "gone" is missing. In the second case, both "gone" and it's definition is missing. I'm not sure what the cause of that is.
« Last Edit: February 22, 2008, 07:43 AM by Nod5 »

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #16 on: February 22, 2008, 07:32 AM »
Ok I have updated to your version :Thmbsup: Thanks for pointing out ;)

btw: ninjawords really seams promising :)

EDIT: If you wanted to make it even faster you can try this url:
http://ninjawords.co...initions/getdef/test
instead. It is what ninjawords.com uses to send ajax reguest ;)
My open-source online piano game: https://github.com/musicope/game
« Last Edit: February 22, 2008, 07:37 AM by czechboy »

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #17 on: February 22, 2008, 07:43 AM »
Great. I'll try it now.  edit: works fine"  :Thmbsup:

Two more things:
- the ninjawords plugin page says "nw - to start Definr plug-in" when you really mean "nw - to start Ninjawords plug-in".
- note that: "nw school, wall " is not needed for multiple lookups. "nw school,wall " is enough. That way the plugin accesses the Ninjawords site only once compared to twice.

Using http://ninjawords.co...initions/getdef/test from the beginning would probably have been best, but I'm not sure if its needed now.
How many milliseconds do you think we'll save by using it? ;D
« Last Edit: February 22, 2008, 07:49 AM by Nod5 »

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #18 on: February 22, 2008, 07:55 AM »
You are right :-[
All suggestions corrected (hopefully) :)
My open-source online piano game: https://github.com/musicope/game

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Definr.com plugin
« Reply #19 on: February 22, 2008, 08:29 AM »
I gave the alternative page for grabbing the definitions ( http://ninjawords.co...initions/getdef/test ) a go after all. Do you notice any difference in speed? Also, since the definitions are grabbed blazingly fast, maybe it's best to remove the "Please wait..." text completely? It just causes FARR to flicker a very brief moment but is almost not readable.

edit: this cuts off some words it seems, will troubleshoot that later. edit2: works now, I earlier forgot to escape \ at one place
function doQuery(querykey,querynokeyword){
  var url = "http://ninjawords.com/definitions/getdef/"+querynokeyword;
  var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");
  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4) {
      var string = xmlhttp.responseText;
      string = string.replace(/\\n|\\t/g,'');
      var splitString = string.split('\\074dt class=\\"title-word\\"\\076');
      var string ="";
      for (var i=1;i<splitString.length; ++i){
        if (i > 1) {
          string +="\\par -----------------------------\\par ";
        }
        splitString[i] = "\\b " + splitString[i];
        splitString[i] = splitString[i].replace(/", query: ".*?$/,"");
        splitString[i] = splitString[i].replace(/\\074dd.*?\\076/g,'\\b0 \\par\\par ');
        splitString[i] = splitString[i].replace(/ :\\074\/span\\076/g,": ");
        splitString[i] = splitString[i].replace(/\\074div class=\\"examples\\"\\076/g,"\. ");
        splitString[i] = splitString[i].replace(/\\074.*?\\076/g,"");
        splitString[i] = splitString[i].replace(/\\u2014/g,"-");
        splitString[i] = splitString[i].replace(/\\u2019/g,"'");
        splitString[i] = splitString[i].replace(/&mdash/g,"-");
        splitString[i] = splitString[i].replace(/more&raquo;\,/g,"");
        string += splitString[i];
      }
      FARR.setStrValue("statusbar","Define");
      FARR.setStrValue("window.richeditmode",pre_string+string+post_string);
      }
    }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}
« Last Edit: February 22, 2008, 09:47 AM by Nod5 »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Definr.com plugin
« Reply #20 on: February 22, 2008, 08:44 AM »
you could put the please wait in the status bar.

ps. i've added to my todo list to try to be smarter about resizing the window to avoid the flicker.

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: Definr.com plugin
« Reply #21 on: February 22, 2008, 09:51 AM »
I have tried to leave "please wait" in status bar but it is not visible either... so I will erase it completely and update the plugin.
Btw: I must say that the upload plugin saves me a lot of time! Uploading new version takes 1-2seconds 8)

Offtopic:
I can see your todo list is getting pretty loooooong :P Is it only you programming FARR? I wonder is FARR opensource, so that anybody can help a little? :)
My open-source online piano game: https://github.com/musicope/game
« Last Edit: February 22, 2008, 09:53 AM by czechboy »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Definr.com plugin
« Reply #22 on: February 22, 2008, 10:53 AM »
it's only me.
FARR is not open source unfortunately :(  most of my big programs aren't.  it's something i'd like to do more of once i can convince myself it wouldn't make donations go from very little to even less :)

the main reason the todo list is getting so long is because i've been working on a paid job for the last couple of months and will be on it for another 2 months full time.  so i only have a little bit of time here and there.

BUT after i get a little break in april or so, i'm really looking forward to getting back and doing a lot of work on FARR and a few others, as well as a couple more programs i am interested in writing.  so until DC becomes a full time job, i have to take breaks now and then to pay the bills.

it does have the advantage though of having the ideas have time to marinate a little and see the patterns in the requests.

so please everyone who is waiting for new features and fixes keep in mind that FARR development has not slowed, i just have to work on it in bursts with some delays for now.

icekin

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 264
    • View Profile
    • icekin.com Technology,Computers and the Internet
    • Read more about this member.
    • Donate to Member
Re: Definr.com plugin
« Reply #23 on: February 25, 2008, 06:52 PM »
I created a folder called Definr inside plugins and then extracted the files into that folder before exiting and restarting FARR. I got the following error.

[attachimg=#1][/attachimg]

[attachimg=#2][/attachimg]