阿里云日志美化

Log format

目前為 2021-05-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name         阿里云日志美化
// @namespace    GoldSubmarine
// @version      0.1
// @description  Log format
// @author       GoldSubmarine
// @match        https://sls.console.aliyun.com/lognext/project/*
// @icon         https://www.google.com/s2/favicons?domain=tampermonkey.net
// @grant        none
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    // 💬💡
    const observer = new MutationObserver(function(records) {
        for(const record of records) {
            record.addedNodes.forEach(li => {
                let hiddenStr = ""
                $(li).find("div[class^='Virtual__style__live-content'] > div").each(function() {
                    let html = $(this).text()

                    let removeLabelArr = ["__raw_log__: ", "body: "]
                    removeLabelArr.forEach((removeLabel) => {
                        if(html.indexOf(removeLabel) === 0) {
                            let span = $(this).find("span").eq(0)
                            if(span.text() === removeLabel) span.remove()
                        }
                    })

                    let labelArr = ["__tag__:__hostname__:", "__tag__:__path__:", "app:"]
                    labelArr.forEach((label) => {
                        if(html.indexOf(label) === 0) {
                            hiddenStr += html + ' '
                            $(this).css("display","none")
                        }
                    })
                })
                let tipHtml = $(li).find("div[class^='Virtual__style__live-content'] > span:eq(1)")
                tipHtml.html(" 💡 ")
                tipHtml.attr("aria-label", hiddenStr)
                tipHtml.attr("data-balloon-pos", "right")
            })
        }
    });

    function addCssByLink(url) {
        var link = document.createElement('link')
        link.setAttribute('rel', 'stylesheet')
        link.setAttribute('type', 'text/css')
        link.setAttribute('href', url)

        var heads = document.getElementsByTagName('head')
        if (heads.length) heads[0].appendChild(link)
        else document.documentElement.appendChild(link)
    }

    $( document ).ready(function() {
        let wrap = $("div[class^='Context__style__inner-list'] .next-virtual-list-wrapper ul")[0]
        if(wrap) {
            observer.observe(wrap, {childList: true})
        }
        addCssByLink('https://cdn.jsdelivr.net/npm/[email protected]/balloon.min.css')
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址