Emacs China Blocker

7/21/2021, 11:13:28 AM

目前為 2021-07-21 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Emacs China Blocker
// @namespace   https://liujiacai.net/
// @match       https://emacs-china.org/
// @grant       none
// @version     1.0
// @author      https://github.com/jiacai2050
// @description 7/21/2021, 11:13:28 AM
// ==/UserScript==


const blockedUsers = ['nesteiner'];
const prefix = 'https://emacs-china.org/u/';

let seenPostCount = 0;

function removeBlockedPosts() {
  console.log('remove...');
  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('load', function() {
  setTimeout(removeBlockedPosts, 200);
});

window.addEventListener('wheel', removeBlockedPosts);