Alert to User

Displays a custom modal alert for dilution requirements and non-numerical values, applies a flashing pink background to rows containing ">", and prompts the user to enter a comment if "NO RESULT" is found.

目前为 2024-12-30 提交的版本。查看 最新版本

// ==UserScript==
// @name        Alert to User
// @namespace   Violentmonkey Scripts
// @match       *://his.kaauh.org/lab/*
// @grant       none
// @version     2.3
// @author      Hamad AlShegifi
// @description Displays a custom modal alert for dilution requirements and non-numerical values, applies a flashing pink background to rows containing ">", and prompts the user to enter a comment if "NO RESULT" is found.
// @license     MIT
// ==/UserScript==

(function () {
    'use strict';

    // Function to create a custom modal dialog
    function showModal(message, onConfirm) {
        // Create overlay
        const 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 = "999";
        document.body.appendChild(overlay);

        // Create modal
        const modal = document.createElement("div");
        modal.style.position = "fixed";
        modal.style.top = "50%";
        modal.style.left = "50%";
        modal.style.transform = "translate(-50%, -50%) scale(0.5)";
        modal.style.backgroundColor = "#f4f4f9";
        modal.style.padding = "30px";
        modal.style.boxShadow = "0px 10px 30px rgba(0, 0, 0, 0.15)";
        modal.style.zIndex = "1000";
        modal.style.borderRadius = "15px";
        modal.style.textAlign = "center";
        modal.style.transition = "transform 0.3s ease, opacity 0.3s ease";
        modal.style.opacity = "0";

        // Add heading
        const heading = document.createElement("h2");
        heading.textContent = "Attention!";
        heading.style.fontFamily = "'Arial', sans-serif";
        heading.style.color = "#333";
        heading.style.marginBottom = "10px";
        heading.style.fontSize = "24px";
        modal.appendChild(heading);

        // Add message
        const content = document.createElement("p");
        content.textContent = message;
        content.style.fontFamily = "'Arial', sans-serif";
        content.style.color = "#555";
        content.style.marginBottom = "20px";
        content.style.fontSize = "16px";
        content.style.lineHeight = "1.5";
        modal.appendChild(content);

        // Add input field for user comment
        const input = document.createElement("input");
        input.type = "text";
        input.placeholder = "Enter your comment";
        input.style.padding = "10px";
        input.style.width = "100%";
        input.style.marginBottom = "20px";
        input.style.border = "1px solid #ccc";
        input.style.borderRadius = "5px";
        input.style.fontSize = "16px";
        modal.appendChild(input);

        // Add Confirm button
        const confirmButton = document.createElement("button");
        confirmButton.textContent = "Confirm";
        confirmButton.style.padding = "10px 20px";
        confirmButton.style.border = "none";
        confirmButton.style.backgroundColor = "#ff4081";
        confirmButton.style.color = "white";
        confirmButton.style.borderRadius = "30px";
        confirmButton.style.cursor = "pointer";
        confirmButton.style.fontSize = "16px";
        confirmButton.style.transition = "background-color 0.3s ease, transform 0.2s ease";

        // Add hover effect
        confirmButton.addEventListener("mouseenter", () => {
            confirmButton.style.backgroundColor = "#d81b60";
            confirmButton.style.transform = "scale(1.05)";
        });
        confirmButton.addEventListener("mouseleave", () => {
            confirmButton.style.backgroundColor = "#ff4081";
            confirmButton.style.transform = "scale(1)";
        });

        // Handle Confirm button click
        confirmButton.addEventListener("click", () => {
            const comment = input.value.trim();
            if (comment) {
                onConfirm(comment);
                document.body.removeChild(modal);
                document.body.removeChild(overlay);
            } else {
                alert("Please enter a comment!");
            }
        });
        modal.appendChild(confirmButton);

        // Append modal to the body
        document.body.appendChild(modal);

        // Animate modal appearance
        setTimeout(() => {
            modal.style.transform = "translate(-50%, -50%) scale(1)";
            modal.style.opacity = "1";
        }, 10);
    }

    // Function to replace "NO RESULT" with user comment
    function replaceNoResultWithComment(divElement, comment) {
        if (divElement) {
            divElement.innerText = comment;
        }
    }

    // Function to check for "NO RESULT" and prompt user for comment
    function checkForNoResult() {
        const divs = document.querySelectorAll(
            'div[role="gridcell"][col-id="TestResult"] app-result-value-render div'
        );

        divs.forEach(div => {
            const text = div.textContent.trim();

            if (text === "no result") {
                showModal("Please enter a comment to replace 'NO RESULT':", (comment) => {
                    replaceNoResultWithComment(div, comment);
                });
            }
        });
    }

    // Function to wait for elements to load
    function waitForElements(selector, callback, timeout = 10000) {
        const startTime = Date.now();

        function checkElements() {
            const elements = document.querySelectorAll(selector);
            if (elements.length > 0) {
                callback();
            } else if (Date.now() - startTime < timeout) {
                requestAnimationFrame(checkElements);
            } else {
                console.error("Timeout: Elements not found.");
            }
        }

        checkElements();
    }

    // Wait for the page to load and process elements
    try {
        window.addEventListener('load', () => {
            console.log("Page fully loaded. Waiting for elements...");
            waitForElements(
                'div[role="gridcell"][col-id="TestResult"] app-result-value-render div',
                checkForNoResult
            );
        });
    } catch (error) {
        console.error("An error occurred:", error);
    }
})();

QingJ © 2025

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