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 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Alert to User
  3. // @namespace Violentmonkey Scripts
  4. // @match *://his.kaauh.org/lab/*
  5. // @grant none
  6. // @version 2.3
  7. // @author Hamad AlShegifi
  8. // @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.
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Function to create a custom modal dialog
  16. function showModal(message, onConfirm) {
  17. // Create overlay
  18. const overlay = document.createElement("div");
  19. overlay.style.position = "fixed";
  20. overlay.style.top = "0";
  21. overlay.style.left = "0";
  22. overlay.style.width = "100%";
  23. overlay.style.height = "100%";
  24. overlay.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
  25. overlay.style.zIndex = "999";
  26. document.body.appendChild(overlay);
  27.  
  28. // Create modal
  29. const modal = document.createElement("div");
  30. modal.style.position = "fixed";
  31. modal.style.top = "50%";
  32. modal.style.left = "50%";
  33. modal.style.transform = "translate(-50%, -50%) scale(0.5)";
  34. modal.style.backgroundColor = "#f4f4f9";
  35. modal.style.padding = "30px";
  36. modal.style.boxShadow = "0px 10px 30px rgba(0, 0, 0, 0.15)";
  37. modal.style.zIndex = "1000";
  38. modal.style.borderRadius = "15px";
  39. modal.style.textAlign = "center";
  40. modal.style.transition = "transform 0.3s ease, opacity 0.3s ease";
  41. modal.style.opacity = "0";
  42.  
  43. // Add heading
  44. const heading = document.createElement("h2");
  45. heading.textContent = "Attention!";
  46. heading.style.fontFamily = "'Arial', sans-serif";
  47. heading.style.color = "#333";
  48. heading.style.marginBottom = "10px";
  49. heading.style.fontSize = "24px";
  50. modal.appendChild(heading);
  51.  
  52. // Add message
  53. const content = document.createElement("p");
  54. content.textContent = message;
  55. content.style.fontFamily = "'Arial', sans-serif";
  56. content.style.color = "#555";
  57. content.style.marginBottom = "20px";
  58. content.style.fontSize = "16px";
  59. content.style.lineHeight = "1.5";
  60. modal.appendChild(content);
  61.  
  62. // Add input field for user comment
  63. const input = document.createElement("input");
  64. input.type = "text";
  65. input.placeholder = "Enter your comment";
  66. input.style.padding = "10px";
  67. input.style.width = "100%";
  68. input.style.marginBottom = "20px";
  69. input.style.border = "1px solid #ccc";
  70. input.style.borderRadius = "5px";
  71. input.style.fontSize = "16px";
  72. modal.appendChild(input);
  73.  
  74. // Add Confirm button
  75. const confirmButton = document.createElement("button");
  76. confirmButton.textContent = "Confirm";
  77. confirmButton.style.padding = "10px 20px";
  78. confirmButton.style.border = "none";
  79. confirmButton.style.backgroundColor = "#ff4081";
  80. confirmButton.style.color = "white";
  81. confirmButton.style.borderRadius = "30px";
  82. confirmButton.style.cursor = "pointer";
  83. confirmButton.style.fontSize = "16px";
  84. confirmButton.style.transition = "background-color 0.3s ease, transform 0.2s ease";
  85.  
  86. // Add hover effect
  87. confirmButton.addEventListener("mouseenter", () => {
  88. confirmButton.style.backgroundColor = "#d81b60";
  89. confirmButton.style.transform = "scale(1.05)";
  90. });
  91. confirmButton.addEventListener("mouseleave", () => {
  92. confirmButton.style.backgroundColor = "#ff4081";
  93. confirmButton.style.transform = "scale(1)";
  94. });
  95.  
  96. // Handle Confirm button click
  97. confirmButton.addEventListener("click", () => {
  98. const comment = input.value.trim();
  99. if (comment) {
  100. onConfirm(comment);
  101. document.body.removeChild(modal);
  102. document.body.removeChild(overlay);
  103. } else {
  104. alert("Please enter a comment!");
  105. }
  106. });
  107. modal.appendChild(confirmButton);
  108.  
  109. // Append modal to the body
  110. document.body.appendChild(modal);
  111.  
  112. // Animate modal appearance
  113. setTimeout(() => {
  114. modal.style.transform = "translate(-50%, -50%) scale(1)";
  115. modal.style.opacity = "1";
  116. }, 10);
  117. }
  118.  
  119. // Function to replace "NO RESULT" with user comment
  120. function replaceNoResultWithComment(divElement, comment) {
  121. if (divElement) {
  122. divElement.innerText = comment;
  123. }
  124. }
  125.  
  126. // Function to check for "NO RESULT" and prompt user for comment
  127. function checkForNoResult() {
  128. const divs = document.querySelectorAll(
  129. 'div[role="gridcell"][col-id="TestResult"] app-result-value-render div'
  130. );
  131.  
  132. divs.forEach(div => {
  133. const text = div.textContent.trim();
  134.  
  135. if (text === "no result") {
  136. showModal("Please enter a comment to replace 'NO RESULT':", (comment) => {
  137. replaceNoResultWithComment(div, comment);
  138. });
  139. }
  140. });
  141. }
  142.  
  143. // Function to wait for elements to load
  144. function waitForElements(selector, callback, timeout = 10000) {
  145. const startTime = Date.now();
  146.  
  147. function checkElements() {
  148. const elements = document.querySelectorAll(selector);
  149. if (elements.length > 0) {
  150. callback();
  151. } else if (Date.now() - startTime < timeout) {
  152. requestAnimationFrame(checkElements);
  153. } else {
  154. console.error("Timeout: Elements not found.");
  155. }
  156. }
  157.  
  158. checkElements();
  159. }
  160.  
  161. // Wait for the page to load and process elements
  162. try {
  163. window.addEventListener('load', () => {
  164. console.log("Page fully loaded. Waiting for elements...");
  165. waitForElements(
  166. 'div[role="gridcell"][col-id="TestResult"] app-result-value-render div',
  167. checkForNoResult
  168. );
  169. });
  170. } catch (error) {
  171. console.error("An error occurred:", error);
  172. }
  173. })();

QingJ © 2025

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