fanzhenhua / 气象数据填写

// ==UserScript==
// @name         气象数据填写
// @description  仅支持私人内网网站使用!
// @version      0.0.1
// @author       FanZhenHua
// @match        *://www.jyshare.com/front-end/5575*
// @match        *://10.1.65.226/index.html*
// @connect      */radarParam/selectRadarParams/*    // 匹配Api接口链接,禁止跨域弹窗
// @grant        GM_xmlhttpRequest
// @require      https://unpkg.com/mammoth/mammoth.browser.min.js
// @license      MIT
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAC79JREFUeJztWQlwVdUZ/s659749yctmQiAISUBQGZBNQUasGq21IAw6Uqud1uK0xY7OaKcdxHZa7TjadpwOuLSOqKOVsWDraLHaFtcBhUJToAEMBCIJWUjysrz93e30v9tLImUTMdMZT/Jy37vv3HO+7/+/fzkg4/98yKMN4GzHlwRGe3xJ4GzHsZafBYTp1ytrV+uf5flRJRBvXDjPZ7z3NzOT/KT3o8u/VjZv69EzXeOcE+hrWBoIFmRuB8xQRguvK7nw1aR1v2Pfd2VFNNzNdb0ARnKabGavodvPn+n655yASLYs4Iqxhvv9gaCcvGFg79fvjF606UjI2FfPJXURdANckiDz3AgCseY7C3wYmJHTgzvLpryQGTUCaS3SF8wdzXBJBCRJqw8q+rbMoeufYUZsOdPNMKCDMUDyi6/Edi8u94VCYUWK/4CheSVT+yJmT/ZXtMxPRo2ACM04bBqtfQJGsWVthlwlNxIPwIwDRoomCAhI4EpkTDgUf5uzVJQZiXFCS9KlH9lenj3Z+uecwPh5jw8kd0zohtBqRW6AdkyChf3gvnEAG0/4cxBGD1guxpDonybkUrqvEClAjau6qpe/9YUS6Gl+UJLN5jrOcgUSM8MSz9TxTMtEM9cGXsTAgzPBeBWB7qe4TtgeADsPzF9OOuqgmGknrgWAUgAty9/J+SftBj7+Ygh07LxPCqY2rvFFipYROj8EU5iuB029j7OIBu6/hG5zmOoOBzwMwm/ZmpPF/R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Wi4Aa2x90AAAAASUVORK5CYII=
// ==/UserScript==

/* 创建一个按钮组元素 */
function buttonBoxGroup() {
    const buttonGroup = document.createElement("div");
    // 设置按钮为悬浮固定定位,使其在页面滚动时位置不变
    buttonGroup.style.position = "fixed";
    buttonGroup.style.left = "35px";
    buttonGroup.style.top = "520px";
    buttonGroup.style.zIndex = "9999";
    // buttonGroup.style.backgroundColor = "#F5F5FB"; // 背景颜色
    buttonGroup.style.border = "none"; // 去除边框
    buttonGroup.style.borderRadius = "5px"; // 添加圆角
    buttonGroup.style.padding = "10px"; // 添加内边距
    buttonGroup.style.gap = "5px"; // 子元素间间距
    buttonGroup.style.cursor = "move"; // 鼠标指针
    buttonGroup.style.display = "flex"; //弹性布局
    buttonGroup.style.flexDirection = "column"; // 垂直排列
    buttonGroup.style.boxShadow = "0 4px 6px rgba(0, 0, 0, 0.1)"; // 添加阴影
    document.body.appendChild(buttonGroup);
    return buttonGroup;
}

const buttonGroup = buttonBoxGroup(); // 创建按钮组元素
/* 创建一个按钮元素 */
function buttonBox(textContent) {
    const button = document.createElement("button");
    button.textContent = textContent;
    button.style.color = "white"; // 字体颜色
    button.style.fontSize = "20px"; // 字体大小
    button.style.backgroundColor = "#325D88"; // 背景颜色
    button.style.border = "none"; // 去除边框
    button.style.borderRadius = "5px"; // 添加圆角
    button.style.padding = "8px"; // 添加内边距
    buttonGroup.appendChild(button);
    return button;
}

