Forum Moderators: open

Message Too Old, No Replies

Automatic link to Wikipedia when hover?

Looking for script that provides links to wiktionary

         

s9901470

10:30 pm on May 9, 2005 (gmt 0)

10+ Year Member



Hi

I noticed that the latest version of Trillian chat (trillian.cc) software provides definitions of words when you hover over them during chat from Wikipedia's dictionary (en.wiktionary.org/wiki/)

I was wondering if there is a javascript available that can do the same for web pages, so a page is scanned and when you hover over a word, it accesses Wikipedia and provides a definition?

Any suggestions would be welcome.

Thanks in advance

adni18

12:40 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Trillian has built-in word functions for this(ex. "C:\Program Files\Trillian\users\default\instantlookup\Hello.wik"). My guess is this could probably be done using Perl; you could make a list of words to underline, then perl would search your page for those words. It would then add a <u> tag (or something else) to them. Then, you could make a javascript application for the "hover" window and the definitions. See if your server lets you host Perl scripts.

s9901470

12:53 pm on May 11, 2005 (gmt 0)

10+ Year Member



I have Perl yes, and PHP.

But how would I know which list of words to include? Wouldn't it need to check Wikipedia somehow to see if the word was listed?

Thanks

PatrickDeese

1:21 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My personal opinion is that the wiktionary definition in trillian chat were annoying as all get out - the most useless terms were highlighted like "the", and then there were lots of instances of terms being defined as names of scandinavian rock groups.

I turned it off after 3 or 4 days.

Bernard Marx

3:04 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ola & The Janglers?

PatrickDeese

8:01 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



real example, definition of "reported"

Remixes of the Dive song "Final Report" from 1991

Really useful. :p

adni18

8:59 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, this post may need to be moved to the perl forum, but here goes the script for reading and underlining the words:

Words.txt:

banana
grapefruit
apple
grape
orange

Highlight.cgi (chmod 755 or rwxr-xr-x):

#!/usr/bin/perl

use CGI;

print new CGI->header;

my $dopage=new CGI->param("page");

if(-e $dopage && -e "Words.txt")
{
open(PAGE, $dopage);
my @pg=<PAGE>;
close(PAGE);
open(WORDS, "Words.txt");
my @words=<WORDS>;
close(WORDS);
foreach(@words)
{
$d=$_;
$d=~s/\n//g;
foreach(@pg)
{
$_ =~ s/$d/<span style="text-decoration:underline">$d<\/span>/gi;
}
}
print @pg;
}
else
{
print "Error! Page does not exist!";
}

You can use this script by viewing (from a web browser) Highlight.cgi?page=hi.html where hi.html is a saved file, presumably containing some of the words.

s9901470

11:25 am on May 12, 2005 (gmt 0)

10+ Year Member



That's great, many thanks. I'll give it a go. Does anyone know how to do this in PHP? Might need to switch forums...