SmoothScroll & Navigation Enhancer

You can quickly access the previous and next episodes, perform smooth scrolling up or down, and even enable or disable full-screen mode. This script is designed to enhance the reading experience of web content such as manga and comics in a more convenient and efficient way.

当前为 2023-10-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SmoothScroll & Navigation Enhancer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description You can quickly access the previous and next episodes, perform smooth scrolling up or down, and even enable or disable full-screen mode. This script is designed to enhance the reading experience of web content such as manga and comics in a more convenient and efficient way.
  6. // @match https://westmanga.info/*
  7. // @match https://komikcast.vip/*
  8. // @match https://aquamanga.com/read/*
  9. // @match https://www.webtoons.com/*
  10. // @match https://kiryuu.id/*
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. var scrollInterval = null;
  19. var isScrolling = false
  20. var isFullscreen = false;
  21. var activeElement;
  22.  
  23. var smoothScrollSpeed = 9; // Kecepatan pengguliran yang mulus
  24. var smoothScrollDelay = 10; // Penundaan di antara setiap langkah pengguliran yang mulus
  25.  
  26. function smoothScrollStep(direction) {
  27. var scrollDistance = direction === 'up' ? -smoothScrollSpeed : smoothScrollSpeed;
  28. window.scrollBy(0, scrollDistance);
  29. }
  30.  
  31. function startSmoothScrolling(direction) {
  32. if (!isScrolling) {
  33. isScrolling = true;
  34. smoothScrollStep(direction);
  35. scrollInterval = setInterval(function() {
  36. smoothScrollStep(direction);
  37. }, smoothScrollDelay);
  38. }
  39. }
  40.  
  41. function stopSmoothScrolling() {
  42. if (isScrolling) {
  43. isScrolling = false;
  44. clearInterval(scrollInterval);
  45. }
  46. }
  47.  
  48. document.addEventListener('keydown', function(event) {
  49. if ((event.key === 'a' || event.key === 'A' || event.key === 'ArrowLeft') && !event.ctrlKey && !event.altKey && event.key !== 'Tab') {
  50. var prevButton;
  51. if (window.location.host === 'westmanga.info') {
  52. prevButton = document.querySelector('.ch-prev-btn');
  53. } else if (window.location.host === 'komikcast.vip') {
  54. prevButton = document.querySelector('.nextprev a[rel="prev"]');
  55. } else if (window.location.host === 'aquamanga.com') {
  56. prevButton = document.querySelector('a.btn.prev_page');
  57. } else if (window.location.host === 'kiryuu.id') {
  58. prevButton = document.querySelector('a.ch-prev-btn');
  59. } else if (window.location.host === 'www.webtoons.com') {
  60. prevButton = document.querySelector('a[title="Episode sebelumnya"]');
  61. }
  62. if (prevButton) {
  63. // Periksa elemen yang sedang dalam fokus
  64. activeElement = document.activeElement;
  65. if (!(activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA'))) {
  66. // Pengguna tidak sedang mengetik
  67. prevButton.click();
  68. }
  69. }
  70. } else if ((event.key === 'd' || event.key === 'D' || event.key === 'ArrowRight') && !event.ctrlKey && !event.altKey && event.key !== 'Tab') {
  71. var nextButton;
  72. if (window.location.host === 'westmanga.info') {
  73. nextButton = document.querySelector('.ch-next-btn');
  74. } else if (window.location.host === 'komikcast.vip') {
  75. nextButton = document.querySelector('.nextprev a[rel="next"]');
  76. } else if (window.location.host === 'aquamanga.com') {
  77. nextButton = document.querySelector('a.btn.next_page');
  78. } else if (window.location.host === 'kiryuu.id') {
  79. nextButton = document.querySelector('a.ch-next-btn');
  80. } else if (window.location.host === 'www.webtoons.com') {
  81. nextButton = document.querySelector('a[title="Episode selanjutnya"]');
  82. }
  83. if (nextButton) {
  84. // Periksa elemen yang sedang dalam fokus
  85. activeElement = document.activeElement;
  86. if (!(activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA'))) {
  87. // Pengguna tidak sedang mengetik
  88. nextButton.click();
  89. }
  90. }
  91. } else if ((event.key === 's' || event.key === 'S') && !event.ctrlKey && !event.altKey && event.key !== 'Tab') {
  92. // Periksa elemen yang sedang dalam fokus
  93. activeElement = document.activeElement;
  94. if (!(activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA'))) {
  95. // Pengguna tidak sedang mengetik
  96. startSmoothScrolling('down');
  97. }
  98. } else if ((event.key === 'w' || event.key === 'W') && !event.ctrlKey && !event.altKey && event.key !== 'Tab') {
  99. // Periksa elemen yang sedang dalam fokus
  100. activeElement = document.activeElement;
  101. if (!(activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA'))) {
  102. // Pengguna tidak sedang mengetik
  103. startSmoothScrolling('up');
  104. }
  105. } else if ((event.key === 'f' || event.key === 'F') && !event.ctrlKey && !event.altKey && event.key !== 'Tab') {
  106. // Periksa elemen yang sedang dalam fokus
  107. activeElement = document.activeElement;
  108. if (!(activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA'))) {
  109. // Pengguna tidak sedang mengetik, masuk ke mode fullscreen
  110. event.preventDefault();
  111. toggleFullscreen(); // Fungsi Anda untuk masuk/keluar dari mode fullscreen
  112. }
  113. } else if ((event.key === 'q' || event.key === 'Q') && !event.ctrlKey && !event.altKey && event.key !== 'Tab') {
  114. var allChapterButton;
  115. if (window.location.host === 'westmanga.info') {
  116. allChapterButton = document.querySelector('.allc a');
  117. } else if (window.location.host === 'www.webtoons.com') {
  118. allChapterButton = document.querySelector('a[class="subj NPI=a:end,g:in_id"]');
  119. } else if (window.location.host === 'kiryuu.id') {
  120. allChapterButton = document.evaluate("//div[contains(text(), 'Semua chapter ada di')]/a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  121. } else if (window.location.host === 'komikcast.vip') {
  122. allChapterButton = document.querySelector('div.allc a');
  123. } else if (window.location.host === 'aquamanga.com') {
  124. // Ambil URL saat ini
  125. var currentUrl = window.location.href;
  126. // Gunakan ekspresi reguler untuk menghapus segmen URL setelah judul komik
  127. var newUrl = currentUrl.replace(/\/read\/([^/]+)\/.*/, '/read/$1/');
  128. // Periksa elemen yang sedang dalam fokus
  129. activeElement = document.activeElement;
  130. if (!(activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA'))) {
  131. // Pengguna tidak sedang mengetik memindahkan pengguna ke URL yang telah diubah
  132. window.location.href = newUrl;
  133. }
  134. }
  135. if (allChapterButton) {
  136. // Periksa elemen yang sedang dalam fokus
  137. activeElement = document.activeElement;
  138. if (!(activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA'))) {
  139. // Pengguna tidak sedang mengetik
  140. allChapterButton.click();
  141. }
  142. }
  143. }
  144. });
  145.  
  146. function toggleFullscreen() {
  147. if (!isFullscreen) {
  148. enterFullscreen();
  149. } else {
  150. exitFullscreen();
  151. }
  152. isFullscreen = !isFullscreen;
  153. }
  154.  
  155. function enterFullscreen() {
  156. const elem = document.documentElement;
  157. if (elem.requestFullscreen) {
  158. elem.requestFullscreen();
  159. } else if (elem.mozRequestFullScreen) {
  160. elem.mozRequestFullScreen();
  161. } else if (elem.webkitRequestFullscreen) {
  162. elem.webkitRequestFullscreen();
  163. } else if (elem.msRequestFullscreen) {
  164. elem.msRequestFullscreen();
  165. }
  166. }
  167.  
  168. function exitFullscreen() {
  169. if (document.exitFullscreen) {
  170. document.exitFullscreen();
  171. } else if (document.mozCancelFullScreen) {
  172. document.mozCancelFullScreen();
  173. } else if (document.webkitExitFullscreen) {
  174. document.webkitExitFullscreen();
  175. } else if (document.msExitFullscreen) {
  176. document.msExitFullscreen();
  177. }
  178. }
  179.  
  180. document.addEventListener('keyup', function(event) {
  181. if ((event.key === 's' || event.key === 'S' || event.key === 'w' || event.key === 'W') && !event.ctrlKey && !event.altKey && event.key !== 'Tab') {
  182. stopSmoothScrolling();
  183. window.scrollTo(window.pageXOffset, window.pageYOffset); // Menghentikan scroll secara instan
  184. }
  185. });
  186. })();