/* 启用-禁用 按钮 */
function disabledButtonGroup(state, button) {
    if (state) {
        // 计算按钮偏移量
        const dx = Math.abs(parseInt(buttonGroup.style.left) - parseInt(startX));
        const dy = Math.abs(parseInt(buttonGroup.style.top) - parseInt(startY));
        // 移动量均小于3
        if (dx < 3 && dy < 3) {
            button.disabled = true; // 禁用按钮
            button.style.backgroundColor = "#CDCDCD";
            button.style.cursor = "not-allowed";
            return true;
        }
        return false;
    } else {
        // 取消禁用
        button.disabled = false;
        button.style.backgroundColor = "#325D88";
        button.style.cursor = "pointer";
        return false;
    }
}

const tipBoxes = []; // 记录所有提示框元素的数组
/* 计算并设置所有提示框的位置 */
function setTipBoxesPosition() {
    const totalHeight = tipBoxes.reduce((sum, box) => sum + box.offsetHeight, 0);
    const gap = 5;
    const totalGap = (tipBoxes.length - 1) * gap;
    const startTop = (window.innerHeight - totalHeight - totalGap) / 2;

    let currentTop = startTop;
    tipBoxes.forEach((box) => {
        box.style.top = `${currentTop}px`;
        currentTop += box.offsetHeight + gap;
    });
}

/* 创建并显示悬浮提示框 */
function showTipsBox(text, color = "black") {
    const popup = document.createElement("div");
    // popup.textContent = text;
    // 将字符串中的 \n 替换为 <br>
    const textWithBreaks = text.replace(/\n/g, "<br>");
    popup.innerHTML = textWithBreaks;
    // 设置基本样式
    popup.style.position = "fixed";
    popup.style.left = "50%";
    popup.style.transform = "translateX(-50%)";
    popup.style.color = color; // 字体颜色
    popup.style.fontSize = "22px"; // 字体大小
    popup.style.backgroundColor = "lightblue"; // 背景色
    popup.style.opacity = "0.6"; // 透明度
    popup.style.padding = "15px";
    popup.style.zIndex = "10000"; // 前置等级
    popup.style.textAlign = "center"; // 设置文本水平居中
    popup.style.border = "none"; // 去除边框
    popup.style.borderRadius = "10px"; // 添加圆角

    document.body.appendChild(popup);
    tipBoxes.push(popup);
    setTipBoxesPosition(); // 计算并设置所有提示框的位置

    // 定时移除提示框
    setTimeout(() => {
        document.body.removeChild(popup);
        const index = tipBoxes.indexOf(popup);
        if (index > -1) {
            tipBoxes.splice(index, 1);
            setTipBoxesPosition(); // 计算并设置所有提示框的位置
        }
    }, 8000);
}

/* 添加事件侦听器 */
function addMyEventListener() {
    let isDragging = false;
    let initialX, initialY, currentX, currentY;
    (startX = 0), (startY = 0); // 全局变量

    // 鼠标按下事件处理函数
    const handleMouseDown = (e) => {
        isDragging = true;
        initialX = e.clientX;
        initialY = e.clientY;
        startX = buttonGroup.style.left;
        startY = buttonGroup.style.top;
    };

    // 鼠标抬起事件处理函数
    const handleMouseUp = () => {
        isDragging = false;
    };

    // 鼠标移动事件处理函数
    const handleMouseMove = (e) => {
        if (isDragging) {
            currentX = e.clientX;
            currentY = e.clientY;
            const diffX = currentX - initialX;
            const diffY = currentY - initialY;
            const left = parseInt(buttonGroup.style.left) + diffX;
            const top = parseInt(buttonGroup.style.top) + diffY;
            buttonGroup.style.left = left + "px";
            buttonGroup.style.top = top + "px";
            initialX = currentX;
            initialY = currentY;
        }
    };

    // 绑定事件
    buttonGroup.addEventListener("mousedown", handleMouseDown);
    document.addEventListener("mouseup", handleMouseUp);
    document.addEventListener("mousemove", handleMouseMove);
}

function main() {
    addMyEventListener(); // 添加事件侦听器
    var button = buttonBox("填写数据");

    // 按钮点击事件处理函数
    button.addEventListener("click", async function () {
        const result = disabledButtonGroup(true, this); // 禁用按钮
        if (result) {
            showTipsBox(`请联系作者!`, "red");
        }
        disabledButtonGroup(false, this); // 启用按钮
    });
}

main();