屏蔽拼车轮子贴脚本

专注感兴趣的板块

// ==UserScript==
// @name         IDC Flare 屏蔽拼车帖
// @namespace    https://idcflare.com/
// @version      1.0.0
// @description  在 IDC Flare 的话题列表中隐藏带“拼车”标签的帖子
// @author       Codex
// @match        https://idcflare.com/*
// @run-at       document-start
// @grant        GM_addStyle
// ==/UserScript==

(function () {
  'use strict';

  const HIDDEN_CLASS = 'tm-hide-carpool-topic';
  const CARPOOL_TAG_SELECTOR =
    'a[data-tag-name="拼车"], a[href="/tag/4-tag/4"], a[href^="/tag/4-tag/4/"]';

  GM_addStyle(`
    /* 当前站点为带“拼车”标签的话题行添加此类名。 */
    .topic-list-item.tag-拼车,
    .topic-list-item.${HIDDEN_CLASS} {
      display: none !important;
    }
  `);

  function hideCarpoolTopics(root = document) {
    // 主规则会直接命中当前 DOM;这里是备用规则,用于兼容站点未来改动。
    root.querySelectorAll(CARPOOL_TAG_SELECTOR).forEach((tag) => {
      const topic = tag.closest('.topic-list-item');
      if (topic) topic.classList.add(HIDDEN_CLASS);
    });
  }

  function start() {
    hideCarpoolTopics();

    // Discourse 会无刷新换页并动态加载更多话题,因此持续处理新增内容。
    const observer = new MutationObserver((mutations) => {
      for (const mutation of mutations) {
        for (const node of mutation.addedNodes) {
          if (!(node instanceof Element)) continue;

          if (node.matches(CARPOOL_TAG_SELECTOR)) {
            node.closest('.topic-list-item')?.classList.add(HIDDEN_CLASS);
          }
          hideCarpoolTopics(node);
        }
      }
    });

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

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', start, { once: true });
  } else {
    start();
  }
})();

23 个赞

这个脚本很不错,值得推荐

3 个赞

这个要点个大大的赞,首页终于清净了。

3 个赞

虽然但是,只是主页的话其实论坛自带有现成的
参见

同理,主站 linux.do 也可以

3 个赞

不错的脚本

直接点这个:bell:免打扰就行了