by | ritz |
---|
ok, so how does it work?
When you type an URL starting with javascript: in your browser, the browser will interpret the line as a piece of javascript. using this technique you can do things to the current webpage [or document, as it is called in javascript] like changing the url in certain ways, or compiling the information in a different way.
a small, and well-known example is:
javascript:alert(document.lastModified);
this small script brings up a messabox displaying the time and date the document was last modified.. good for evaluating the site you are looking at, for example.
there are basically three ways of implementing these small javascripts, or bookmarklets as they are called sometimes:
the BIG (magic) meat (October 2004)
This is an "ad hoc" solution found by ~S~ Ritz on our Seekers' msgboard. It began like this...javascript:
var clicks=1;
function info(x){
if(clicks!=0) window.status='click to delete '+x.srcElement.tagName+', shift+click to stop the killing.';
};
function del(x){
if(clicks!=0 && !x.shiftKey){
x.srcElement.setAttribute('style','display:none');
window.status=x.srcElement.tagName+' deleted.';
} else {
clicks=0;
window.status='';
};
};
window.status='busy..';
a=document.getElementsByTagName('*');
for(i=0; a.length!=i; i++){
a.item(i).onclick=del;
a.item(i).onmouseover=info;
};
window.status='done. hide any document element by clicking on it. shift+click to abort.';
void(0);
javascript:
var lastEL=document.body;
var lastStyle=document.body.getAttribute('style');
var EL_KILLA=1;
function hover(x){
e=x.srcElement;
if(EL_KILLA){
window.status='press DEL to delete '+e.tagName+', ESC to cancel.';
lastEL.setAttribute('style',lastStyle);
lastEL = e;
lastStyle = e.getAttribute('style');
e.setAttribute('style', 'border:2px dashed red');
}
};
function key(x){
k = x.keyCode;
if(k==27){
EL_KILLA=0;
window.status='';
lastEL.setAttribute('style',lastStyle);
}
if(k==0 && EL_KILLA){
lastEL.setAttribute('style',lastStyle='display:none');
window.status=lastEL.tagName+' deleted.';
}
};
window.status='busy..';
document.onkeypress=key;
a=document.getElementsByTagName('*');
for(i=0; a.length!=i; i++){
a.item(i).onmouseover=hover;
};
window.status='done. point and press DEL on any element. ESC to cancel.';
void(0);
the (rest of) the meat
Ok, here follows a list of javascript-oneliners i've developed so far, copy, bookmark, whatever, abuse for your own pleasure.. some of these might be stolen from bookmarklets.com but i've only included the scripts that could be used for our purposes here.. please check out their site if you want more bookmarklets [i didn't get all of them to work in Opera, though.]
javascript:void(location.href='http://' + location.host + '/robots.txt')
display robots.txt for this domain.
javascript:if(document.Cracker.length<1){alert('No cookie for this site.')}else{zz=prompt('Cookie for this site:',document.Cracker)}
display cookie for this site
javascript:location.href+='&num=100'
google 100 results. changes the url line so google will give 100 results instead of whatever you have now.
javascript:location.search+='&filter=0'
google no filter. changes the url so google will "repeat the search with the omitted results included."
javascript:location.search+='&filter=0&num=100'
combines the two previous scripts :)
javascript: location.href='http://translate.google.com/translate?u='+location.href+'&hl=en'
automatic google translator. google autodetects the source language if you omit the &sl= tag, so all you have to do is run this script over any site in any language google understands to translate it to english. ofcourse you can change &hl=en to any other destination language instead of english.
javascript:a0=prompt('two-letter source language code:'); location.href='http://world.altavista.com/urltrurl?lin='+a0+'&lout=en&url='+location.href
altavista translator. i couldn't get altavista to autodetect the source language, so the user is prompted for it. it still saves time, compared to loading bablefish..
javascript:ttt314=prompt('Highlight words on this site:','');ttt314=ttt314.replace(/\s/g,'+');location.href='http://www.google.com/search?q=cache:'+location.href+'+'+ttt314;
google cache highlight. prompts the user for a set of words to highlight, and looks the current page up in google's cache, with those words highlighted.
javascript: location.href='http://spireproject.com/cgi-bin/footnote.pl?form=2&page='+escape(prompt('URL:',''));
pseudo-proxy. of course you can modify this script to work for any "proxy" site that works in this manner. you are prompted for the url.
javascript: location.href='http://spireproject.com/cgi-bin/footnote.pl?form=2&page='+escape(location.href);
automatic pseudo-proxy. the user is not prompted, but instead the current url is used.
javascript:aaa314='<html><body>';for(xxx314=0; xxx314<document.links.length; xxx314++){aaa314+='<img src='+document.links[xxx314]+'><br>';};document.write('<center>'+aaa314+'</center></body></html>');void(document.close());
show pictures. makes a new html-pages, that solely consists of <img>-tags. every link on the source page is turned into an <img>-tag, no matter whether it is an actual image or not. very useful if you find an open directory and quickly want to check out all the pictures inside it. [hello pr0n searchers :-P]
javascript:zepp=prompt('cookiestring? [ex: cookieName=cookieValue]','');document.Cracker = zepp;
add cookie. prompts the user for the cookiestring, and then sets the according cookie. good to circumvent pages with
very stupid login-protections.
(ahem :-)
javascript:blarg=prompt("unescape what?", ""); xxxx=prompt("okay y0!", unescape(blarg));
unescape. to convert escaped strings to readable text. use this to read those redirection urls full of http%3A// stuff..
javascript:blarg=prompt("escape what?", ""); xxxx=prompt("ok4y y0!", escape(blarg));
escape. to convert characters that are illegal in URLs or whatever, to escaped strings.. useful for messing up scripts and forms
[making them accept strings they weren't meant to accept :) ]
(ahem :-)
javascript:href7=location.href;qsplit7=href7.split("?"); asplit7=qsplit7[1].split("&"); for(ind7=0; ind7<asplit7.length&&asplit7[ind7].charAt(0)!="q"; ind7++);clean7=prompt("this be cleaned url", qsplit7[0]+"?"+asplit7[ind7]);location.href=(clean7==null)?href7:clean7;
google url cleaner. this is a MUST for all you people posting on ~S~ board!! :) it strips the current URL [assuming that it is from google] to everything but the bare http://www.google.com/search?q=qxapoiu . makes the url much clearer to read and who needs all that &hl=en&lr=&ie=ISO-8859-1 crap anyway?
Well that's all the javascript-oneliners i've made until now.. every once in a while i think of something new "that should be simpler using javascript" .. perhaps i will post my new findings on ~S~ board, or i will write an additional essay.. anyway, i hope i have given you a nice taste of the power of in-url javascript, so if you have coded a cool piece of bookmarklet, please let me know about it :)