伽利略日志json序列化

json序列化

当前为 2024-12-05 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         伽利略日志json序列化
// @namespace    http://tampermonkey.net/
// @version      20241205
// @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 = '9999';

    // 创建输入框
    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 = '序列化并复制';
    },true);

})();