Created
March 15, 2012 17:30
-
-
Save Zirak/2045479 to your computer and use it in GitHub Desktop.
QC scripty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//a script I hacked together in 10 minutes for easily reading Questionable Content: | |
// http://questionablecontent.net | |
//A and D keys, and their corresponding arrow keys, for movement between comic strips | |
//don't be alarmed if the image is a broken one, wait some more. if the script really failed | |
//to load a comic strip, it alerts a message | |
var s = document.getElementById( 'strip' ).cloneNode(), | |
l = document.createElement( 'p' ), | |
acts = [], | |
id = s.src.match( /\d+/ )[ 0 ]; | |
s.width = 700; | |
s.onload = function () { | |
l.textContent = ''; | |
window.scroll( 0 ); | |
}; | |
s.onerror = function () { | |
var exts = [ 'png', 'gif', 'jpg' ], | |
srcExt = this.src.split( '.' ).reverse()[ 0 ], | |
idx = exts.indexOf( srcExt ); | |
console.log( srcExt, idx, exts[idx+1] ); | |
if ( idx === exts.length-1 ) { | |
alert( 'I IZ BROKE' ); | |
} | |
else { | |
refresh( exts[idx + 1] ); | |
} | |
}; | |
//A and left-arrow | |
acts[ 'A'.charCodeAt(0) ] = acts[ 37 ] = function () { id-- }; | |
//D and right-arrow | |
acts[ 'D'.charCodeAt(0) ] = acts[ 39 ] = function () { id++ }; | |
[].slice.call( document.body.children ).forEach(function ( c ) { | |
document.body.removeChild( c ); | |
}); | |
document.body.appendChild ( l ); | |
document.body.appendChild( s ); | |
window.addEventListener( 'keyup', function ( e ) { | |
if ( acts[e.which] ) { | |
l.textContent = 'Loading...'; | |
acts[ e.which ](); | |
localStorage.lastID = id; | |
refresh(); | |
} | |
}); | |
function refresh ( ext ) { | |
ext = ext || 'png'; | |
s.src = 'http://questionablecontent.net/comics/' + id + '.' + ext; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment