Return to Snippet

Revision: 7490
at November 5, 2009 09:54 by wizard04


Updated Code
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();
	}
})()

Revision: 7489
at August 12, 2008 14:15 by wizard04


Updated Code
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}window.open('http://www.ninjawords.com/'+getQ(window.top))})();

//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;
	}
	window.open('http://www.ninjawords.com/'+getQ(window.top));
})();

Revision: 7488
at July 31, 2008 09:18 by wizard04


Updated Code
javascript:(function(){function t(f){if(f.getSelection)return f.getSelection().toString();if(f.document.selection)return f.document.selection.createRange().text;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}window.open('http://www.ninjawords.com/'+getQ(window.top))})();

//Here it is expanded so you can read it:
javascript:(function(){
	function t(f)	//get the selected text in frame f
	{
		if(f.getSelection) return f.getSelection().toString();
		if(f.document.selection) return f.document.selection.createRange().text;
		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;
	}
	window.open('http://www.ninjawords.com/'+getQ(window.top));
})();

Revision: 7487
at July 31, 2008 09:13 by wizard04


Updated Code
javascript:(function(){function t(f){if(f.getSelection)return f.getSelection().toString();if(f.document.selection)return f.document.selection.createRange().text;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}window.open('http://www.ninjawords.com/'+getQ(window.top))})();

//Here it is expanded so you can read it:
javascript:(function(){
	function t(f)
	{
		if(f.getSelection) return f.getSelection().toString();
		if(f.document.selection) return f.document.selection.createRange().text;
		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;
	}
	window.open('http://www.ninjawords.com/'+getQ(window.top));
})();

Revision: 7486
at July 25, 2008 22:25 by wizard04


Updated Code
javascript:(function(){function t(f){if(f.getSelection)return f.getSelection().toString();if(f.document.selection)return f.document.selection.createRange().text;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}window.open('http://www.ninjawords.com/'+getQ(window.top))})();

Revision: 7485
at July 25, 2008 21:46 by wizard04


Initial Code
javascript:(function(){function getSel(frm){var str=frm.getSelection().toString().replace(/^[^a-z0-9-]+|[^a-z0-9-]+$/ig,"").replace(/[^a-z0-9-]+/ig, ",");var s="";for(var i=0;i<frm.length;i++){s=getSel(frm[i]);if(s)str+=(str?",":"")+s;}return str;}var q=getSel(window.top);if(q)window.open("http://www.ninjawords.com/"+q);})();

Initial URL

                                

Initial Description
Select some text, click the bookmarklet, and the definition(s) will open up in [Ninjawords](http://www.ninjawords.com).

[Ninjawords](javascript:(function(&#41;{function%20t(f&#41;{try{if(f.getSelection&#41;return%20f.getSelection(&#41;.toString(&#41;;if(f.document.selection&#41;return%20f.document.selection.createRange(&#41;.text}catch(e&#41;{}return%20''}function%20getQ(f&#41;{var%20q=t(f&#41;.replace(/^[^a-z0-9-]+|[^a-z0-9-]+$/ig,''&#41;.replace(/[^a-z0-9-]+/ig,%20','&#41;;var%20s='';for(var%20i=0;i<f.length;i++&#41;{s=getQ(f[i]&#41;;if(s&#41;q+=(q?',':''&#41;+s}return%20q}if(window.location.hostname!='ninjawords.com'&#41;window.open('http://ninjawords.com/'+getQ(window.top&#41;&#41;;else{document.getElementById('q'&#41;.value%20=%20getQ(window.top&#41;;Ninjawords.textboxQuery(&#41;}}&#41;(&#41; "Drag this into your bookmarks!")

Initial Title
Ninjawords Bookmarklet

Initial Tags
javascript

Initial Language
JavaScript