emacs-china user blocker

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);