30
\$\begingroup\$

Sometimes people get frustrated on the StackExchange network (specifically SO).

stackoverflow logo modified

Your task is to create a bookmarklet that causes StackOverflow to explode/implode/destroy in some fashion. This will provide a nicer way of dispersing our frustrations.

The Rules:

  • it must be in the form of a bookmarklet
  • must work in Chrome and Firefox (latest stable)
  • jQuery is on the site, so you can use it
  • no creating a script tag that pulls explosionThisPage.js or similar

Scoring is the number of characters that need to be copied and pasted, except:

  • -1 if you include an explanation
  • -5 for each upvote
  • -10 if you don't use jQuery
  • -10 if it makes an explosion sound
  • +9e72 if it actually does harm to the site (F5 should repair the damage)

If the gif's distracting, remove it.

\$\endgroup\$
8
  • 7
    \$\begingroup\$ IMO the spec isn't sharp enough for an objective determination of whether a submission meets it. \$\endgroup\$ Commented Aug 20, 2013 at 12:33
  • \$\begingroup\$ in a comment, as it's not mine: javascript: varwww_WHAK_com = 'http://www.is-a-jerk.com/flash/url.asp?flash=10&insult=off&destroy=' + encodeURIComponent(top.location.href.replace('http://', '').replace('https://', '')); top.location.href = www_WHAK_com; void(0); \$\endgroup\$
    – SeanC
    Commented Aug 20, 2013 at 13:20
  • 1
    \$\begingroup\$ My comment wasn't about the scoring system but about the task specification. \$\endgroup\$ Commented Aug 20, 2013 at 14:57
  • 4
    \$\begingroup\$ Really? That should be minus 9*10**72 points if it actually manages to cause harm to the site, and then repair it when the user reloads the page. That would be quite a feat. \$\endgroup\$ Commented Feb 10, 2014 at 11:41
  • 2
    \$\begingroup\$ @FakeRainBrigand IMO, causing real harm to the site that is somehow repaired upon reloading is far more impressive than simply causing harm to the site. \$\endgroup\$ Commented Feb 11, 2014 at 16:43

11 Answers 11

29
\$\begingroup\$

Here's my entry, which I'll call the drunkenator:

javascript:void(setInterval(function(){c='1234567890poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP=)(/&%25$%23"!1';$(':not(iframe,script,style)').contents().each(function(){if(this.nodeType==3&&/\S/.test(this.nodeValue)){a=this.nodeValue.split('');x=0;for(i=0;i<a.length;i++){r=Math.random()*9999;if(r<10){x=1;j=c.indexOf(a[i]);a[i]=(r<4%3F(t=a[i-1],a[i-1]=a[i],t):r<5%3F'':r<6%3Fa[i]+a[i]:j<0%3Fa[i]:c.charAt(j+(r<8%3F1:-1)))}}if(x)this.nodeValue=a.join('')}})},100))

At 474 chars, it's probably not going to win any golf prizes, but I'm hoping to make up for it in upvotes. :)

Here's the same code de-obfuscated:

setInterval(function () {
  var c = '1234567890poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP=)(/&%$#"!1';
  $(':not(iframe,script,style)').contents().each(function () {
    if (this.nodeType==3 && /\S/.test(this.nodeValue)) {
      var a = this.nodeValue.split('');
      var x = 0;
      for (i = 0; i < a.length; i++) {
        r = Math.random() * 9999;
        if (r < 10) {
          x = 1;
          j = c.indexOf(a[i]);
          a[i] = ( r < 4 ? (t = a[i-1], a[i-1] = a[i], t)
                 : r < 5 ? ''
                 : r < 6 ? a[i] + a[i]
                 : j < 0 ? a[i] : c.charAt(j + (r < 8 ? 1 : -1)) ); 
        }
      }
      if (x) this.nodeValue = a.join('');
    }
  });
}, 100);

What it does is randomly mutate the text on the page, swapping adjacent characters, deleting or duplicating characters or replacing them with ones adjacent to them on the keyboard. The effect is kind of subtle at first, but leave it running for a while, and the page content will inevitably decay into a mess of drunken typing:

