Greasy Fork

AGSV盒子审核助手

盒子审核页面按钮固定

当前为 2025-07-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         AGSV盒子审核助手
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  盒子审核页面按钮固定
// @author       AGSV骄阳
// @match        https://www.agsvpt.com/nexusphp/seed-box-records?tableFilters[status][value]=0
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict';

    // 添加自定义样式
    GM_addStyle(`
        .action-buttons {
            display: flex;
            gap: 10px; /* 按钮间距 */
            align-items: center; /* 垂直居中对齐 */
            justify-content: flex-start; /* 左对齐 */
        }

        .action-button {
            background-color: white; /* 按钮背景色 */
            border: 1px solid #ccc; /* 按钮边框 */
            padding: 5px 10px; /* 按钮内边距 */
            border-radius: 5px; /* 按钮圆角 */
            cursor: pointer; /* 鼠标光标 */
            text-align: center; /* 文本居中 */
        }

        .action-button:hover {
            background-color: #f0f0f0; /* 悬停时的背景色 */
        }

        .button-container {
            display: flex;
            justify-content: flex-start; /* 默认左对齐 */
        }

        .highlight {
            background-color: red; /* 红色高亮 */
            color: white; /* 白色文字 */
        }
    `);

    // 创建空白列
    function addEmptyHeaderColumn() {
        const headerRow = document.querySelector('thead tr'); // 寻找标题行
        if (headerRow) {
            const emptyHeaderCell = document.createElement('th');
            emptyHeaderCell.style.width = '80px'; // 设置宽度,与按钮相同
            headerRow.insertBefore(emptyHeaderCell, headerRow.firstChild); // 将空白列插入到最前面
        }
    }

    // 创建按钮的函数
    function createButtons() {
        const rows = document.querySelectorAll('tr'); // 寻找所有行

        // 需要检测的关键词
        const keywords = ["azure", "google cloud", "aws", "oracle cloud", "digital ocean", "linode", "vultr", "甲骨文", "oracle"];
        // 将关键词转换为小写以便进行不区分大小写的比较
        const lowerCaseKeywords = keywords.map(keyword => keyword.toLowerCase());

        rows.forEach(row => {
            const editButton = row.querySelector('a[dusk="filament.tables.action.edit"]'); // 编辑按钮
            const changeStatusButton = row.querySelector('button[dusk="filament.tables.action.audit"]'); // 更改状态按钮

            if (editButton && changeStatusButton) {
                const existingContainer = row.querySelector('.button-container');
                if (existingContainer) {
                    return; // 如果已有按钮容器则跳过
                }

                // 创建按钮容器
                const buttonContainer = document.createElement('div');
                buttonContainer.classList.add('button-container');

                // 创建编辑按钮
                const newEditButton = document.createElement('div');
                newEditButton.classList.add('action-button');
                newEditButton.innerText = '编辑';
                newEditButton.onclick = () => {
                    window.location.href = editButton.href; // 导航到编辑页面
                };

                // 创建更改状态按钮
                const newChangeStatusButton = document.createElement('div');
                newChangeStatusButton.classList.add('action-button');
                newChangeStatusButton.innerText = '更改状态';
                newChangeStatusButton.onclick = () => {
                    changeStatusButton.click(); // 模拟点击更改状态按钮
                };

                // 检查行中是否包含指定关键词
                const spanElements = row.querySelectorAll('span');
                let highlightStatus = false;

                spanElements.forEach(span => {
                    const spanText = span.textContent.trim().toLowerCase(); // 转换为小写进行比较
                    if (lowerCaseKeywords.includes(spanText)) {
                        highlightStatus = true; // 找到匹配的关键词
                    }
                });

                // 如果找到关键词,则高亮更改状态按钮
                if (highlightStatus) {
                    newChangeStatusButton.classList.add('highlight');
                }

                // 将按钮添加到容器
                buttonContainer.appendChild(newEditButton);
                buttonContainer.appendChild(newChangeStatusButton);

                // 将按钮容器添加到行的最左侧
                row.insertBefore(buttonContainer, row.firstChild);
            }
        });
    }

    // 初始创建空白列和按钮
    addEmptyHeaderColumn();
    createButtons();

    // 监控DOM变化
    const observer = new MutationObserver(() => {
        createButtons(); // 监控到变化时重新创建按钮
    });

    const table = document.querySelector('table');
    if (table) {
        observer.observe(table, {
            childList: true,
            subtree: true
        });
    }
})();