grafana-html-decode

grafana html decode

当前为 2025-02-12 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         grafana-html-decode
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  grafana html decode
// @author       chong
// @include      *://*.otr-devops.cn.svc.corpintra.net/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license MIT
// ==/UserScript==
(function() {
    'use strict';

    // HTML解码函数
    function decodeHTML(html) {
        var txt = document.createElement('textarea');
        txt.innerHTML = html;
        return txt.value;
    }

    // 解码指定元素的内容
    function decodeHTMLForElements(elements) {
        elements.forEach(element => {
            element.innerHTML = decodeHTML(element.innerHTML);
        });
    }

    // 主解码逻辑
    function decodeAll() {

        // 解码所有具有特定类名的元素
        const messageElements = document.querySelectorAll('.css-uev0p3-logs-row__message');
        decodeHTMLForElements(messageElements);

        // 解码所有表格单元格内容
        const tableCells = document.querySelectorAll('.css-1lm1wit-wordBreakAll-wrapLine');
        decodeHTMLForElements(tableCells);

        console.log('解码完成!');
    }

    // 动态添加解码按钮
    function addDecodeButton() {
    // 选择所有符合条件的 <button> 元素
        const targetButton = document.querySelector('.button-group.css-8qah51.refresh-picker');

        // 检查是否已经添加过按钮
        if (!targetButton.nextElementSibling || !targetButton.nextElementSibling.classList.contains('custom-decode-button')) {
            // 创建新的按钮
            const decodeButton = document.createElement('button');

            decodeButton.className = 'custom-decode-button css-rf9bj2-toolbar-button ';
            decodeButton.innerText = 'Decode';
            decodeButton.title = 'Decode HTML entities';
            decodeButton.onclick = decodeAll;

            // 设置按钮的其他样式
            decodeButton.style.marginLeft = '3px';
            decodeButton.style.textAlign = 'center';
            decodeButton.style.width = '96px';



            // 将按钮插入到目标按钮的右边
            targetButton.parentElement.appendChild(decodeButton);

        }

    }

    // 延迟1000毫秒后执行addDecodeButton函数
    setTimeout(addDecodeButton, 1000);

   const handler = setInterval(()=>{
      addDecodeButton();
    }, 5000);

})();