Greasy Fork

来自缓存

Greasy Fork is available in English.

NGA Auto Pagerize

简单的自动翻页

当前为 2021-05-06 提交的版本,查看 最新版本

// ==UserScript==
// @name        NGA Auto Pagerize
// @namespace   http://greasyfork.icu/users/263018
// @version     1.1.1
// @author      snyssss
// @description 简单的自动翻页

// @match       *://bbs.nga.cn/*
// @match       *://ngabbs.com/*
// @match       *://nga.178.com/*

// @noframes
// ==/UserScript==

((ui) => {
  if (!ui) return;

  // 钩子
  const hookFunction = (object, functionName, callback) => {
    ((originalFunction) => {
      object[functionName] = function () {
        const returnValue = originalFunction.apply(this, arguments);

        callback.apply(this, [returnValue, originalFunction, arguments]);

        return returnValue;
      };
    })(object[functionName]);
  };

  // 翻页
  if (ui.pageBtn) {
    const execute = (() => {
      const observer = new IntersectionObserver((entries) => {
        if (entries[0].intersectionRatio > 0) {
          ui.loadReadHidden(0, 2);
        }
      });

      return () => {
        const anchor = document.querySelector('[title="加载下一页"]');

        if (anchor) {
          observer.observe(anchor);
        } else {
          observer.disconnect();
        }
      };
    })();

    hookFunction(ui, "pageBtn", execute);

    execute();
  }
  
  // 附件样式
  if (ui.topicArg)
  {
    const execute = () => {
      const elements = document.querySelectorAll('[title="主题中有附件"]');
      
      elements.forEach((element) => {
          element.className = "block_txt white nobr vertmod";
          element.style = "background-color: #BD7E6D";
          element.innerHTML = "附件";
      })
    };

    hookFunction(ui.topicArg, "loadAll", execute);

    execute();
  }
})(commonui);