Lab Enhancements

Automatically clicks "VERIFY2" and enhances lab page functionality.

// ==UserScript==
// @name           Lab Enhancements
// @namespace      http://tampermonkey.net/
// @version        1.7
// @description    Automatically clicks "VERIFY2" and enhances lab page functionality.
// @match          *://his.kaauh.org/lab/*
// @grant          none
// ==/UserScript==

(function() {
    'use strict';

    // --- Script Configuration ---
    let previousUrl = window.location.href;
    let isScriptEnabled = localStorage.getItem('autoVerifyEnabled') === 'true';
    const delayTime = 1000; // Delay in milliseconds before attempting to click VERIFY2

    // --- Helper Functions ---
    // Load Font Awesome for icons
    function loadFontAwesome() {
        if (!document.querySelector('link[href*="font-awesome"]')) {
            const link = document.createElement('link');
            link.rel = 'stylesheet';
            link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css';
            document.head.appendChild(link);
            console.log('Font Awesome loaded');
        }
    }

    // Check if the URL matches the specific pattern
    function checkUrl() {
        const urlSegments = window.location.href.split('/');
        const lastThreeSegments = urlSegments.slice(-3).join('/');
        return lastThreeSegments === '0/BIOCHEMISTRY/undefined'; // Updated URL pattern
    }

    // Find and click the "VERIFY2" button
    function clickVerifyButton() {
        // Locate button using class and exact text content
        const verifyButton = Array.from(document.querySelectorAll('button.btn.btn-primary.btn-sm'))
            .find(button => button.textContent.trim() === 'VERIFY2');

        if (verifyButton) {
            console.log('VERIFY2 button found:', verifyButton);
            verifyButton.click();
            console.log('VERIFY2 button clicked');
            return true;
        } else {
            console.error('VERIFY2 button not found.');
        }
        return false;
    }

    // Observe DOM changes to detect when "VERIFY2" appears
    function observeDOMForVerifyButton() {
        const observer = new MutationObserver(() => {
            if (clickVerifyButton()) {
                observer.disconnect(); // Stop observing once button is clicked
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    // Handle URL changes and attempt to click VERIFY2
    function handleUrlChange() {
        if (isScriptEnabled && checkUrl()) {
            console.log('URL ends with "/0/BIOCHEMISTRY/undefined". Waiting to click VERIFY2...');
            setTimeout(() => {
                if (!clickVerifyButton()) {
                    console.log('VERIFY2 button not immediately found. Observing DOM changes...');
                    observeDOMForVerifyButton();
                }
            }, delayTime);
        }
    }

    // --- UI Enhancements ---
    // Add a toggle button to enable/disable the script
    function addToggleButton() {
        const button = document.createElement('button');
        button.className = 'app-btn'; // Use existing button class for consistency
        button.style.marginLeft = '10px';
        button.style.padding = '10px 15px';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '25px'; // Rounded corners
        button.style.cursor = 'pointer';
        button.style.position = 'relative';
        button.style.zIndex = '1000'; // Ensure it is on top
        button.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.2)'; // Add shadow
        button.style.transition = 'background-color 0.3s, transform 0.3s'; // Smooth transition

        updateButtonAppearance(button);

        button.onclick = function() {
            isScriptEnabled = !isScriptEnabled;
            localStorage.setItem('autoVerifyEnabled', isScriptEnabled);
            updateButtonAppearance(button);
            console.log('Script is now ' + (isScriptEnabled ? 'enabled' : 'disabled'));
        };

        const targetObserver = new MutationObserver(() => {
            const targetLi = document.querySelector('.nav-item.clock-nav');
            if (targetLi) {
                targetLi.appendChild(button);
                targetObserver.disconnect(); // Stop observing once the button is added
                console.log('Toggle button added to clock-nav');
            }
        });
        targetObserver.observe(document.body, { childList: true, subtree: true });
    }

    // Update the toggle button appearance
    function updateButtonAppearance(button) {
        button.innerHTML = isScriptEnabled ?
            '<i class="fa-solid fa-badge-check" style="color: white; margin-right: 5px;"></i>Auto Verify 2' :
            'Auto Verify 2';
        button.style.backgroundColor = isScriptEnabled ? '#28a745' : '#d1d4c9'; // Green when active, gray when inactive

        // Add hover effects
        button.onmouseover = function() {
            button.style.backgroundColor = isScriptEnabled ? '#218838' : '#b0b3b8'; // Darker shade on hover
            button.style.transform = 'scale(1.05)'; // Slightly larger on hover
        };
        button.onmouseout = function() {
            button.style.backgroundColor = isScriptEnabled ? '#28a745' : '#d1d4c9'; // Original color
            button.style.transform = 'scale(1)'; // Normal size
        };
    }

    // --- Initialization ---
    loadFontAwesome();
    setInterval(() => {
        if (previousUrl !== window.location.href) {
            console.log('URL changed:', window.location.href);
            previousUrl = window.location.href;
            handleUrlChange();
        }
    }, 500);

    handleUrlChange();
    addToggleButton();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址