Go home, SO, you're drunk!

Ps. The code isn't in any way SO-specific, so it'll work on any website that uses jQuery. Try it on Wikipedia for hilarious results. The idea is based on something I wrote years ago as a creative interpretation of the "99 bottles of beer" challenge: my version introduced a slowly increasing number of typos into each verse, until the last ones were all but unrecognizable. If anyone wants to see it, here's the original Perl code.

\$\endgroup\$
1
  • 6
    \$\begingroup\$ More lide the Dyslexinator (sorru, i'm typping while it's ruqning) \$\endgroup\$
    – TheDoctor
    Commented Feb 15, 2014 at 23:37
27
\$\begingroup\$

Chicken!

Score: 46 - 1 (explanation) - 5*17 (votes) = -40

javascript:$('*:not(:has(*))').text('chicken')

It simply takes every element with no children and replaces it with the text 'chicken'.

Sample screenshots:
more chicken
this question chickenified

image

\$\endgroup\$
8
  • \$\begingroup\$ Awesome idea :-) It's also interesting to see things like "answered chicken" or the page title, which have non-chicken words... Why? \$\endgroup\$
    – Brigand
    Commented Oct 14, 2013 at 20:19
  • \$\begingroup\$ @FakeRainBrigand Huh? The page title becomes "chicken" for me... \$\endgroup\$
    – Doorknob
    Commented Oct 14, 2013 at 20:32
  • \$\begingroup\$ Longer but more thorough version, partially based on my entry: javascript:void($(':not(iframe,script,style)').contents().each(function(){if(this.nodeType==3)this.nodeValue=this.nodeValue.replace(/\w+/g,'chicken')})) \$\endgroup\$ Commented Dec 13, 2013 at 17:30
  • \$\begingroup\$ @Doorknob, congrats, you had a score of 15, which was the lowest (sorry it took me so long to accept one). If I could do it over again, though, I'd make a vote worth -15, though. \$\endgroup\$
    – Brigand
    Commented Feb 11, 2014 at 15:34
  • 1
    \$\begingroup\$ Should have been HODOR! \$\endgroup\$
    – SztupY
    Commented Feb 15, 2014 at 21:31
16
\$\begingroup\$

I don't know why this was downvoted, I like it :)

This isn't the shortest, but I think it's pretty:

133 chars -1

javascript:(function(){setInterval(function(){$("div, span").eq(Math.round(Math.random()*$("div, span").length)).hide(500)},90)}());

Ungolfed:

javascript:(function(){  
         window.setInterval(function() {
                 i = Math.round(Math.random() * $("div, span").length);
                 $("div, span").eq(i).hide("slow");
         } , 90);
}());

Explanation: I hope this counts, this script implodes the site instead of exploding it ;) This just picks a random div or span every 90ms and closes it slowly..

\$\endgroup\$
3
  • \$\begingroup\$ +1 but the random() isn't efficient for a full and controlled destroy, anyway I like it :) \$\endgroup\$ Commented Oct 17, 2013 at 12:28
  • \$\begingroup\$ Just threw it into the URL window, and nothing's happened,,,? \$\endgroup\$ Commented Dec 16, 2013 at 0:22
  • \$\begingroup\$ Sorry Wally, didn't see your comment. You need to save it as a bookmark. \$\endgroup\$
    – Fels
    Commented Feb 12, 2014 at 8:44
11
\$\begingroup\$

Because it was not defined if the higher or lower score wins...

javascript:$(".vote-down-off").click()

Base: 38
Bonis:

  • +9e72 Permanent damage.

Final score: 9000000000000000000000000000000000000000000000000000000000000000000000038

Btw, I did not try it.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ haha By the way, if you ask JavaScript: 9e72+38 === 9e72 :-) \$\endgroup\$
    – Brigand
    Commented Aug 20, 2013 at 13:48
  • 3
    \$\begingroup\$ Who asks javascript? Use jQuery. \$\endgroup\$ Commented Aug 20, 2013 at 13:52
  • 16
    \$\begingroup\$ i.sstatic.net/sGhaO.gif :D \$\endgroup\$
    – Doorknob
    Commented Aug 20, 2013 at 16:57
  • 4
    \$\begingroup\$ Err ... should I vote down or up...? \$\endgroup\$ Commented Feb 11, 2014 at 19:34
  • 1
    \$\begingroup\$ Oh, I get it... it clicks the buttons with class "vote-down-off" if you use it. It's code-challenge tagged, which implies that lowest score wins. \$\endgroup\$
    – Nzall
    Commented Feb 18, 2014 at 15:39
