Greasy Fork

Greasy Fork is available in English.

讯飞星火助手

讯飞星火助手工具

当前为 2023-05-06 提交的版本,查看 最新版本

// ==UserScript==
// @name         讯飞星火助手
// @namespace    http://tampermonkey.net/
// @version      0.0.2
// @description  讯飞星火助手工具
// @author       kj
// @match        https://xinghuo.xfyun.cn/desk
// @icon         https://www.google.com/s2/favicons?sz=64&domain=xfyun.cn
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';
    const generateUUID = () => {
        let d = new Date().getTime();
        if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
            d += performance.now(); // use high-precision timer if available
        }
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
            const r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
        });
    }
    const checkHit = dom => {
        return /^watermark-wrapper$/gi.exec(dom.getAttribute('id')) || /^.*_watermark_.*$/gi.exec(dom.getAttribute('class'));
    }
    let uuid = generateUUID();
    const hideIt = dom => {
        if (checkHit(dom)) {
            if (dom.id) {
                const styleId = `hide-${uuid}`;
                let styleEl = document.getElementById(styleId);
                if (!styleEl) {
                    styleEl = document.createElement('style');
                    styleEl.setAttribute('id', styleId);
                    const escapedId = dom.id.replace(/^\d/, char => `\\${char.charCodeAt(0).toString(16)} `);
                    styleEl.innerHTML = `${dom.tagName.toLowerCase()}#${escapedId}{display:none!important;transform: translateX(100000000px);overflow: hidden;}`;
                    document.body.appendChild(styleEl);
                }
            } else {
                const styleId = `hide-${uuid}`;
                let styleEl = document.getElementById(styleId);
                if (!styleEl) {
                    styleEl = document.createElement('style');
                    styleEl.setAttribute('id', styleId);
                    const clazz = dom.getAttribute('class').trim().split(/\s+/gi).join('.');
                    styleEl.innerHTML = `${dom.tagName.toLowerCase()}.${clazz}"]{display:none!important;transform: translateX(100000000px);overflow: hidden;}`;
                    document.body.appendChild(styleEl);
                }
            }
        } else {
            dom.style.visibility = 'hidden';
            dom.style.opacity = '0';
        }
    }
    const observer = new MutationObserver((mutationsList, observer) => {
        mutationsList.forEach((mutation) => {
            if (mutation.addedNodes && mutation.addedNodes[0]) {
                if (checkHit(mutation.addedNodes[0])) {
                    hideIt(mutation.addedNodes[0]);
                }
            }
        });
    });
    observer.observe(document.body, {
        childList: true,
        attributes: true,
    });
    const doms = Array.from(document.querySelectorAll('div')).filter(e => checkHit(e));
    if (doms.length > 0) {
        doms[0].style.visibility = 'hidden';
        doms[0].style.opacity = '0';
    }
})();