Alert to User

Displays a custom modal alert for dilution requirements and non-numerical values, and applies a flashing pink background to rows containing ">".

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

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

(function () {
    'use strict';

    // Function to create a custom modal dialog
    function showModal(message) {
        // 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 OK button
        const okButton = document.createElement("button");
        okButton.textContent = "OK";
        okButton.style.padding = "10px 20px";
        okButton.style.border = "none";
        okButton.style.backgroundColor = "#ff4081";
        okButton.style.color = "white";
        okButton.style.borderRadius = "30px";
        okButton.style.cursor = "pointer";
        okButton.style.fontSize = "16px";
        okButton.style.transition = "background-color 0.3s ease, transform 0.2s ease";

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

        // Close modal on click
        okButton.addEventListener("click", () => {
            document.body.removeChild(modal);
            document.body.removeChild(overlay);
        });
        modal.appendChild(okButton);

        // 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 apply flashing pink background to rows
    function applyFlashingPinkToRows(rows) {
        rows.forEach(row => {
            row.style.transition = "background-color 0.5s ease";
            row.style.backgroundColor = "transparent";

            // Flash pink background
            setInterval(() => {
                row.style.backgroundColor = row.style.backgroundColor === "pink" ? "transparent" : "pink";
            }, 500);
        });
    }

    // Function to check if a value is numerical
    function isNumerical(value) {
        return !isNaN(parseFloat(value)) && isFinite(value);
    }

    // Function to check for ">" symbol and non-numerical values
    function checkForDilution() {
        const divs = document.querySelectorAll(
            'div[role="gridcell"][col-id="TestResult"] app-result-value-render div'
        );

        const rowsToFlash = [];
        let hasNonNumericalValue = false;

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

            // Check for ">" symbol
            if (text.includes(">")) {
                const row = div.closest("div[role='row']");
                if (row) rowsToFlash.push(row);
            }

            // Check for non-numerical values
            if (text && !isNumerical(text)) {
                hasNonNumericalValue = true;
            }
        });

        // Apply flashing effect to rows with ">"
        if (rowsToFlash.length > 0) {
            applyFlashingPinkToRows(rowsToFlash);
            showModal("Dilution is required for this sample !!");
        }

        // Alert for non-numerical values
        if (hasNonNumericalValue) {
            showModal("Non-numerical value detected in the results !!");
        }
    }

    // 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 elements to be available
    window.addEventListener('load', () => {
        console.log("Page fully loaded. Waiting for elements...");
        waitForElements(
            'div[role="gridcell"][col-id="TestResult"] app-result-value-render div',
            checkForDilution
        );
    });
})();

QingJ © 2025

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