Wanted buttons at the bottom of comics...

Everything else.

Moderator: GreenCrayon

Post Reply
ph3rny
Posts: 1
Joined: Thu May 17, 2012 11:09 pm

Wanted buttons at the bottom of comics...

Post by ph3rny »

... so I wrote a greasemonkey script and thought I'd share if anyone else felt the same way...

I've only tested in firefox, but it should be easily adaptable to other browsers:

Code: Select all

// ==UserScript==
// @name        SMBC Buttons
// @description Adds the next/previous/random buttons at the bottom
// @include     http://www.smbc-comics.com/*
// @version     1
// ==/UserScript==

(function() {
    'use strict';

    var nextButtons = document.querySelectorAll('img[usemap="#buttons"]')[0],
        lineBreak = document.createElement('br'),
        newNextButtons = nextButtons.cloneNode(true),
        comicTable = nextButtons.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling;

    // make sure nothing is wrong
    if (!nextButtons || !comicTable || comicTable.nodeName.toUpperCase() !== 'TABLE') {
        alert('something went wrong');
    }

    // insert a line break first
    comicTable.parentNode.insertBefore(lineBreak, comicTable.nextSibling);

    // then a copy of the buttons image
    comicTable.parentNode.insertBefore(newNextButtons, comicTable.nextSibling);

} ());

User avatar
Sandwiches
[Insert In Mouth]
Posts: 202
Joined: Fri Apr 13, 2012 10:01 am

Re: Wanted buttons at the bottom of comics...

Post by Sandwiches »

Well done very creative

although you can use z,x,c as back, random, forward. Maybe that is even more convenient than your script.

User avatar
sotic
[Insert Here]
Posts: 325
Joined: Thu Aug 04, 2011 5:55 am
Location: Wisconsin
Contact:

Re: Wanted buttons at the bottom of comics...

Post by sotic »

Code: Select all

(function() {
    'use strict';
Huh, I didn't know Javascript had this. Neat :)

Code: Select all

    var nextButtons = document.querySelectorAll('img[usemap="#buttons"]')[0],
        // ...
        comicTable = nextButtons.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling;
I can't think of a better way to do this, but if the page's DOM layout ever changes you'll have to figure out how many siblings to skip over again. For the time being, comicTable = nextButtons.parentNode.childNodes[4] would be more readable. And you could even say var parent = nextButtons.parentNode, comicTable = parent.childNodes[4]; then you would have a direct reference to use down here instead of comicTable.parentNode:

Code: Select all

    // insert a line break first
    comicTable.parentNode.insertBefore(lineBreak, comicTable.nextSibling);

    // then a copy of the buttons image
    comicTable.parentNode.insertBefore(newNextButtons, comicTable.nextSibling);
This is bad commenting. Not terrible or malicious, thanks to the simple nature of the problem, but good statements and variable names speak for themselves. Superfluous commenting is just another opportunity to confuse the reader if anything changes later.

Anyway, it gets the job done and I don't see room for error--alert()s are obnoxious but it seems like that one'll come up only when the DOM layout changes. But the z, x and c keys work just as well if you're using a Qwerty keyboard.
Wind catches lily / Scatt'ring petals to the wind: / Segmentation fault

User avatar
Lethal Interjection
Death by Elocution
Posts: 8048
Joined: Wed Oct 12, 2005 2:17 pm
Location: Behind your ear. It's magic!
Contact:

Re: Wanted buttons at the bottom of comics...

Post by Lethal Interjection »

sotic wrote: But the z, x and c keys work just as well if you're using a Qwerty keyboard.
Damn my choice of the Dvorak Simplified!

User avatar
RussellBrand
Posts: 2
Joined: Wed Aug 29, 2012 5:37 am

Re: Wanted buttons at the bottom of comics...

Post by RussellBrand »

The Bizzaro World, also known as Htrae (Earth in reverse) is a square planet that is populated by twisted types of Superman and his other DC universe friends. Some indicators of financial health sound like they would make a good deal more sense on Htrae. Here is a survey of some. Get a payday loan to get by while the economy recovers. It is very hard to spend a lot of money right now especially if you don't have enough savings. If you need to pay your other bills as well, you should try availing a payday loan right away.

Post Reply