泛采专业版插件

1.检测后台服务是否异常,2.ESC关闭置顶弹出窗.3.保存快捷键

当前为 2021-12-10 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         泛采专业版插件
// @include        *://spider.vpc.shangjian.tech/*
// @include        *://baelish.zncjtest.xhszjs.cn/*
// @include        *://baelish-zncj.xhszjs.com/*
// @include        *://8.131.101.146:30726/*
// @require        https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// @icon           https://www.valuesimplex.com/images/favicon.ico
// @icon64          https://www.valuesimplex.com/images/favicon.ico
// @grant           GM_xmlhttpRequest
// @version      2.4.5
// @description  1.检测后台服务是否异常,2.ESC关闭置顶弹出窗.3.保存快捷键
// @author       房天生
// @match        *://spider.vpc.shangjian.tech/*
// @match        *://baelish.zncjtest.xhszjs.cn/*
// @match        *://baelish-zncj.xhszjs.com/*
// @match        *://8.131.101.146:30726/*
// @grant             GM_info
// @namespace https://raw.githubusercontent.com/fangtiansheng/xinhua/master/script/baelish.js
// ==/UserScript==

(function () {
    "use strict";
    // 定时ping泛采系统查看服务是否在线
    const scriptInfo = GM_info.script;
    const version = scriptInfo.version;
    var interval = 1000 * 20;

    var ping = function () {
        let xhr = new XMLHttpRequest();
        xhr.open("GET", "crawl/crawl/get-user-list");
        xhr.onreadystatechange = function () {
            let head = document.getElementsByClassName("head")[0];
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    head.style.backgroundColor = "";
                    window.document.title = "爬虫管理系统";
                } else {
                    head.style.backgroundColor = "gray";
                    window.document.title = "🔥后台服务异常🔥";
                }
            }
        };
        xhr.send();
    };

    window.setInterval(ping, interval);
    console.log(
        `%c 泛采系统专业版插件 %c v${version} %c`,
        "background:#0049b0 ; padding: 1px; border-radius: 3px 0 0 3px;  color: #fff",
        "background:#f56c6c ; padding: 1px; border-radius: 0 3px 3px 0;  color: #fff",
        "background:transparent"
    );

    //定时扫描项目报警数量(禁用)
    if (1 === 2 && window.location.hostname === "spider.vpc.shangjian.tech") {
        setInterval(async () => {
            const project = await fetch(
                "https://spider.vpc.shangjian.tech/spider/project",
                {
                    headers: {
                        accept: "application/json, text/plain, */*",
                        "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
                        "cache-control": "no-cache",
                        pragma: "no-cache",
                        "sec-ch-ua":
                            '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
                        "sec-ch-ua-mobile": "?0",
                        "sec-fetch-dest": "empty",
                        "sec-fetch-mode": "cors",
                        "sec-fetch-site": "same-origin",
                    },
                    referrerPolicy: "no-referrer",
                    body: null,
                    method: "GET",
                    mode: "cors",
                    credentials: "include",
                }
            )
                .then((response) => response.json())
                .then(function (response) {
                    let data = response.data;
                    let count = 0;
                    let names = [];
                    for (let i = 0; i < data.length; i++) {
                        if (data[i].warning_count > 0 && data[i].id !== 97) {
                            names.push(data[i].name);
                        }
                    }
                    return names;
                })
                .then(function (names) {
                    //console.log("[+]项目中 "+names.length+"个报警。");
                    if (names.length > 0) {
                        window.document.title = "🔥报警: " + names.join(", ");
                    }
                });
            let list = JSON.parse(localStorage.getItem("report_ids"));
            if (list.length > 0) {
                console.log("共", list.length, "条警告。");
                let url =
                    "spider/monitor?type=delete_report_history&report_id=" +
                    list.toString();
                fetch(url, {
                    headers: {
                        accept: "application/json, text/plain, */*",
                        "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
                        "cache-control": "no-cache",
                        pragma: "no-cache",
                        "sec-ch-ua":
                            '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
                        "sec-ch-ua-mobile": "?0",
                        "sec-fetch-dest": "empty",
                        "sec-fetch-mode": "cors",
                        "sec-fetch-site": "same-origin",
                    },
                    referrerPolicy: "no-referrer",
                    body: null,
                    method: "DELETE",
                    mode: "cors",
                    credentials: "include",
                });
            } else {
                console.log("目前没有告警。");
            }
        }, interval);
    }
    if (window.location.hostname.endsWith("xhszjs.cn")) {
        setInterval(async () => {
            const project = await fetch(window.location.origin, {
                headers: {
                    accept:
                        "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                    "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
                    "cache-control": "no-cache",
                    pragma: "no-cache",
                    "upgrade-insecure-requests": "1",
                },
                referrer: "http://baelish.zncjtest.xhszjs.cn/",
                referrerPolicy: "strict-origin-when-cross-origin",
                body: null,
                method: "GET",
                mode: "cors",
                credentials: "include",
            });
        }, interval);
    }
    // ESC关闭置顶弹出窗
    window.addEventListener("keydown", function (e) {
        if (e.keyCode === 27) {
            console.log("esc 按了");
            //全部弹窗
            var popups = document.getElementsByClassName("popup_hover");
            for (let i = popups.length; i--;) {
                //遍历全部弹窗
                if (popups[i].style.display === "") {
                    //查找弹出的窗口
                    let icon_close = popups[i].getElementsByClassName("popup_head_close_icon");
                    icon_close[0].click();
                    break;
                }
            }
        }
    });
    //保存
    window.addEventListener('keydown', e => {
        if (e.ctrlKey && e.key === 's') {
            // Prevent the Save dialog to open
            e.preventDefault();
            // Place your code here
            document.getElementsByClassName("planDetail_toolBox_item")[0]
                .getElementsByTagName("button")[0].click()
        }
    });
    //TODO Enter确认绑定按钮
})();