Greasy Fork is available in English.

Mangalib Infinite Scroll

Infinite scroll on chat mangalib.me

  1. // ==UserScript==
  2. // @name Mangalib Infinite Scroll
  3. // @version 0.7.3
  4. // @description Infinite scroll on chat mangalib.me
  5. // @author reiwsan
  6. // @match https://mangalib.me/*
  7. // @match https://ranobelib.me/*
  8. // @namespace https://greatest.deepsurf.us/users/221048
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const preloadPos = 321;
  16.  
  17. /**
  18. * @param {Element} chatMore
  19. * @returns {void}
  20. */
  21. const historyAutoload = function(chatMore) {
  22. let chatItems = document.querySelector('.chat__items'),
  23. historyLoad = false;
  24.  
  25. /**
  26. * @param {Element} chatMore
  27. * @returns {boolean}
  28. */
  29. const chatMoreClick = function(chatMore) {
  30. chatMore.click();
  31. return true;
  32. }
  33.  
  34. chatItems.addEventListener('scroll', _ => {
  35. let scrollPos = ((chatItems.scrollHeight - chatItems.clientHeight) - chatItems.scrollTop),
  36. scrollPreload = (scrollPos <= preloadPos);
  37.  
  38. historyLoad = (scrollPreload && !historyLoad) ?
  39. chatMoreClick(chatMore) : scrollPreload;
  40. });
  41. }
  42.  
  43. if (typeof _CHAT_INSTANCE !== 'undefined') {
  44. const chatInitInterval = setInterval(() => {
  45. let chatMore = document.querySelector('.chat__more');
  46.  
  47. if (chatMore) {
  48. clearInterval(chatInitInterval);
  49. historyAutoload(chatMore);
  50. }
  51. }, 50);
  52. }
  53. })();