1. manifest.json

{
    "manifest_version": 3,
    "name": "TimeUtil",
    "version": "1.0.0",
    "description": "XAG log timestamp transformer",
    "icons": {
        "48": "icon.png"
    },
    "action": {
        "default_icon": "icon.png"
    },
    "permissions": [
        "activeTab"
    ],
    "content_scripts": [
        {
            "matches": [
                "https://xrtk.xaggeo.com/log/*.log"
            ],
            "js": [
                "background.js"
            ]
        }
    ]
}

2. 处理.js

function convert() {
    // 在这里执行与原始 HTML 页面相同的逻辑
    var result = '';
    var content = document.body.innerText; // 获取当前页面的文本内容
    var lines = content.split(/[(\r\n)\r\n]+/);

    lines.sort();
    var index = 1;
    for (var i = 0; i < lines.length; i++) {
        var line = addDateTime(lines[i], i - 1 >= 0 ? lines[i - 1] : null);
        if (line) {
            line = pz(index, 4, ' ') + ' ' + line;
            index++;
        }
        result += line;
    }

    // 在这里更新原始页面的文本内容
    // document.body.innerText = result;

    // Create a new div element
    var styledDiv = document.createElement('div');
    // Apply the style similar to the initial TimeUtil textarea
    styledDiv.style.width = '100%';
    styledDiv.style.fontFamily = 'monospace';
    styledDiv.style.fontSize = '12px';
    styledDiv.style.whiteSpace = 'pre-wrap';  // Preserves line breaks
    styledDiv.textContent = result;

    // Apply alternating background colors
    // var linesArray = result.split('\n');
    // for (var i = 0; i < linesArray.length; i++) {
    //     var lineDiv = document.createElement('div');
    //     lineDiv.textContent = linesArray[i];
    //     lineDiv.style.backgroundColor = i % 2 === 0 ? '#e6f7ff' : '#c2e2f2';
        
    //     lineDiv.style.color = '#000000';  // Black text color
    //     styledDiv.appendChild(lineDiv);
    // }

    // Replace the content of the body with the new styled div
    document.body.innerHTML = '';
    document.body.appendChild(styledDiv);
}

function addDateTime(line, lastLine) {
    if (line == lastLine) {
        return ''
    }
    var lastTs = 0
    if (lastLine) {
        var lastItems = lastLine.split(/,/)
        lastTs = parseInt(lastItems[0])
        if (lastTs < 1000000000) {
            lastTs *= 1000
        }
    }
    var items = line.split(/,/)
    var ts = parseInt(items[0])
    if (ts < 1000000000) {
        ts *= 1000
    }
    return '[' + ts2DateString(ts) + ' ' + pz((ts - lastTs), 13, ' ') + '] ' + line + '\r\n'
}
function ts2DateString(ts) {
    var date = new Date(ts)
    return pz(date.getHours()) + ':' +
        pz(date.getMinutes()) + ':' +
        pz(date.getSeconds()) + ':' +
        pz(date.getMilliseconds(), 3)
}
function pz(str, len, char) {
    len = len || 2
    char = char || '0'
    return (str || '').toString().padStart(len, char)
}

// 在页面加载完毕后调用 convertToTimeUtil 函数
window.onload = convert;

3. 加个 icon

from PowerPoint 另存为图片

4. 安装

插件管理界面 打开开发者模式 Reload 更新文件