Thursday, October 15, 2009

Most Excellent JavaScript Codes EVER! And I HATE when people type words in all uppercase just to emphasize a point! But this is WORTH IT!


So, my first non-introductory post here will knock off the Programming/Web Design section, though it is more scripting than either of those. But that's okay.

Anyway, this is for those who have not already seen these, though they have appeared in several different blogs and posts all over the Interwebs. I'm probably posting them mostly just so that I don't forget about them.

If you've done any kind of hacking or Web Security work, you probably know that you can use JavaScript in the Address Bar to do cool stuff, such as
javascript:alert(document.cookie);

which will bring up an alert box with the current page's cookies. There are a lot of really cool things you can do with JavaScript injections like that. Today, I rediscovered one of my old favorites, and from there made a few new awesome discoveries, one of which being the coolest thing I have ever seen done with JavaScript.

  • My old favorite, the universal page editor:
    javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

    This will allow you to edit the web page you are viewing, move and resize pictures, change some text, etc. It won't permanently change the page on the server, so don't go thinking "Oh, man! I can totally hack anything now!", because you can't. Not with this. It is fun to use, however, if a roommate or coworker steps away from their computer for a minute or two with a webpage open. =D

  • The next one I found, the Window Shaker:
    javascript:function Shw(n) {if (self.moveBy) {for (i = 35; i > 0; i--) {for (j = n; j > 0; j--) {self.moveBy(1,i) ;self.moveBy(i,0);self.moveBy(0,-i);self.moveBy(-i,0); } } }} Shw(6)

    This one is just plain fun. For any developers out there, include this as a part of any javascript app you design. It'll get great reviews.

  • Finally, the all-time coolest thing you can do with address bar JavaScript, The Content Spinner:
    javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);

    This one will grab elements off the page and spin them in circles! It's so cool! Right now the above code, as is, is set to spin images. go to Google Images and search for... whatever, paste this in the address bar, and watch the magic happen! It also works well on Facebook, specifically on the news feed, where there are lots of pictures. If you study the code, you will find the little chunk DI=document.getElementsByTagName("img");. By changing the phrase inside the parenthesis to a, p, li, h1, input, etc, you can change what part of the page is spinning! (Can you tell I'm excited?) I think img is the coolest, but that's just me. Oh, another thing: this tends to eat up memory, especially when you do something involving text, so the spinning mass of characters will eventually become choppy and freeze up. When this happens, I've found that you can jiggle the mouse to keep things moving. Just refresh the page when you get tired of it. It'll go back to the normal page.

So those are all of the really cool ones that do graphical, visible stuff. There's a few others that are more useful than aesthetic:
  • javascript:alert(document.forms[0].to.value="something") - This will allow you to change the value passed to a script by a form.

  • javascript:void(document.bgColor="blue") - This specifically changes the background color, but if you know what you are doing, you can use a void() function in this format to change any value on the page.

  • javascript:alert("The actual URL is:\t\t" + location.protocol + "//" + location.hostname + "/" + "\nThe address URL is:\t\t" + location.href + "\n" + "\nIf the server names do not match, this may be a spoof."); - This little number can be useful if you think a site is a scam site imitating another. use this to display what the site really is and what it claims to be side by side, so you can tell for sure. (source: http://www.daniweb.com/forums/thread165903.html)


And these are just a taste of what you can do with JavaScript in your address bar. To find out more, just Google "JavaScript injections".



Today's quote:
"Once I am officially regional manager... I will need a new 'number two'. My ideal choice? Jack Bauer. But he is unavailable, fictional, and overqualified."
                                                   - Dwight Schrute, The Office

No comments:

Post a Comment