Skip to content

Instantly share code, notes, and snippets.

@justan
Created June 19, 2012 13:44
Show Gist options
  • Select an option

  • Save justan/2954287 to your computer and use it in GitHub Desktop.

Select an option

Save justan/2954287 to your computer and use it in GitHub Desktop.
a bookmarklet for emule search selected text
//bookmarklet
//javascript:(function(a){var b,c=a.selection,a=a.activeElement,d=top.getSelection,e=a&&a.selectionEnd;e?b=a.value.substring(a.selectionStart,e):d&&(b=d()+"");c&&(b=c.createRange().text);b&&(location="ed2k://|search|%s|/".replace(/%s/,b))})(document);
//origin code
(function(doc){
var text,
IEselection = doc.selection,
activeEle = doc.activeElement,
getSelection = top.getSelection,
selectionEnd = activeEle && activeEle.selectionEnd;
selectionEnd ?
(text = activeEle.value.substring(activeEle.selectionStart, selectionEnd)) : //input / textarea
getSelection && (text = getSelection() + '');
IEselection && (text = IEselection.createRange().text);
if(text){
location = 'ed2k://|search|%s|/'.replace(/%s/, text);
}
})(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment