WebNovel Nav Arrows

Bind arrow keys (left/right) to Previous/Next Chapter links

  1. // ==UserScript==
  2. // @name WebNovel Nav Arrows
  3. // @description Bind arrow keys (left/right) to Previous/Next Chapter links
  4. // @version 1.1.2
  5. // @author PixelTech
  6. // @license MIT
  7. // @namespace https://greasyfork.org/en/scripts/406139-webnovel-nav-arrows
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var Key = {
  16. LEFT: "ArrowLeft",
  17. RIGHT: "ArrowRight"
  18. };
  19.  
  20. var prev_link, next_link;
  21. var host = window.location.host;
  22. var pathname = window.location.pathname;
  23. var path = pathname.substring(0,pathname.lastIndexOf("/"));
  24. var subdomain = host.split ('.')[1];
  25.  
  26. if (subdomain.length <= 3) {
  27. var subdomain = host.split('.')[0]
  28. }
  29.  
  30. // For Debug
  31. console.log("WebNovel Nav Arrows --- Detected Host: " + host);
  32. console.log("WebNovel Nav Arrows --- Subdomain Match: " + subdomain);
  33. console.log("WebNovel Nav Arrows --- Pathname Match: " + path);
  34.  
  35. if (subdomain.includes("wuxiaworld")) {
  36. var l = document.querySelectorAll("next > a");
  37. var i = l.length;
  38. for (i = 0; i < l.length; i++) {
  39. if (String(l[i]).includes(path)) {
  40. next_link = l[i];
  41. console.log("WebNovel Nav Arrows --- Next Link: " + next_link); // For Debug
  42. }
  43. }
  44. var l = document.querySelectorAll("prev > a");
  45. var i = l.length;
  46. for (i = 0; i < l.length; i++) {
  47. if (String(l[i]).includes(path)) {
  48. prev_link = l[i];
  49. console.log("WebNovel Nav Arrows --- Prev Link: " + prev_link); // For Debug
  50. }
  51. }
  52. }
  53.  
  54. if (!subdomain.includes("wuxiaworld")) {
  55. var l = document.getElementsByTagName('a'); //Find all links
  56. var i = l.length;
  57. for (i = 0; i < l.length; i++) {
  58. if ((l[i].innerHTML.match(/Next*/) || l[i].innerHTML.match(/NEXT*/)) && String(l[i]).includes(path)) { //Match iterations that contain Next* IF that iteration includes the matching domain (helps with redirected WordPress sites)
  59. next_link = l[i];
  60. console.log("WebNovel Nav Arrows --- Next Link: " + next_link); // For Debug
  61. }
  62. if ((l[i].innerHTML.match(/Prev*/) || l[i].innerHTML.match(/PREV*/) || l[i].innerHTML.match(/Last*/)) && String(l[i]).includes(path)) { //Match iterations that contain Prev* or Last* IF that iteration includes the matching domain (helps with redirected WordPress sites)
  63. prev_link = l[i];
  64. console.log("WebNovel Nav Arrows --- Previous Link: " + prev_link); // For Debug
  65. }
  66. }
  67. }
  68.  
  69. //-- Should override any keybinds set by site or browser
  70. function handleKeyboardEvent(event) {
  71. switch (event.key){
  72. case Key.LEFT:
  73. prev_link.click();
  74. break;
  75. case Key.RIGHT:
  76. next_link.click();
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82.  
  83. document.addEventListener('keydown', handleKeyboardEvent, true); //
  84.  
  85. })();