Thread Navigating by Arrow keys

Use ← or → and Ctrl to navigate to previous, next, first or last page

  1. // ==UserScript==
  2. // @name Thread Navigating by Arrow keys
  3. // @name:vi Thread Navigating by Arrow keys
  4. // @namespace https://gf.qytechs.cn/scripts/6849-thread-navigating-by-arrow-keys
  5. // @description Use ← or → and Ctrl to navigate to previous, next, first or last page
  6. // @description:vi Use ← or → and Ctrl to navigate to previous, next, first or last page
  7. // @author theheroofvn
  8. // @include /^.*(thread|forum|diendan).*$/
  9. // @include http://www.vn-zoom.com/*
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
  11. // @noframes
  12. // @grant GM_addStyle
  13. // @version 6.8
  14. // ==/UserScript==
  15.  
  16. $(document).ready(function () {
  17. $(window).focus();
  18.  
  19. function custom_site(list) {
  20. if (list.length === 0) return 0;
  21. for (var i = 0; i < list.length; i++) {
  22. if (location.hostname == list[i].host) {
  23. prev = list[i].prev;
  24. next = list[i].next;
  25. first = list[i].first;
  26. last = list[i].last;
  27. up = list[i].up;
  28. return 1;
  29. }
  30. }
  31. return 0;
  32. }
  33.  
  34. function checkScriptExist(script) {
  35. return $('script[src*="' + script + '"]').length > 0 ? true : false;
  36. }
  37.  
  38. function detect_forum() {
  39. if (window.location.hostname === 'forum.xda-developers.com') {
  40. return 'vbb';
  41. }
  42.  
  43. let result = "";
  44.  
  45. if (checkScriptExist("vbulletin")) result = "vbb";
  46. else if (checkScriptExist("/js/xf/")) result = "xenforo";
  47. else if (checkScriptExist("general.js")) result = "mybb";
  48. else if (checkScriptExist("forum_fn.js")) result = "phpbb";
  49.  
  50. return result;
  51. }
  52.  
  53. var prev, next, first, last, up, up_sub = '[itemtype="https://schema.org/BreadcrumbList"] a';
  54. var site_info = [
  55. {
  56. host: "voz.vn",
  57. prev: "a.pageNav-jump--prev",
  58. next: "a.pageNav-jump--next",
  59. first: ".pageNav-main>.pageNav-page:first-child>a",
  60. last: ".pageNav-main>.pageNav-page:last-child>a"
  61. }
  62. , {
  63. host: "www.webtretho.com",
  64. prev: "a.arrowPrePage",
  65. next: "a.arrowNextPage",
  66. first: "a.arrowFstPage",
  67. last: "a.arrowLstPage"
  68. }, {
  69. host: "forum.bkav.com.vn",
  70. prev: "a.js-pagenav-prev-button",
  71. next: "a.js-pagenav-next-button",
  72. first: "a[data-page='1']",
  73. last: "a.js-pagenav-button:nth-last-child(2)",
  74. up: "#breadcrumbs a.crumb-link"
  75. }
  76. ];
  77.  
  78. if (custom_site(site_info) === 0) {
  79. switch (detect_forum()) {
  80. case 'vbb':
  81. prev = 'a[rel="prev"]';
  82. next = 'a[rel="next"]';
  83. first = 'a[rel="start"], a[rel="first"]';
  84. last = 'a[title^="Last"], a[title*="uối"]';
  85. up = "span.navbar a, li.navbit a";
  86. break;
  87. case 'xenforo':
  88. prev = "a.pageNav-jump--prev";
  89. next = "a.pageNav-jump--next";
  90. last = ".pageNav-main > .pageNav-page:last-child > a";
  91. first = '.pageNav-main > .pageNav-page:first-child > a';
  92. // up = ".p-breadcrumbs";
  93. break;
  94. case 'mybb':
  95. prev = "a.pagination_previous";
  96. next = "a.pagination_next";
  97. first = "a.pagination_first";
  98. last = "a.pagination_last";
  99. up = ".navigation > a";
  100. break;
  101. case 'phpbb':
  102. prev = ".display-options a.left-box.left";
  103. next = ".display-options a.right-box.right";
  104. first = ".pagination > span > a:first-child";
  105. last = ".pagination > span > a:last-child";
  106. up = ".navlinks > .icon-home a";
  107. break;
  108. default:
  109. return;
  110. }
  111. }
  112.  
  113. var nav = {
  114. prev: function () {
  115. return $(prev);
  116. },
  117.  
  118. next: function () {
  119. return $(next);
  120. },
  121.  
  122. first: function () {
  123. if ($(first).length > 0) {
  124. return $(first);
  125. } else {
  126. var $prev = $(prev).first();
  127.  
  128. if ($prev) {
  129. $prev.attr('href', function (_, value) {
  130. return value.replace(/page=\d+/, 'page=1');
  131. });
  132.  
  133. return $prev;
  134. } else {
  135. return $();
  136. }
  137. }
  138. },
  139.  
  140. last: function () {
  141. if ($(last).length > 0) {
  142. return $(last);
  143. } else {
  144. var $next = $(next).first();
  145.  
  146. if ($next) {
  147. $next.attr('href', function (_, value) {
  148. return value.replace(/page=\d+/, 'page=9999');
  149. });
  150.  
  151. return $next;
  152. } else {
  153. return $();
  154. }
  155. }
  156. },
  157.  
  158. up: function () {
  159. return $(up).length > 0 ? $(up).last() : $(up_sub).last();
  160. }
  161. };
  162.  
  163. var allowed = true;
  164.  
  165. $(document).keydown(function (e) {
  166. if (!allowed) {
  167. return;
  168. }
  169.  
  170. allowed = false;
  171.  
  172. var key = e.keyCode,
  173. action = null;
  174.  
  175. if (e.ctrlKey) {
  176. allowed = true;
  177. if (key == 39) action = "last";
  178. else if (key == 37) action = "first";
  179. else if (key == 8) action = "up";
  180. } else if (key == 39) {
  181. action = "next";
  182. } else if (key == 37) {
  183. action = "prev";
  184. } else {
  185. return;
  186. }
  187.  
  188. if (!action || e.target.tagName == "INPUT" || e.target.tagName == "TEXTAREA" || e.target.isContentEditable) {
  189. return;
  190. }
  191.  
  192. var $anchor = nav[action]();
  193.  
  194. if ($anchor.length) {
  195. window.location.href = $anchor[0].href;
  196. }
  197. }).keyup(function (e) {
  198. allowed = true;
  199. });
  200. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址