前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何屏蔽 Emacs China 论坛指定用户的帖子

如何屏蔽 Emacs China 论坛指定用户的帖子

作者头像
飞驰的西瓜
发布2022-07-26 16:26:03
8380
发布2022-07-26 16:26:03
举报
文章被收录于专栏:EmacsTalk

Emacs China 作为国内少数中文优质论坛,混的时间久了难免会对某些用户的帖子有些反感,虽然论坛自身有屏蔽的功能[1],但仅仅是把内容用「ignored content」来替代,帖子本身还在,没法直接把帖子直接隐藏掉,因此写了个油猴脚本来做这件事。

安装地址:https://greasyfork.org/en/scripts/429688-emacs-china-user-blocker

代码语言:javascript
复制
// ==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==
// user ids 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);

引用链接

[1] 有屏蔽的功能: https://emacs-china.org/t/topic/11765

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-07-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 EmacsTalk 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档