Useless Things Series: Circle 4 - Eye Simulation

It display a small circle, within a blue circle, within a red circle. The point is it simulate and look like an eye it will follow the mouse movement.

  1. // ==UserScript==
  2. // @name Useless Things Series: Circle 4 - Eye Simulation
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description It display a small circle, within a blue circle, within a red circle. The point is it simulate and look like an eye it will follow the mouse movement.
  6. // @match *://*/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace https://gf.qytechs.cn/users/1126616
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to create a circle
  16. function createCircle(container, centerX, centerY, bigCircleWidth, bigCircleHeight) {
  17. // Maximum radius that the red circle can pass through (adjustable by the user)
  18. let maxAllowedRadius = 50;
  19.  
  20. // Create the big blue circle
  21. const bigCircle = document.createElement('div');
  22. bigCircle.style.position = 'absolute';
  23. bigCircle.style.width = `${bigCircleWidth}px`;
  24. bigCircle.style.height = `${bigCircleHeight + 2}px`;
  25. bigCircle.style.border = '3px dashed blue'; // Change border style here
  26. bigCircle.style.borderRadius = '90% /90%'; // Eye-shaped border-radius
  27. bigCircle.style.left = `${centerX - bigCircleWidth / 2}px`;
  28. bigCircle.style.top = `${centerY - bigCircleHeight / 2}px`;
  29. container.appendChild(bigCircle);
  30.  
  31. // Create the big red circle
  32. const bigCircleAbove = document.createElement('div');
  33. bigCircleAbove.style.position = 'absolute';
  34. bigCircleAbove.style.width = `${bigCircleWidth + 100}px`; // Larger width
  35. bigCircleAbove.style.height = `${bigCircleHeight}px`;
  36. bigCircleAbove.style.border = '5px solid red'; // Change border style here
  37. bigCircleAbove.style.borderRadius = '100% /100%'; // Eye-shaped border-radius
  38. bigCircleAbove.style.left = `${centerX - (bigCircleWidth + 100) / 2}px`;
  39. bigCircleAbove.style.top = `${centerY - bigCircleHeight / 2}px`;
  40. container.appendChild(bigCircleAbove);
  41.  
  42. // Create the small red filled circle
  43. const smallCircle = document.createElement('div');
  44. smallCircle.style.width = '60px';
  45. smallCircle.style.height = '60px';
  46. smallCircle.style.borderRadius = '50%';
  47. smallCircle.style.backgroundColor = 'red';
  48. smallCircle.style.position = 'absolute';
  49. smallCircle.style.transition = 'all 0.1s ease-out'; // Smooth transition
  50. smallCircle.style.zIndex = '9999'; // Ensure it's above other elements
  51. smallCircle.style.pointerEvents = 'auto'; // Make it clickable
  52. container.appendChild(smallCircle);
  53.  
  54. // Add event listener to prevent mouse pass-through
  55. smallCircle.addEventListener('mousemove', function(event) {
  56. event.stopPropagation();
  57. });
  58.  
  59. // Add event listener for mouse movement
  60. let timeout;
  61. document.addEventListener('mousemove', function(event) {
  62. clearTimeout(timeout); // Reset the timeout on mouse movement
  63. // Calculate the distance between the mouse position and the center of the screen
  64. const distance = Math.sqrt(Math.pow(event.clientX - centerX, 2) + Math.pow(event.clientY - centerY, 2));
  65.  
  66. // Ensure the distance does not exceed the maximum allowed radius
  67. if (distance >= maxAllowedRadius) {
  68. // Calculate the angle between the mouse position and the center of the screen
  69. const angle = Math.atan2(event.clientY - centerY, event.clientX - centerX);
  70. // Calculate the position of the small circle on the circumference of the blue circle
  71. const smallCircleX = centerX + maxAllowedRadius * Math.cos(angle) - 20;
  72. const smallCircleY = centerY + maxAllowedRadius * Math.sin(angle) - 20;
  73. // Set the position of the small circle
  74. smallCircle.style.left = `${smallCircleX}px`;
  75. smallCircle.style.top = `${smallCircleY}px`;
  76. } else {
  77. // Set the position of the small circle to the mouse position
  78. smallCircle.style.left = `${event.clientX - 20}px`;
  79. smallCircle.style.top = `${event.clientY - 20}px`;
  80. }
  81. });
  82.  
  83. // Function to move the small circle to the center when there is no mouse movement after a certain time
  84. function moveToCenter() {
  85. const smallCircleX = centerX - 20;
  86. const smallCircleY = centerY - 20;
  87. smallCircle.style.left = `${smallCircleX}px`;
  88. smallCircle.style.top = `${smallCircleY}px`;
  89. }
  90.  
  91. // Set a timeout to move the small circle to the center after 2 seconds of inactivity
  92. document.addEventListener('mousemove', function() {
  93. clearTimeout(timeout);
  94. timeout = setTimeout(moveToCenter, 2000);
  95. });
  96.  
  97. // Function to set the maximum allowed radius
  98. function setMaxAllowedRadius(radius) {
  99. maxAllowedRadius = radius;
  100. }
  101.  
  102. // Expose the function to the global scope
  103. window.setMaxAllowedRadius = setMaxAllowedRadius;
  104.  
  105. // Add event listener to remove the circle when clicked
  106. smallCircle.addEventListener('click', function() {
  107. // Remove all circles
  108. container.removeChild(bigCircle);
  109. container.removeChild(bigCircleAbove);
  110. container.removeChild(smallCircle);
  111. // Show the circle again after 3 seconds
  112. setTimeout(function() {
  113. container.appendChild(bigCircle);
  114. container.appendChild(bigCircleAbove);
  115. container.appendChild(smallCircle);
  116. }, 3000);
  117. });
  118.  
  119.  
  120. }
  121.  
  122. // Create a container for the circles
  123. const container = document.createElement('div');
  124. container.classList.add('shape'); // Add a class for easier selection
  125. container.style.position = 'fixed';
  126. container.style.top = '0';
  127. container.style.left = '0';
  128. container.style.width = '100%';
  129. container.style.height = '100%';
  130. container.style.pointerEvents = 'none';
  131. container.style.zIndex = '9999';
  132. document.body.appendChild(container);
  133.  
  134. // Get the center coordinates of the screen
  135. const centerX = window.innerWidth / 2;
  136. const centerY = window.innerHeight / 2;
  137.  
  138. // Create circles positioned at the left and right centers of the screen
  139. createCircle(container, centerX / 2, centerY, 200, 170); // Left center
  140. createCircle(container, centerX + centerX / 2, centerY, 200, 170); // Right center
  141.  
  142. function addMouthCircle() {
  143. let distanceFromBottom = 10;
  144.  
  145. // Create the resizing circle container
  146. const resizingCircleContainer = document.createElement('div');
  147. resizingCircleContainer.classList.add('shape'); // Add a class for easier selection
  148. resizingCircleContainer.style.position = 'fixed';
  149. resizingCircleContainer.style.bottom = `${distanceFromBottom}px`; // Distance from the bottom of the screen
  150. resizingCircleContainer.style.left = '50%'; // Center horizontally
  151. resizingCircleContainer.style.transform = 'translateX(-50%)'; // Adjust horizontal position to center
  152. resizingCircleContainer.style.transition = 'all 0.1s ease-out'; // Smooth transition
  153. resizingCircleContainer.style.borderRadius = '50% /90%'; // Oval shape
  154. resizingCircleContainer.style.zIndex = '10000';
  155. document.body.appendChild(resizingCircleContainer);
  156.  
  157. // Create the resizing circle
  158. const resizingCircle = document.createElement('div');
  159. resizingCircle.style.width = '60px'; // Initial width
  160. resizingCircle.style.height = '60px'; // Initial height
  161. resizingCircle.style.borderRadius = '50%';
  162. resizingCircle.style.border = '2px solid black'; // Outline color and thickness
  163. resizingCircle.style.backgroundColor = 'blue'; // Default fill color of the circle
  164. resizingCircle.style.position = 'relative';
  165. resizingCircle.style.transition = 'all 0.1s ease-out'; // Smooth transition
  166. resizingCircleContainer.appendChild(resizingCircle);
  167.  
  168. // Create the small circle inside the resizing circle
  169. const smallCircle = document.createElement('div');
  170. smallCircle.style.width = '40px'; // Initial width
  171. smallCircle.style.height = '40px'; // Initial height
  172. smallCircle.style.borderRadius = '20%';
  173. smallCircle.style.backgroundColor = 'red'; // Fill color of the small circle
  174. smallCircle.style.position = 'absolute';
  175. smallCircle.style.left = '50%'; // Center horizontally
  176. smallCircle.style.top = '70%'; // Center vertically
  177. smallCircle.style.transform = 'translate(-50%, -50%)'; // Adjust position to center
  178. resizingCircle.appendChild(smallCircle);
  179.  
  180. // Add event listener for mouse movement
  181. document.addEventListener('mousemove', function(event) {
  182. const distance = Math.sqrt(Math.pow(event.clientX - centerX, 2) + Math.pow(event.clientY - (window.innerHeight - distanceFromBottom), 2));
  183. const maxSize = 200; // Maximum size of the circle when mouse is far
  184. const minSize = 0; // Minimum size of the circle when mouse is near
  185. const newSize = maxSize - distance * 0.3; // Adjust size based on distance
  186. resizingCircle.style.width = `${Math.max(minSize, newSize)}px`;
  187. resizingCircle.style.height = `${Math.max(minSize, newSize)}px`;
  188. smallCircle.style.width = `${Math.max(minSize / 2, newSize / 2)}px`; // Adjust size of the small circle
  189. smallCircle.style.height = `${Math.max(minSize / 2, newSize / 2)}px`;
  190. });
  191.  
  192. // Add event listener for click event on the resizing circle
  193. resizingCircle.addEventListener('click', function() {
  194. // Enlarge the circles
  195. resizingCircle.style.width = '900px';
  196. resizingCircle.style.height = '900px';
  197. // Enlarge the small circle
  198. smallCircle.style.width = '600px';
  199. smallCircle.style.height = '600px';
  200. });
  201.  
  202. }
  203. addMouthCircle();
  204.  
  205. function createNose(container, centerX1, centerX2, distanceFromTop, triangleSize) {
  206. // Calculate the midpoint between the centers of the two circles
  207. const midX = (centerX1 + centerX2) / 2;
  208. const centerY = window.innerHeight / 2; // Automatically calculate the vertical center
  209.  
  210. // Create the container for the nose triangle
  211. const noseContainer = document.createElement('div');
  212. noseContainer.classList.add('shape'); // Add a class for easier selection
  213. noseContainer.style.position = 'absolute';
  214. noseContainer.style.top = `${distanceFromTop}px`; // Set the distance from the top of the screen
  215. noseContainer.style.left = `${midX}px`; // Center horizontally
  216. noseContainer.style.transform = 'translateX(-50%)'; // Adjust horizontal position to center
  217. container.appendChild(noseContainer);
  218.  
  219. // Create the triangle
  220. const triangle = document.createElement('div');
  221. triangle.style.width = '0';
  222. triangle.style.height = '0';
  223. triangle.style.borderLeft = `${triangleSize / 2}px solid transparent`;
  224. triangle.style.borderRight = `${triangleSize / 2}px solid transparent`;
  225. triangle.style.borderBottom = `${triangleSize}px solid #00FF00`; // Green color using hex code
  226. noseContainer.appendChild(triangle);
  227.  
  228. }
  229.  
  230. // Call createNose function to create the nose
  231. createNose(container, centerX / 2, centerX + centerX / 2, 450, 50); // Adjust the size and position of the nose as needed
  232.  
  233.  
  234. // Add event listener to the document for the 'keydown' event
  235. document.addEventListener('keydown', function(event) {
  236. if (event.key === 'e' || event.key === 'E') { // Check if 'e' key is pressed
  237. toggleShapesVisibility(); // Toggle visibility of all shapes
  238. }
  239. });
  240.  
  241. // Function to toggle the visibility of all shapes
  242. function toggleShapesVisibility() {
  243. const allShapes = document.querySelectorAll('.shape'); // Select all shapes
  244. allShapes.forEach(shape => {
  245. if (shape.style.display === 'none') {
  246. shape.style.display = 'block'; // Show hidden shapes
  247. } else {
  248. shape.style.display = 'none'; // Hide visible shapes
  249. }
  250. });
  251. }
  252.  
  253. function hideShapes() {
  254. const allShapes = document.querySelectorAll('.shape'); // Select all shapes
  255. allShapes.forEach(shape => {
  256. shape.style.display = 'none'; // Hide all shapes
  257. });
  258. }
  259.  
  260. hideShapes();
  261.  
  262. })();

QingJ © 2025

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