Greasy Fork

Greasy Fork is available in English.

妖火去除帖子列表滑动底部加载重复帖子

2025/3/30 17:27:21

当前为 2025-03-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        妖火去除帖子列表滑动底部加载重复帖子
// @namespace   yaohuo.me
// @match       https://yaohuo.me/*
// @match       https://www.yaohuo.me/*
// @grant       none
// @version     1.2
// @noframes    off
// @run-at      document-end
// @author      老六 (https://yaohuo.me/bbs/userinfo.aspx?touserid=25038)
// @description 2025/3/30 17:27:21
// @license     MIT
// ==/UserScript==

(() => {
  'use strict';
  console.log("start filter...")
  const existingIds = new Set();
  const getPostId = (item) => item.querySelector('a.topic-link')?.getAttribute('href')?.match(/bbs-(\d+)\.html/)?.[1];


    document.querySelectorAll('body > .listdata').forEach(item => {
      const id = getPostId(item);
      if (id) existingIds.add(id);
    });

    const original_KL_CallBack = window.KL_CallBack;
    if (typeof original_KL_CallBack !== 'function') return;

    window.KL_CallBack = () => {
      original_KL_CallBack();

      if (window.xmlhttp?.readyState === 4 && window.xmlhttp?.status === 200) {
        const responseText = window.xmlhttp.responseText;
        const startIndex = responseText.indexOf("<!--listS-->");
        const endIndex = responseText.indexOf("<!--listE-->");

        if (startIndex !== -1 && endIndex > startIndex) {
          const newDoc = new DOMParser().parseFromString(`<div>${responseText.substring(startIndex + 12, endIndex)}</div>`, 'text/html');

          newDoc.querySelectorAll('.listdata').forEach(newItem => {
            const id = getPostId(newItem);
            if (id) {
              if (existingIds.has(id)) {
                document.querySelector(`a.topic-link[href*="bbs-${id}.html"]`)?.closest('div.listdata')?.remove();
              } else {
                existingIds.add(id);
              }
            }
          });
        }
      }
    };

})();