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