Skip to content

Instantly share code, notes, and snippets.

@fransr
Created August 10, 2017 13:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fransr/db901674466ec5d9fe2e73da6c79818b to your computer and use it in GitHub Desktop.
Save fransr/db901674466ec5d9fe2e73da6c79818b to your computer and use it in GitHub Desktop.
Chinese whispers bookmarklet using Google Translate
javascript:(function(){function $(i,b){b=(b?b:document);return b.getElementById(i.substr(1))};var i=location.hash.substr(1).split('/')[0]||'en',a=JSON.stringify(NND).match(/[a-zA-Z-]+/g),o=i,x,p,c=0,j=$,e=0;if(i=='auto')i='en';a=[...new Set(a)],d=[i,'or','ug','tt','tk','mg','lo','rw','si','zh'];function n(v) {c++;var l=a.pop();while(l==o||d.find(function(ee){return ee==l}))l=a.pop();if(!l||c>100){if(e){j('#result_box').innerText=v;x.close();return;}else{l=i;e=1;}};console.log(o,l,v);x=window.open(location.href.split('#')[0]+'?'+Math.random()+'#'+o+'/'+l+'/'+v.replace(/ /g,'%20'),'x');o=l;p=setInterval(q,500);}function q(){if(!j('#result_box',x.document)||!j('#result_box',x.document).innerText||!j('#result_box',x.document).innerText.length)return;clearInterval(p);txt=j('#result_box',x.document).innerText;n(txt);}n(j('#source').value);})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment