SH Arrow Key Next/Prev Chapter

Navigate to the next / previous chapter on right / left arrow keys on ScribbleHub.

安装此脚本?
作者推荐脚本

您可能也喜欢SH Continue Reading Anywhere

安装此脚本
  1. // ==UserScript==
  2. // @name SH Arrow Key Next/Prev Chapter
  3. // @namespace ultrabenosaurus.ScribbleHub
  4. // @version 0.4
  5. // @description Navigate to the next / previous chapter on right / left arrow keys on ScribbleHub.
  6. // @author Ultrabenosaurus
  7. // @license GNU AGPLv3
  8. // @source https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
  9. // @match https://www.scribblehub.com/read/*/chapter/*
  10. // @icon https://www.google.com/s2/favicons?domain=scribblehub.com
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. var consoleTitle = "SH Arrow Key Next/Prev Chapter:";
  17.  
  18. document.onkeyup = function(e){
  19. e = e || window.event;
  20. var prevSelector = "div.next_nav_links a.btn-wi.btn-prev";
  21. var prevAnchorText = "Previous";
  22. var nextSelector = "div.next_nav_links a.btn-wi.btn-next";
  23. var nextAnchorText = "Next";
  24.  
  25. //console.log(consoleTitle, e);
  26.  
  27. var commentBox = document.querySelectorAll('div#comment_placeholder.comment_placeholder');
  28. var commentEditBox = document.querySelectorAll('div.cmt_edit_chp');
  29. if( ( commentBox.length > 0 && e.target == commentBox[0] ) || ( commentEditBox.length > 0 && e.target == commentEditBox[0] ) ) {
  30. console.info(consoleTitle, "Matched a comment box, aborting chapter navigation.");
  31.  
  32. e = prevSelector = prevAnchorText = nextSelector = nextAnchorText = commentBox = null;
  33. return;
  34. }
  35.  
  36. if( e.keyCode == '37' ) {
  37. // left arrow
  38. e.preventDefault();
  39. var pLink = document.querySelectorAll(prevSelector);
  40. if( pLink.length == 0 ) {
  41. console.error(consoleTitle, "No links found for query selctor: '"+prevSelector+"'");
  42. return null;
  43. }
  44. if( pLink[0].textContent.search(prevAnchorText) >= 0 ) {
  45. console.info(consoleTitle, "Navigating to previous chapter:", pLink[0].href);
  46. pLink[0].click();
  47. } else {
  48. console.error(consoleTitle, "Link in position 0 did not contain text: '"+prevAnchorText+"'");
  49. }
  50. pLink = null;
  51. } else if( e.keyCode == '39' ) {
  52. // right arrow
  53. e.preventDefault();
  54. var nLink = document.querySelectorAll(nextSelector);
  55. if( nLink.length == 0 ) {
  56. console.error(consoleTitle, "No links found for query selctor: '"+nextSelector+"'");
  57. return null;
  58. }
  59. if( nLink[0].textContent.search(nextAnchorText) >= 0 ) {
  60. console.info(consoleTitle, "Navigating to next chapter:", nLink[0].href);
  61. nLink[0].click();
  62. } else {
  63. console.error(consoleTitle, "Link in position 0 did not contain text: '"+nextAnchorText+"'");
  64. }
  65. nLink = null;
  66. }
  67.  
  68. e = prevSelector = prevAnchorText = nextSelector = nextAnchorText = commentBox = null;
  69. };
  70. })();