真白萌:自动载入更多通知

卷动到通知列表底部时自动载入更多通知。

  1. // ==UserScript==
  2. // @name Masiro: Auto Load More Notifications
  3. // @name:zh-TW 真白萌:自動載入更多通知
  4. // @name:zh-CN 真白萌:自动载入更多通知
  5. // @description Load more notifications automatically when scrolled to the bottom of the notifications list.
  6. // @description:zh-TW 捲動到通知列表底部時自動載入更多通知。
  7. // @description:zh-CN 卷动到通知列表底部时自动载入更多通知。
  8. // @icon https://icons.duckduckgo.com/ip3/masiro.me.ico
  9. // @author Jason Kwok
  10. // @namespace https://jasonhk.dev/
  11. // @version 1.0.2
  12. // @license MIT
  13. // @match https://masiro.me/admin
  14. // @match https://masiro.me/admin/*
  15. // @exclude-match https://masiro.me/admin/auth/*
  16. // @run-at document-end
  17. // @grant none
  18. // @supportURL https://greasyfork.org/scripts/487408/feedback
  19. // ==/UserScript==
  20.  
  21. const observer = new MutationObserver((records) =>
  22. {
  23. for (const record of records)
  24. {
  25. for (const node of record.addedNodes)
  26. {
  27. if (node.classList.contains("message-frame"))
  28. {
  29. const moreButton = node.querySelector(".message-footer");
  30. const messagesList = node.querySelector(".message-content");
  31.  
  32. messagesList.addEventListener("scroll", handleScroll);
  33. handleScroll();
  34.  
  35. function handleScroll()
  36. {
  37. if ((messagesList.scrollTop + messagesList.clientHeight) >= (messagesList.scrollHeight - 20))
  38. {
  39. if (!moreButton || (moreButton.style.display === "none"))
  40. {
  41. messagesList.removeEventListener("scroll", handleScroll);
  42. }
  43. else
  44. {
  45. moreButton.click();
  46. }
  47. }
  48. }
  49. }
  50. }
  51. }
  52. });
  53.  
  54. observer.observe(document.querySelector(".navbar-custom-menu .navbar-nav li:first-child > div"), { childList: true });