Skip to main content

Wicktionary Bookmarklet

A bookmarklet is defined by Wictionary as "A small piece of JavaScript code stored as a URL within a bookmark". I have been using bookmarklets to make my life easier from a long time.

Some that I use regularly are

  1. [Read Now] : This makes it really easy for me to read pages which are unreadable.
  2. [Google Translate] : Translates pages
  3. [Mobilise This] : Formats the page for mobile viewing by Google.
  4. [Acronym lookup] : This helps me find the meanings for abbreviations.
The links in [] brackets are bookmarklets. Just drag them to your bookmark bar.

I picked these up from these two pages. There is also a whole website dedicated to them bookmarklets.

As a developer, what i like about bookmarklets is that they are coded in JavaScript and i can meddle with them till my heart's content, without worrying about breaking anything.

However, i wanted a bookmarklet that would allow me to look up meaning of words. Wiktionary was my open dictionary of choice. They did have bookmarklets, but I didn't like the way the current page was replaced by the relevant wiktionary entry. Also i didn't know what was going on inside the bookmarklet. So i wanted to (a). know what was going on? ,and (b). open the wiktionary entry in a new page.

The code of the official wiktionary bookmarklet was taken and then made into a human readable form.

javascript:(function(){
q=window.getSelection().toString();
if(!q)q=prompt('Wiktionary:');
if(q)location.href='http://en.wiktionary.org/w/wiki.phtml?search='+encodeURI(q);
})()

The first line defines that the string is a bit of javascript code. The way the function is defined; it is called an anonymous function. This is to ensure that the function does not return an undefined value ( discussed here ).

In the second line, the selected text is added as the value of a variable q after making it into a string (.toString()). The 3rd line asks us which word we want the meaning for (prompt('Wiktionary:')) if no text has been selected (if(!q)).

The 4th line: Since now the text has been selected (or entered). The relevant webpage is opened.

After doing some googling, i came up with this page that explained how the Window.open function worked just the way i wanted it to. So I changed the 4th line and my final code was:

javascript:(function(){
Q=window.getSelection().toString();
if(!Q){Q=prompt('Wiktionary:')}
if(Q){window.open('http://en.wiktionary.org/w/wiki.phtml?search='+encodeURI(Q)+'')}
})()

The website minifyjavascript.com runs a javascript minifying service. Using this I minified my code and now, proudly present the [Wiktionary] bookmarklet, featuring opening the meaning of the selected (or entered) word using wiktionary in a new browser window. Do drag away to the (bookmark) bar and use for your pleasure.

Comments

  1. Hi Trs,
    Well written article. This was a very interesting concept. Im hoping to modify ur bookmarklet and experiment with it.. definitely made browsing the net easier.. :)

    ReplyDelete
    Replies
    1. Thanks a lot dude.

      For starters, Do try looking at coding a bookmarklet for http://www.indiabookstore.net . it compares book prices including flipkart which both junglee and google dont do (a real chore, doing that). That would be really nice.

      Delete

Post a Comment

Popular posts from this blog

Yo mama so geeky : generating jokes using Markov Chains

A few days back, I saw this article “ How to fake a sophisticated knowledge of Wine with Markov Chains ” on the programming subreddit. To my utter delight, the article referenced the code, along with a very detailed explanation, so I spent an hour getting it all to work. The hour taken was no fault of the original authors, it was taken because I wanted to get a good hang of XPath, which will be the topic of a later post. The program auto-generates wine reviews, by using Markov Chains to come up with a sequence of most probable trigrams. It was great fun spouting my expert-level sommelier reviews, especially considering that I can count on one hand the number of times I have actually tasted wine! The reviews were just the right amount of ambiguous with a hint of snobbishness (which, according to me, just made the whole thing perfectly more believable). While I was showing off my new-found expertise in wines, my partner in crime,  Rupsa , told me it could probably be used for ot...

The first half of 2017 in review

Hi people, Half the year is over and i think its good to list out things, so that i have an idea as to how i am doing with my studies ( and pretty much everything else ). It's been a wonderful and fulfilling half year, to be honest. I did a lot of things I always wanted to do.  I started experimenting with hydroponics - haven't really progressed much, but I am sure I will do something substantial in the other half of the year. Benefits are a lot over traditional way, and the joy of watching your plants grow are invaluable, at the least. I read a few books on history. I have always wanted to do this , but I always had an excuse or 2 to avoid it. I finally started, and it's brought me a sense of childlike wonder, something I sorely missed. I cleaned my home! That's 20 years of procrastination right there! It was insane but I got it done. Whew! And wow!  At the beginning of the year, i finished my re-study of the CS subjects. Post February, i opened th...