emacs-china user blocker

Emacs-China 论坛,屏蔽指定用户的帖子

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

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

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        emacs-china user blocker
// @namespace   https://liujiacai.net/
// @match       https://emacs-china.org/
// @grant       none
// @version     1.0
// @author      https://github.com/jiacai2050
// @description Emacs-China 论坛,屏蔽指定用户的帖子
// @icon        https://emacs-china.org/uploads/default/optimized/2X/d/dd05943671ee57856f9d7fa7ba6497f31bfcd332_2_180x180.png
// ==/UserScript==


// users id your want to block
const blockedUsers = [];
const prefix = 'https://emacs-china.org/u/';

let seenPostCount = 0;

function removeBlockedPosts() {
  const allPosts = document.querySelectorAll('td.posters a');
  console.log(allPosts.length);
  if (seenPostCount >= allPosts.length) {
    // console.log('already removed, return directly');
    return;
  }
  const oldLength = seenPostCount;
  seenPostCount = allPosts.length;
  for (let i=oldLength;i<allPosts.length;i++) {
    const post = allPosts[i];
    const url = post.href;
    for (blocked of blockedUsers) {
      const userLink = prefix + blocked;
      if (url === userLink) {
        const tr = post.parentNode.parentNode;
        const titleLink = tr.firstElementChild.firstElementChild.firstElementChild;
        console.log(`remove post: ${titleLink.textContent}, url: ${titleLink.href}, by ${blocked}`);
        tr.remove();
      }
    }
  }
}

window.addEventListener('wheel', removeBlockedPosts);
window.addEventListener('load', removeBlockedPosts);