Qiita timeline auto more

auto fetch more entries

Stan na 11-03-2024. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Qiita timeline auto more
// @namespace    https://htsign.hateblo.jp
// @version      0.3.2
// @description  auto fetch more entries
// @author       htsign
// @match        https://qiita.com/*
// @grant        none
// ==/UserScript==

const queryNodes = function* (path, root = document) {
  const result = document.evaluate(path, root, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE);
  let node;
  while ((node = result.iterateNext()) != null) {
    yield node;
  }
};

const listElement = document.querySelector('main');
if (listElement) {
  const READMORE_XPATH = './/button[text()="もっと読む"]';

  const io = new IntersectionObserver((entries, observer) => {
    entries
      .filter(entry => entry.isIntersecting)
      .forEach(({ target }) => {
        observer.unobserve(target);
        target.click();
      });
  }, { rootMargin: '100%' });
  const mo = new MutationObserver(records => {
    const buttons = records
      .flatMap(r => [...r.addedNodes])
      .flatMap(node => [...queryNodes(READMORE_XPATH, node)]);

    buttons.forEach(io.observe.bind(io));
  });
  mo.observe(listElement, { childList: true, subtree: true });

  const button = document.evaluate(READMORE_XPATH, listElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE)?.singleNodeValue;
  if (button) {
    io.observe(button);
  }
}