MangaDex show only unread

02/12/2023, 01:30 AM

// ==UserScript==
// @name        MangaDex show only unread
// @namespace   Violentmonkey Scripts
// @match       https://mangadex.org/*
// @icon        https://icons.duckduckgo.com/ip2/mangadex.org.ico
// @grant       none
// @run-at      document-end
// @version     9.01
// @author      xxshade
// @license     MIT
// @description 02/12/2023, 01:30 AM
// ==/UserScript==

const HIDE_READ_DELAY = 500;

let timeoutId;

function hideRead() {
  const arrDivs = document.querySelectorAll(".chapter-feed__container.details.mb-4:not([style*='display: none;'])");

  if (arrDivs.length) {
    for (const div of arrDivs) {
      const unreadChapters = div.querySelectorAll("div.flex.chapter.relative:not(.read):not([style*='display: none;'])");
      const unreadChaptersLength = unreadChapters.length;
      if (unreadChaptersLength === 0) {
        div.style.display = "none";
      } else {
        const readChapters = div.querySelectorAll("div.flex.chapter.relative.read:not([style*='display: none;'])");
        for (const readChapter of readChapters) {
          readChapter.style.display = "none";
        }
      }
    }
  }
}

const observer = new MutationObserver(function() {
  clearTimeout(timeoutId);
  timeoutId = setTimeout(hideRead, HIDE_READ_DELAY);
});

observer.observe(document.body, {
  childList: true,
  subtree: true
});