Next chapter in mangalib.me automatically

Click next chapter in mangalib.me automatically

  1. // ==UserScript==
  2. // @name Next chapter in mangalib.me automatically
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Click next chapter in mangalib.me automatically
  6. // @author Killua Kill
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=mangalib.me
  8. // @match https://mangalib.me/*
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to check if the button is visible on the screen
  17. function isButtonVisible() {
  18. var button = document.querySelectorAll('.reader-next__btn')[1];
  19. var rect = button.getBoundingClientRect();
  20. return (
  21. rect.top >= 0 &&
  22. rect.left >= 0 &&
  23. rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
  24. rect.right <= (window.innerWidth || document.documentElement.clientWidth)
  25. );
  26. }
  27.  
  28. // Function to click the button
  29. function clickButton() {
  30. var button = document.querySelectorAll('.reader-next__btn')[1];
  31. button.click();
  32. }
  33.  
  34. // Check if the button is visible on the screen and click it
  35. if (isButtonVisible()) {
  36. clickButton();
  37. } else {
  38. // If the button is not visible, wait for it to appear and then click it
  39. var observer = new MutationObserver(function(mutationsList) {
  40. for (var mutation of mutationsList) {
  41. if (mutation.type === 'childList' && isButtonVisible()) {
  42. clickButton();
  43. observer.disconnect();
  44. break;
  45. }
  46. }
  47. });
  48.  
  49. observer.observe(document.body, { childList: true, subtree: true });
  50. }
  51. })();