伽利略日志json序列化

json序列化

目前為 2024-12-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         伽利略日志json序列化
// @namespace    http://tampermonkey.net/
// @version      2024-11-08
// @description  json序列化
// @author       promisewu
// @match        https://j.woa.com/service/log/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=woa.com
// @grant        none
// @license      GPL License
// ==/UserScript==

(function() {
    'use strict';

    // 创建浮层弹窗
    const overlay = document.createElement('div');
    overlay.style.position = 'fixed';
    overlay.style.top = '50px';
    overlay.style.right = '0';
    overlay.style.backgroundColor = 'white';
    overlay.style.padding = '5px';
    overlay.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
    overlay.style.zIndex = '1000';

    // 创建输入框
    const input1 = document.createElement('input');
    input1.type = 'text';

    const input2 = document.createElement('input');
    input2.type = 'text';

    // 创建按钮
    const button = document.createElement('button');
    button.style.border = '1px solid #9d9494';
    button.style.margin = '0 5px';
    button.style.borderRadius = '3px';
    button.textContent = '序列化并复制';
    button.addEventListener('click', async() => {
        const serializeObj=JSON.parse(JSON.parse(input1.value).body)
        const serializedStr = JSON.stringify(serializeObj);
        input2.value = serializedStr;
        await navigator.clipboard.writeText(serializedStr)
        console.log('伽利略日志json序列化:' ,serializeObj)
        button.textContent = '复制成功';
    });

    // 将元素添加到浮层弹窗
    overlay.appendChild(input1);
    overlay.appendChild(button);
    overlay.appendChild(input2);

    const closeButton = document.createElement('button');
    closeButton.textContent = '关闭';
    closeButton.style.border = '1px solid #9d9494';
    closeButton.style.borderRadius = '3px';
    closeButton.style.marginLeft = '5px';
    closeButton.addEventListener('click', () => {
        overlay.style.display = 'none';
    });

    // 将关闭按钮添加到浮层弹窗
    overlay.appendChild(closeButton);

    // 将浮层弹窗添加到页面
    document.body.appendChild(overlay);

    document.addEventListener('copy', function(event) {
        // 获取选中的文本
        const selectedText = window.getSelection().toString();
        input1.value=selectedText
        button.textContent = '序列化并复制';
    });

})();