探测黑名单Plus - colg.cn

2020/11/27 下午10:18:36

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        探测黑名单Plus - colg.cn
// @namespace   Violentmonkey Scripts
// @match       https://bbs.colg.cn/thread*
// @match       https://bbs.colg.cn/forum*
// @grant       none
// @version     1.3
// @author      -
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @description 2020/11/27 下午10:18:36
// @license MIT
// ==/UserScript==
(function () {
    'use strict';
    jQuery.noConflict();
    (function ($) {
        window.addEventListener('load', function () { //等缓存完了再运行
          function uidCheckBlack(checkeduid, checkedname) {
            let defer = jQuery.Deferred();
            let res = "";
            jQuery.ajax({
                type: "get",
                url: "https://bbs.colg.cn/home.php?mod=spacecp&ac=friend&op=add&uid=" + checkeduid,
                dataType: "html",
                async: true, //默认为true,即默认为异步请求,否则为同步请求
                success: function (data) {
                    if (jQuery(data).find("#return_").length == 0) {
                        //当已经是好友的时候,返回friend
                        if (jQuery(data).find("#messagetext p:first").text().indexOf("好友") != -1) {
                            console.log("发现好友:" + checkedname + " ,uid是: " + checkeduid);
                            res = "friend";
                            defer.resolve(res);
                        } else if (jQuery(data).find("#messagetext p:first").text().indexOf("隐私设置") != -1) {
                            console.log("拉黑了你的是: " + checkedname + " ,uid是: " + checkeduid);
                            res = "black";
                            defer.resolve(res);
                        } else {
                            console.log("已经检测:" + checkedname + " ,uid是: " + checkeduid);
                            res = "others";
                            defer.resolve(res);
                        }
                    } else {
                        console.log("已经检测:" + checkedname + " ,uid是: " + checkeduid);
                        res = "others";
                        defer.resolve(res);
                    };

                },
                error: function (data) {
                    console.log(data);
                }
            });
            return defer.promise();
        }
        var selfuid = /uid=\d+/.exec(jQuery("#um > p > strong > a:first").attr("href"))[0].slice(4, );

        function checkthread() {
            let $threadList = jQuery("div.authi > a.xw1[target='_blank'][href]");
            if ($threadList.length > 0) {
                $threadList.each(function () {
                    //找到uid
                    let uid = /uid=\d+/.exec(jQuery(this).attr("href"))[0].slice(4, );
                    if (uid === selfuid) return;
                    let intext = jQuery(this).text();
                    let $thisobj = jQuery(this);
                    jQuery.when(uidCheckBlack(uid, intext)).done(function (data) {
                        if (data == "black") {
                            $thisobj.addClass("red");
                            $thisobj.css("color", "#FF0000");
                            $thisobj.text(intext + "(拉黑)");
                        } else if (data == "friend") {
                            $thisobj.css("color", "#FFCC00");
                            $thisobj.text(intext + "(好友)");
                        } else {
                            $thisobj.css("color", "#009900");
                        }
                    });
                });
            };
        }

        function checkform() {
            //列表遍历
            let $fromList = jQuery("#threadlisttableid td.by > cite > a[c='1'][mid][href]");
            if ($fromList.length > 0) {
                $fromList.each(function () {
                    //找到uid
                    let uid = /uid=\d+/.exec(jQuery(this).attr("href"))[0].slice(4, );
                    if (uid === selfuid) return;
                    let intext = jQuery(this).text();
                    let $thisobj = jQuery(this);
                    jQuery.when(uidCheckBlack(uid, intext)).done(function (data) {
                        if (data == "black") {
                            $thisobj.addClass("red");
                            $thisobj.css("color", "#FF0000");
                            $thisobj.text(intext + "(拉黑)");
                        } else if (data == "friend") {
                            $thisobj.css("color", "#FFCC00");
                            $thisobj.text(intext + "(好友)");
                        } else {
                            $thisobj.css("color", "#009900");
                        }
                    });
                });
            };

        }
        checkthread();
        checkform();
        }, false);
    })(jQuery);
})();