SMBC Navigation Improvements

Adding keyboard navigation, aftercomic text just displayed, and aftercomic image is a link to the next comic.

  1. // ==UserScript==
  2. // @name SMBC Navigation Improvements
  3. // @namespace http://userscripts.org/users/Scuzzball
  4. // @description Adding keyboard navigation, aftercomic text just displayed, and aftercomic image is a link to the next comic.
  5. // @include http://www.smbc-comics.com/*
  6. // @version 1.0
  7. // ==/UserScript==
  8.  
  9. function getNextAndPrevious() {
  10. var areas = document.getElementsByTagName("area");
  11. var links = [];
  12. for (var i = 0, len = areas.length; i < len; ++i) {
  13. if (areas[i].coords == "351,21,425,87") {//Next coordinates. Uses one bloody image for navigation, and linkes based on coordinates in the image. CAUSE THAT"S A GOOD WAY TO DO IT.
  14. links["next"] = areas[i].href;
  15. }
  16. if (areas[i].coords == "131,13,216,84") { //Previous coordinates
  17. links["previous"] = areas[i].href;
  18. }
  19. }
  20. return links;
  21. }
  22.  
  23.  
  24.  
  25. var links = getNextAndPrevious();
  26.  
  27. document.getElementById('refbox').parentNode.parentNode.childNodes[0].innerHTML='<a href="' + links['next'] + '"><img src="' + document.getElementById('aftercomic').childNodes[1].src + '"></a>'; //This is shenanagans to get the aftercomic image displayed. 'refbox' is the only ID near where I want to display it.
  28.  
  29. function leftArrowPressed() {
  30. window.location = links['previous'];
  31. }
  32.  
  33. function rightArrowPressed() {
  34. window.location = links['next'];
  35. }
  36.  
  37. document.onkeydown = function(evt) {
  38. evt = evt || window.event;
  39. switch (evt.keyCode) {
  40. case 37:
  41. leftArrowPressed();
  42. break;
  43. case 39:
  44. rightArrowPressed();
  45. break;
  46. }
  47. };