Skip to content

Instantly share code, notes, and snippets.

@briankung
Last active August 29, 2015 14:15
Show Gist options
  • Save briankung/092efc3a10e1f712752c to your computer and use it in GitHub Desktop.
Save briankung/092efc3a10e1f712752c to your computer and use it in GitHub Desktop.
Keypress Navigation for Strong Female Protagonist
// ==UserScript==
// @name Strong Female Protagonist Navigator and Alt Text Reader
// @namespace https://gist.github.com/briankung/092efc3a10e1f712752c
// @version 0.0.7
// @description This lets you navigate the webcomic with the arrow keys. It will show you the mouseover text
// from the current comic before loading the next one unless you hold shift.
// @author Brian Kung
// @match http://strongfemaleprotagonist.com/*
// @grant none
// ==/UserScript==
var LEFT = 37, RIGHT = 39;
window.onkeydown = function(e) {
var prev = document.querySelector('a[rel="prev"]');
var next = document.querySelector('a[rel="next"]');
e = e || window.event;
var findImage = function(node) {
if (node.tagName === 'IMG') {
return node;
} else {
var childNodes = [].slice.call(node.childNodes);
return childNodes.reduce(
function(result,child){ return result || findImage(child) }, null
);
}
};
var comic = function() {
var article = document.querySelector('article');
return findImage(article);
}
if (e.keyCode === LEFT) {
if (prev) { location.href = prev.href }
} else if (!e.shiftKey && e.keyCode === RIGHT) {
var title = comic().title;
if (title) { alert(title) };
if (next) { location.href = next.href };
} else if (e.shiftKey && e.keyCode === RIGHT) {
if (next) { location.href = next.href }
};
};
@briankung
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment