Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 11-20 of 21 total

Russian to English translation bookmarklet

Put this bookmarklet (favelet) in the Bookmarks Toolbar of your browser (Firefox or IE). Then translate any Russian page with it.

javascript:Qr=location.href;location.href='http://www.systranbox.com/systran/box?systran_id=SystranSoft-en&systran_charset=UTF-8&systran_text=&ttype=url&systran_url='+escape(Qr)+'&systran_lp=ru_en'

YubNub Bookmarklet

// description of your code here
This works with the site yubnub.org. First highlight some text, then click the bookmarklet. A dialogue box pops up to ask the YubNub command to be used. It then performs that command on the highlighted text.
javascript:q = "" + (window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text); p = prompt("Yubnub search type? ... ", ""); if (q!=null) location="http://yubnub.org/parser/parse?command=" + escape(p).replace(/ /g, "+") + " " + escape(q).replace(/ /g, "+"); void 0

hide visited link bookmarklet

For IE
javascript:document.createStyleSheet().addRule("a:visited","display:none");void(0);


For Firefox/Opera
javascript:(function(){var css=document.createElement("link");with(css){setAttribute("rel","stylesheet");setAttribute("type","text/css");setAttribute("href","data:text/css,"+encodeURIComponent("a:visited{display:none}"))}document.getElementsByTagName("HEAD")[0].appendChild(css)})();

show images in web directory list

I was tired of found lots of images in a directory, and click in each one to see if someone of these are really cool are soooo dirty.

I wrote this bookmarklet, that create a new document with all the images opened in a table.
NSF56k but nice.

javascript:function showallimagesindirectory(){var s='test';var dc='<b>Images in: '+location.href+'</b><table border=1 style=\'font:x-small verdana\'>';for(var i=0;i<document.links.length;i++){s=document.links[i].href;if(s.toUpperCase().lastIndexOf('.JPG')!=-1 || s.toUpperCase().lastIndexOf('.JPEG')!=-1 || s.toUpperCase().lastIndexOf('.GIF')!=-1 || s.toUpperCase().lastIndexOf('.PNG')!=-1){dc+='<tr>';dc+='<td><img src='+s+'>&nbsp;</td>';dc+='</tr>';}}dc+='</table>';var iw=window.open('','iw','');iw.document.open();iw.document.write(dc);iw.document.close();}showallimagesindirectory();


enjoy!

go to specific del.icio.us tags directly

This is a bookmarklet i've wrote to quickly go to specific tag from people on del.icio.us.

In example you want to go to http://del.icio.us/tag/games
just click bookmarklet, write "games" and let's go!

javascript:(function(){javascript:var i=prompt('Tag?');if(i)document.location='http://del.icio.us/tag/'+i;})();


enjoy!

bookmarklet include javascript

javascript:(function(){var s=document.createElement("script");s.charset="UTF-8";s.src="http://example.com/example.js";document.body.appendChild(s)})();

It's cool!!!

dictionary: english &lt;-> german (dict.leo.org)

javascript:q = "" + (window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text); if (!q) q = prompt("Enter a phrase:", ""); if (q!=null) location="http://dict.leo.org/?search=" + escape(q).replace(/ /g, "+"); void 0

Amazon Statistically Improbable Phrases Search Bookmarklet

javascript:q=document.getSelection();for(i=0;i<frames.length;i++){q=frames[i].document.getSelection();if(q)break;}if(!q)void(q=prompt('Statistically Improbable Phrase:',''));if(q)location.href='http://www.amazon.com/gp/phrase/'+escape(q)+'/ref=sip_bod_0/103-6410487-8187016'

Finding pdf paper from CiteULike

I use CiteULike (http://citeulike.org) to manage papers a lot.
Unfortunately, I don't have access to paid site. But some authors
are generous enough to put pdf on his own site, which I find
using google search.
javascript:(function(){
var title = document.title.substring(11);
var query = '%22' + title + '%22 ' + 'filetype:pdf';
var url = 'http://www.google.com/search?q=' + encodeURI(query);
window.open(url);
})();


It simply takes the paper title from windows title. Then it searches the title(enclosed in quotation) for pdf files of the same name.

Change Gmail encoding to display thai.

Some emails send from yahoo and hotmail will display thai incorrectly. This bookmarklet re-encode it by shifting the unicode numbers. Can be applied to some language whose encoding is in the same "shifting" order.
javascript:(function(){  map=[];for(i=161;i<251;i++)map[i]=String.fromCharCode(i+3424);  function thai(s){s2='';for(var i=0;i<s.length;i++){n=s.charCodeAt(i);if(n>160&&n<251) s2+=map[n];else s2+=s.charAt(i)}return s2}   function rc_thai(el){if(el.nodeType== 3){el.data=thai(el.data);return} if(el.tagName == 'SCRIPT') return; for (var i=0; i<el.childNodes.length; i++) rc_thai(el.childNodes[i])}   for(i=0;i<4;i++){if(fi=window.frames[0].frames[i].document.getElementById('fi')) break}  rc_thai(fi); })();

The one-liner version above maybe difficult to read.
Here's a reorganized one
javascript:(function(){
map=[];
/* create conversion table */
for(i=161;i<251;i++) {
  map[i]=String.fromCharCode(i+3424);
}

function thai(s){
  s2='';
  for(var i=0;i<s.length;i++){
    n=s.charCodeAt(i);
    if(n>160&&n<251) 
      s2+=map[n];
    else 
      s2+=s.charAt(i)
  }
  return s2
}   

/* recursively convert encoding of sub-element */
function rc_thai(el){
  if(el.nodeType== 3){
    el.data=thai(el.data);
    return
  } 
  if(el.tagName == 'SCRIPT') 
    return; 
  for (var i=0; i<el.childNodes.length; i++)
    rc_thai(el.childNodes[i])
}   

/* finding the content element in sub-sub-frame */
for(i=0;i<4;i++){
  if(fi=window.frames[0].frames[i].document.getElementById('fi'))
    break
}  

/* change that element (and all its descendants */
rc_thai(fi); 
})();
« Newer Snippets
Older Snippets »
Showing 11-20 of 21 total