泛采专业版插件

1.检测后台服务是否异常,2.ESC关闭置顶弹出窗.3.保存快捷键, 4.检测meta, 5.confluence显示导航栏

当前为 2022-04-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         泛采专业版插件
// @include      *://*/*
// @match        *://*/*
// @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.5.10
// @description  1.检测后台服务是否异常,2.ESC关闭置顶弹出窗.3.保存快捷键, 4.检测meta, 5.confluence显示导航栏
// @author       房天生
// @grant             GM_info
// @namespace https://raw.githubusercontent.com/fangtiansheng/xinhua/master/script/baelish.js
// ==/UserScript==

(function () {
    "use strict";
    // 定时ping泛采系统查看服务是否在线
    if (window.document.location.href.endsWith("#/home/crawl")) {
        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:#5D5D5D ; padding: 1px; border-radius: 3px 0 0 3px;  color: #fff",
            "background:#0D7FBF ; padding: 1px; border-radius: 0 3px 3px 0;  color: #fff",
            "background:transparent"
        );
    }


    //定时扫描项目报警数量(禁用)
    if (1 === 2 && window.location.hostname === "baelish.data.prod.valuesimplex.tech") {
        setInterval(async () => {
            await fetch(
                "https://baelish.data.prod.valuesimplex.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 names = [];
                    for (let each of data) {
                        if (each.warning_count > 0 && each.id !== 97) {
                            names.push(each.name);
                        }
                    }
                    return names;
                })
                .then(function (names) {
                    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);
    }

    // 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
            var button = document.getElementsByClassName("pageDetail_toolBox_item")[0] || document.getElementsByClassName("planDetail_toolBox_item")[0]
            button.getElementsByTagName("button")[0].click()
        }
    });
    //检测meta标签
    let title = window.document.title;
    if (document.getElementsByName("ArticleTitle").length) {
        console.log('.//*[@name="ArticleTitle"]/@content');
        setInterval(
            function () {
                if (window.document.title.startsWith("🔴")) {
                    window.document.title = "⚪️" + title;
                } else {
                    window.document.title = "🔴" + title;
                }
            }, 600);
    }
    if (document.getElementsByName("PubDate").length || document.getElementsByName("pubdate").length) {
        console.log('.//*[translate(@name, "PUBDATE", "pubdate")="pubdate"]/@content');
    }
    if (document.getElementsByName("ColumnName").length) {
        console.log('.//*[translate(@name, "COLUMNNAME", "columnname")="columnname"]/@content');
    }
    if (document.getElementsByName("ContentSource").length || document.getElementsByName("contentSource").length) {
        console.log('.//*[translate(@name, "CONTENTSOURCE", "contentsource")="contentsource"]/@content');
    }
    // confluence一直显示创建页面按钮
    if (location.hostname.startsWith("confluence")) {
        document.getElementsByClassName("aui-header-primary")[0].getElementsByClassName("aui-nav")[0].style.width = "auto";
    }
    // Wordpress站点发布日期meta标签检测
    if (document.querySelector('meta[property="article:published_time"]') || document.querySelector('meta[property="article:published"]')) {
        console.log('.//*[contains(@property, "article:published")]/@content');
        setInterval(
            function () {
                if (window.document.title.startsWith("🟢")) {
                    window.document.title = "🟡️" + title;
                } else {
                    window.document.title = "🟢" + title;
                }
            }, 600);
    }
})();