Greasy Fork

Greasy Fork is available in English.

阿瓦隆检测工具

用于检查评论是否被阿瓦隆拦截屏蔽

当前为 2022-02-09 提交的版本,查看 最新版本

// ==UserScript==
// @name         阿瓦隆检测工具
// @namespace    https://space.bilibili.com/32957695
// @version      0.1
// @description  用于检查评论是否被阿瓦隆拦截屏蔽
// @author       晓轩iMIKU
// @license MIT
// @compatible   chrome 80 or later
// @compatible   edge 80 or later
// @compatible   firefox 74 or later
// @compatible   safari 13.1 or later
// @match        *://*.bilibili.com/*
// @icon         https://www.google.com/s2/favicons?domain=bilibili.com
// @require      https://unpkg.com/[email protected]/dist/ajaxhook.min.js
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    window.onload = function () {
        ah.proxy({
            onRequest: (config, handler) => {
                handler.next(config);
            },
            onResponse: (response, handler) => {
                if (response.config.url.includes('/x/v2/reply/add')) {
                    setTimeout(() => {
                        chick(response.response)
                    }, 1000);
                }
                handler.next(response);
            }
        })
    }

    function chick(response_str) {
        let response_json = JSON.parse(response_str)
        if (response_json.data.reply.state != 0) {
            copy_delete_reply(response_json);
        }
        else {
            check_reply(response_json).then((flags) => {
                if (!flags) {
                    copy_delete_reply(response_json);
                }
            });
        }
    }

    function check_reply(response_json) {
        let api = "https://api.bilibili.com/x/v2/reply/main";
        let type = response_json.data.reply.type;
        let oid = response_json.data.reply.oid;
        let rpid = response_json.data.reply.rpid;
        let url = `${api}?type=${type}&oid=${oid}&rpid=${rpid}`;
        let flags = new Promise((resolve, reject) => {
            fetch(url, {
                method: 'GET',
            }).then(res => res.json()).then(res => {
                res.data.replies.forEach(reply => {
                    if (reply.rpid == rpid) resolve(true);
                    else if (reply.replies != null) {
                        reply.replies.forEach(reply => {
                            if (reply.rpid == rpid) resolve(true);
                        })
                    }
                    else resolve(false);
                })
            })
        });
        return flags;
    }

    function copy_delete_reply(response_json) {
        let r = confirm(`你的评论:\n${response_json.data.reply.content.message}\n被阿瓦隆屏蔽了,点击确定复制并删除`);
        if (r) {
            let api = "https://api.bilibili.com/x/v2/reply/del";
            let type = response_json.data.reply.type;
            let oid = response_json.data.reply.oid;
            let rpid = response_json.data.reply.rpid;
            let csrf = document.cookie.match(/bili_jct=([^;]+)/)[1];
            fetch(api, {
                method: 'POST',
                body: `type=${type}&oid=${oid}&rpid=${rpid}&csrf=${csrf}`,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                credentials: "include"
            }).then(res => res.json()).then(res => {
                navigator.clipboard.writeText(response_json.data.reply.content.message).then(() => {
                    setTimeout(() => {
                        document.getElementsByClassName('hot-sort')[0].click();
                        document.getElementsByClassName('new-sort')[0].click();
                    }, 500);
                })
            })
        }
    }
})();