8
\$\begingroup\$

My pupose 245 chars.

Mostly not the shorter, but I like it ;-)

javascript:document.body.innerHTML+='<img%20id="bigMsk"%20src="https://i.sstatic.net/VWPZg.gif">';document.getElementById('bigMsk').setAttribute('style','z-index:1;opacity:.6;display:block;position:fixed;top:0;left:0;width:100%;height:100%;');

-1: Explanation:

  • I use the nice offered animated gif image from question,
  • With the help of CSS, I put them over the page in full page, with a 60% opacity.

:

document.body.innerHTML+=
   '<img%20id="bigMsk"%20src="https://i.sstatic.net/VWPZg.gif">';
document.getElementById('bigMsk').setAttribute('style',
    'z-index:1;
     opacity:.6;
     display:block;
     position:fixed;
     top:0;
     left:0;
     width:100%;
     height:100%;
');

Mostly readable by itself ;-)

-10 No JQuery

Alternative:

There is an alternative:

javascript:document.body.innerHTML+='<img%20id="bigMsk"%20src="https://i.sstatic.net/aTtWM.gif">';document.getElementById('bigMsk').setAttribute('style','z-index:1;opacity:.6;display:block;position:fixed;top:0;left:0;width:100%;height:100%;');

Based on unmodified GIF, found at Wikimedia Commons: File:Animated fire by nevit.gif

Image: Image from Wikipedia

Sample:

enter image description here

\$\endgroup\$
1
  • 1
    \$\begingroup\$ That's awesome! \$\endgroup\$
    – Brigand
    Commented Nov 13, 2013 at 3:16
5
\$\begingroup\$

Ok, I think this should meed the criteria:

javascript:document.write("<h1>Exploded</h1>")

Replaces the current page with "Exploded"

Score: 46
-1 Explaination
-10 No jQuery

35

\$\endgroup\$
0
5
\$\begingroup\$

This one's enjoyable, and causes quite a bit of lag too :D

javascript:setInterval(function(){document.body.innerHTML=document.body.innerHTML.replace(/\d+/g,function(){return Math.random()*100|0});},500)

It just sets an interval that replaces all strings of digits with a random number from 0 to 100. Twice per second. It creates a bunch of errors, as you might expect, and I could fix it to stop all the 404s when image URLs are changed, but I think it's more fun this way and it's code golf. :D

Score:

  • 132 base
  • -1 explanation
  • -5 upvote
  • -10 no jQuery

Total score: 116

\$\endgroup\$
10
  • \$\begingroup\$ Does not work in firefox. \$\endgroup\$ Commented Aug 20, 2013 at 13:47
  • \$\begingroup\$ @JohannesKuhn What does it do in FF? It works in Chrome \$\endgroup\$
    – Doorknob
    Commented Aug 20, 2013 at 13:48
  • \$\begingroup\$ Displays a blank page with a number. \$\endgroup\$ Commented Aug 20, 2013 at 13:53
  • \$\begingroup\$ @JohannesKuhn I think I fixed it; does function x(){document.body.innerHTML=document.body.innerHTML.replace(/\d+/g,function(){return Math.random()*100|0})}setInterval(x,500) work for you now? \$\endgroup\$
    – Doorknob
    Commented Aug 20, 2013 at 14:00
  • \$\begingroup\$ Yes, but a single ; at the end would do the same. \$\endgroup\$ Commented Aug 20, 2013 at 14:02
4
\$\begingroup\$

165 chars (164 points)

-1 for explaination

Here's my attempt. It's not particularly short, but it's fun.

javascript:r=Math.random;$("a,span,p").each(function(){var a=$(this);a.css({position:"relative"});a.delay(1E4*r()).animate({left:9E3*r()-4E3,top:9E3*r()-4E3},555)});

