/ Published in: JavaScript
Select some text, click the bookmarklet, and the definition(s) will open up in [Ninjawords](http://www.ninjawords.com).
[Ninjawords](javascript:(function(){function%20t(f){try{if(f.getSelection)return%20f.getSelection().toString();if(f.document.selection)return%20f.document.selection.createRange().text}catch(e){}return%20''}function%20getQ(f){var%20q=t(f).replace(/^[^a-z0-9-]+|[^a-z0-9-]+$/ig,'').replace(/[^a-z0-9-]+/ig,%20',');var%20s='';for(var%20i=0;i
[Ninjawords](javascript:(function(){function%20t(f){try{if(f.getSelection)return%20f.getSelection().toString();if(f.document.selection)return%20f.document.selection.createRange().text}catch(e){}return%20''}function%20getQ(f){var%20q=t(f).replace(/^[^a-z0-9-]+|[^a-z0-9-]+$/ig,'').replace(/[^a-z0-9-]+/ig,%20',');var%20s='';for(var%20i=0;i
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
javascript:(function(){function t(f){try{if(f.getSelection)return f.getSelection().toString();if(f.document.selection)return f.document.selection.createRange().text}catch(e){}return ''}function getQ(f){var q=t(f).replace(/^[^a-z0-9-]+|[^a-z0-9-]+$/ig,'').replace(/[^a-z0-9-]+/ig, ',');var s='';for(var i=0;i<f.length;i++){s=getQ(f[i]);if(s)q+=(q?',':'')+s}return q}if(window.location.hostname!='ninjawords.com')window.open('http://ninjawords.com/'+getQ(window.top));else{document.getElementById('q').value = getQ(window.top);Ninjawords.textboxQuery()}})() //Here it is expanded so you can read it: javascript:(function(){ function t(f) //get the selected text in frame f { try{ if(f.getSelection) return f.getSelection().toString(); if(f.document.selection) return f.document.selection.createRange().text; }catch(e){} //if the frame is in another domain return ''; } function getQ(f) //get the selected text in frame f and its children { //get rid of non-alphanumeric characters and separate words with commas var q = t(f).replace(/^[^a-z0-9-]+|[^a-z0-9-]+$/ig,'').replace(/[^a-z0-9-]+/ig, ','); var s = ''; for(var i=0; i<f.length; i++) //for each child frame { s = getQ(f[i]); if(s) q += (q?',':'')+s; } return q; } if(window.location.hostname != 'ninjawords.com') //if not already at ninjawords.com window.open('http://ninjawords.com/'+getQ(window.top)); else { document.getElementById('q').value = getQ(window.top); Ninjawords.textboxQuery(); } })()