[Share Experiences] (10.12日更新)屏蔽指定用户帖子和回复(油猴脚本)
Tofloor
poster avatar
deepin-superuser
deepin
2023-08-24 23:54
Author

使用方法:要屏蔽的用户写到 blacklist 中,逗号分隔。 例如 var blacklist = [286301, 62471, 170185];

用户ID获取方式:鼠标移动到想要屏蔽的用户头像上,点击 Ta的主页 按钮,地址栏中的数字就是他的用户ID

脚本如下

// ==UserScript==
// @name        拦截指定用户帖子和回复
// @namespace   Violentmonkey Scripts
// @match       https://bbs.deepin.org/*
// @grant       none
// @version     1.0
// @author      -
// @description 2023/8/24 15:03:57
// @run-at           document-idle
// ==/UserScript==

var blacklist = [286301];

if (location.href.indexOf("/post/") == -1) {
    var data = JSON.parse(document.getElementById('ng-state').textContent);
    if (data && data.resolver_thread_list && data.resolver_thread_list.ThreadIndex) {
        data.resolver_thread_list.ThreadIndex.forEach(post => {
            if (blacklist.includes(post.user_id)) {
                timer = setInterval(() => {
                    if (document.querySelector('[href="/post/' + post.id + '"]')) {
                        document.querySelector('[href="/post/' + post.id + '"]').parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.remove()
                    } else {
                        clearInterval(timer)
                    }
                }, 1000)
            }
        })
    }
} else {
    var data = JSON.parse(document.getElementById('ng-state').textContent);
    if (data && data['post-detail'] && data['post-detail'].posts && data['post-detail'].posts.data) {
        data['post-detail'].posts.data.forEach(post => {
            if (blacklist.includes(post.post_user_id)) {
                postTimer = setInterval(() => {
                    if (document.getElementById('post_' + post.id)) {
                        document.getElementById('post_' + post.id).remove()
                    } else {
                        clearInterval(postTimer)
                    }
                }, 1000)
            }
        })
    }
}

// 拦截HTTP请求
const originOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (_, url) {
    const xhr = this;
    const getter = Object.getOwnPropertyDescriptor(
        XMLHttpRequest.prototype,
        "response"
    ).get;
    if (url.indexOf("api/v1/thread/index") != -1) {
        Object.defineProperty(xhr, "response", {
            get: () => {
                let result = getter.call(xhr);
                try {
                    const res = JSON.parse(result);
                    if (res.ThreadIndex) {
                        res.ThreadIndex = res.ThreadIndex.filter(post => !blacklist.includes(post.user_id))
                    }
                    return JSON.stringify(res);
                } catch (e) {
                    return result;
                }
            },
        });
    } else if (url.indexOf("api/v1/thread/post/list") != -1) {
        Object.defineProperty(xhr, "response", {
            get: () => {
                let result = getter.call(xhr);
                try {
                    const res = JSON.parse(result);
                    if (res.data) {
                        res.data = res.data.filter(post => !blacklist.includes(post.user_id))
                    }
                    return JSON.stringify(res);
                } catch (e) {
                    return result;
                }
            },
        });
    }
    originOpen.apply(this, arguments);
};
Reply Favorite View the author
All Replies
jiutian123
deepin
2023-08-25 00:09
#1

我想弄一个 油猴脚本,

切换屏幕,视频不暂停,播完第一个视频后继续播放第二个视频joy

Reply View the author
yanjuner
Super Moderator
2023-08-25 00:10
#2

牛啊

动手能力好强

Reply View the author
187******09
deepin
2023-08-25 00:17
#3

行动力可以啊

然后还有一个更方便的获取ID方法:

  1. 指向要屏蔽的人的发言左上角头像
  2. 在弹出的窗口中鼠标指向“Ta的主页”
  3. 保持指向,左下角(Chrome是这样,其他的不知道)出现的链接最后的数字就是ID
Reply View the author
deepin-superuser
deepin
2023-08-25 00:43
#4
187******09

行动力可以啊

然后还有一个更方便的获取ID方法:

  1. 指向要屏蔽的人的发言左上角头像
  2. 在弹出的窗口中鼠标指向“Ta的主页”
  3. 保持指向,左下角(Chrome是这样,其他的不知道)出现的链接最后的数字就是ID

直接点去Ta的主页 URL里边就是

Reply View the author
deepin-superuser
deepin
2023-08-25 01:08
#5
jiutian123

我想弄一个 油猴脚本,

切换屏幕,视频不暂停,播完第一个视频后继续播放第二个视频joy

以我的技术应该是实现不了的

Reply View the author
一只小H
deepin
2023-08-25 01:29
#6

286301,不用找了yeah joy

Reply View the author
一只小H
deepin
2023-08-25 01:30
#7

只能说官方还是脾气太好joy 换某些社区号早就无了

Reply View the author
阿尼樱奈奈
Moderator
2023-08-25 03:20
#8

like

Reply View the author
青稚°
Moderator
2023-08-25 04:24
#9

厉害,点赞like

Reply View the author
liwl
deepin
2023-08-25 16:52
#10

like 要永远相信铁子

Reply View the author