It slides individual elements off the page in random directions. I specifically included span because of the syntax highlighting (each color has a separate span).

r = Math.random;
$('a,span,p').each(function () {
    var t = $(this);
    t.css({
        position: 'relative'
    });

    t.delay(r()*10000).animate({
        left: r() * 9e3 - 4e3,
        top: r() * 9e3 - 4e3
    }, 555);
});

It of course could be shortened by removing some of the tags, but let me know if there are any ways to shorten it without reducing the performance.

\$\endgroup\$
4
\$\begingroup\$

181 151 chars - 1 (explanation) - 10 (no jQuery) = 140 points

javascript:i=setInterval(function(){for(var a=document;0!==a.childNodes.length;)a=a.childNodes[a.childNodes.length-1];a!==document?a.parentNode.removeChild(a):clearInterval(i)},50);

A few more characters can be saved by omiting the function(){ and using a string instead. Also note the extraction of commonly used properties, e.g., c='childNodes allows us to do z[c] instead of z.childNodes.

javascript:h=setInterval('d=z=document;c="childNodes";for(l="length";z[c][l];z=z[c][z[c][l]-1]);z!=d?z.parentNode.removeChild(z):clearInterval(h)',50);

I guess I could make less points by using jQuery and not traversing properties, but oh well.

Ungolfed:

var intervalHandle = setInterval(function() {
    var lastElement = document;
    //get last element
    while (lastElement.childNodes.length !== 0) {
        lastElement = lastElement.childNodes[lastElement.childNodes.length - 1];
    }

    if(lastElement !== document) {
        lastElement.parentNode.removeChild(lastElement);
    } else {
        clearInterval(intervalHandle);
    }
}, 50);

Basically this finds the latest DOM element on the page and removes it. Then keeps doing that for every 50 milliseconds, which I found to be a kind-of-average nice speed to see a page getting ripped from the ground up. It's therapeutic, I swear it.

Disclaimer: I had made this some time ago and decided to share it, since it seems appropriate here. The source is at my GitHub repository.

\$\endgroup\$
2
  • \$\begingroup\$ This is great! I edited it to include a more-golfed version that saves a few characters. I hope you don't mind. It's functionally identical. \$\endgroup\$
    – Brigand
    Commented Aug 27, 2013 at 15:25
  • \$\begingroup\$ @FakeRainBrigand Not at all, thanks! In fact, you helped me learn some new cool tricks, which was my original intention when writing it. Thanks again! \$\endgroup\$
    – Alpha
    Commented Aug 27, 2013 at 18:11
3
\$\begingroup\$

Javascript, 281

javascript:$('body').html().split('<code>javascript:').forEach(function (a) {if (a.indexOf("location")*a.indexOf("write")*a.indexOf("noscript")==-1) try{exec(a.split("</code>")[0].replace(/&#(\d+)/g, function(match, dec) {return String.fromCharCode(dec);}))} catch (e) {}});void 0;

It gets every response to the question in the form of <code>javascript:(stuff)</code> that doesn't change the location, and runs all of them.

\$\endgroup\$
2
  • \$\begingroup\$ Hmm... I can see lots of whitespace that appears to be removable. Perhaps you should remove it. \$\endgroup\$ Commented Dec 11, 2013 at 7:38
  • 3
    \$\begingroup\$ I am pretty sure this fails the rule: "no creating a script tag that pulls explosionThisPage.js or similar". Also, it doesn't work on every SO page, just this one. Also, it does real damage on questions asking about XSS, so you should add 9e72 to your score. \$\endgroup\$ Commented Dec 11, 2013 at 7:42
2
\$\begingroup\$

I like this effect. It basically toggles a slide effect for every div on the site every 1 millisecond.

javascript:setInterval(function(){$('div').toggle()},1)

Score

56
-1 Explanation
--------------
55 Total
\$\endgroup\$
1
  • \$\begingroup\$ Nice, but just toogle would work too: javascript:setInterval(function(){$('div').toggle(88)},1) \$\endgroup\$
    – Fels
    Commented Aug 20, 2013 at 19:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.