云简平台多行粘贴

云简平台多行粘贴v1.1

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         云简平台多行粘贴
// @namespace    http://desire.net/
// @version      2024-06-19
// @description  云简平台多行粘贴v1.1
// @author       Desire
// @match        https://oasis.h3c.com/oasis6/static/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=h3c.com
// @grant        none
// @license      MIT
// ==/UserScript==

function $x(DOCUMENT, STR_XPATH) {
	var xresult = DOCUMENT.evaluate(STR_XPATH, DOCUMENT, null, XPathResult.ANY_TYPE, null);
	var xnodes = [];
	var xres;
	while (xres = xresult.iterateNext()) {
		xnodes.push(xres);
	}
	return xnodes;
}

function waitForElement(selector, callback) {
    var intervalId = setInterval(function() {
        if (document.querySelector(selector)) {
            clearInterval(intervalId);
            callback();
        }
    }, 500);
}

function changeStyle(button){
    var targetButton = $x(document, '//*[@id="app"]/div/div[2]/div[2]/div[3]/div/div[3]/div/div[1]/div[1]/div[3]/button[3]')[0];

    if (targetButton) {
        // 获取目标按钮的所有样式
        var targetStyles = window.getComputedStyle(targetButton);

        // 将目标按钮的样式应用到新的按钮上
        for (var i = 0; i < targetStyles.length; i++) {
            var key = targetStyles[i];
            button.style[key] = targetStyles.getPropertyValue(key);
        }
    }
}

// 创建一个弹窗的函数
function createPopup() {
    // 创建背景遮罩
    var overlay = document.createElement("div");
    overlay.style.position = "fixed";
    overlay.style.top = "0";
    overlay.style.left = "0";
    overlay.style.width = "100%";
    overlay.style.height = "100%";
    overlay.style.backgroundColor = "rgba(0,0,0,0.5)";
    overlay.style.zIndex = "1000";
    document.body.appendChild(overlay);

    // 创建弹窗容器
    var popup = document.createElement("div");
    popup.style.position = "fixed";
    popup.style.top = "50%";
    popup.style.left = "50%";
    popup.style.transform = "translate(-50%, -50%)";
    popup.style.backgroundColor = "#fff";
    popup.style.padding = "20px";
    popup.style.borderRadius = "8px";
    popup.style.boxShadow = "0 0 10px rgba(0,0,0,0.3)";
    popup.style.zIndex = "1001";
    popup.style.width = "400px";
    overlay.appendChild(popup);

    // 创建关闭按钮
    var closeButton = document.createElement("button");
    closeButton.textContent = "×";
    closeButton.style.position = "absolute";
    closeButton.style.top = "10px";
    closeButton.style.right = "10px";
    closeButton.style.padding = "5px 10px";
    closeButton.style.fontSize = "20px";
    closeButton.style.border = "none";
    closeButton.style.backgroundColor = "transparent";
    closeButton.style.color = "#888";
    closeButton.style.cursor = "pointer";
    popup.appendChild(closeButton);

    // 点击关闭按钮时关闭弹窗
    closeButton.addEventListener("click", function() {
        closePopup();
    });

    // 创建多行输入框
    var textarea = document.createElement("textarea");
    textarea.style.width = "95%";
    textarea.style.height = "100px"; // 设置高度为100px,可以根据需要调整
    textarea.style.marginTop = "20px";
    textarea.style.padding = "10px";
    textarea.style.fontSize = "16px";
    textarea.style.border = "1px solid #ccc";
    textarea.style.borderRadius = "4px";
    textarea.placeholder = "请输入多行内容";
    popup.appendChild(textarea);

    // 创建确认按钮
    var confirmButton = document.createElement("button");
    confirmButton.textContent = "确认";
    confirmButton.style.marginTop = "10px";
    confirmButton.style.padding = "8px 20px";
    confirmButton.style.fontSize = "16px";
    confirmButton.style.backgroundColor = "#007bff";
    confirmButton.style.color = "#fff";
    confirmButton.style.border = "none";
    confirmButton.style.borderRadius = "4px";
    confirmButton.style.cursor = "pointer";
    popup.appendChild(confirmButton);

    // 确认按钮点击事件
    confirmButton.addEventListener("click", function() {
        var shellinb = $x(document, '//*[@id="app"]/div/div[2]/div[2]/div[3]/div/div[3]/div/div[1]/div[2]/div/iframe')[0].contentWindow.shellinabox;
        var userInput = textarea.value;
        var lines = userInput.split('\n');
        var time = 150;

        for (var i = 0; i < lines.length; i++) {
            let line = lines[i].trim(); // 去除行首行尾空白字符
            setTimeout(() => shellinb.keysPressed(line + '\r\n'), time);
            time += 150;
        }

        closePopup();
    });

    // 关闭弹窗的函数
    function closePopup() {
        document.body.removeChild(overlay);
    }
}


(function() {
    'use strict';
    // 等待 class 为 "item" 的元素出现后执行代码
    waitForElement(".item", function() {
        var comment = $x(document, '//*[@id="app"]/div/div[2]/div[2]/div[3]/div/div[3]/div/div[1]/div[1]/div[3]')[0];
        var button = document.createElement("button"); //创建一个按钮
        var span = document.createElement("span");
        span.textContent = "多行粘贴";
        changeStyle(button);
        button.appendChild(span);
        button.addEventListener("click", createPopup) //监听按钮点击事件
        comment.appendChild(button); //把按钮加入到 x 的子节点中
    });

})();