Page 1 of 1

Wanted buttons at the bottom of comics...

Posted: Thu May 17, 2012 11:29 pm
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);

} ());

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

Posted: Thu May 17, 2012 11:58 pm
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.

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

Posted: Fri May 18, 2012 2:22 am
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.

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

Posted: Fri May 18, 2012 2:57 am
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!

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

Posted: Wed Aug 29, 2012 5:55 am
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.