NERD Inserter

just enable it and see what happens

当前为 2024-01-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name NERD Inserter
  3. // @namespace nerd-inserter
  4. // @homepageURL https://c2g.at
  5. // @description just enable it and see what happens
  6. // @author c2g_at
  7. // @match *://*.wikipedia.org/*
  8. // @match *://*.google.*/search*
  9. // @version 0.0.1.20240131233310
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13.  
  14. var mouseX = 0;
  15. var mouseY = 0;
  16. document.addEventListener('mousemove', function(e) {
  17. mouseX = e.clientX;
  18. mouseY = e.clientY;
  19. });
  20.  
  21. function applyMouseForce(img) {
  22. var imgRect = img.getBoundingClientRect();
  23. var imgX = imgRect.left + imgRect.width / 2;
  24. var imgY = imgRect.top + imgRect.height / 2;
  25. var distX = mouseX - imgX;
  26. var distY = mouseY - imgY;
  27. var distance = Math.sqrt(distX * distX + distY * distY);
  28. var maxDistance = 100; // Max distance for interaction
  29.  
  30. if (distance < maxDistance) {
  31. var forceX = (maxDistance - distance) * (distX / distance);
  32. var forceY = (maxDistance - distance) * (distY / distance);
  33.  
  34. img.style.left = img.offsetLeft - forceX + 'px';
  35. img.style.bottom = parseInt(img.style.bottom, 10) - forceY + 'px';
  36. }
  37. }
  38.  
  39. function createFloatingImage(src) {
  40. var img = document.createElement('img');
  41. img.src = src;
  42.  
  43. var size = Math.random() * (120 - 50) + 50; // Size between 50px and 120px
  44. img.style.width = size + 'px';
  45. img.style.height = 'auto';
  46.  
  47. img.style.position = 'fixed';
  48. img.style.bottom = '-150px';
  49. img.style.left = Math.random() * window.innerWidth + 'px';
  50. img.style.zIndex = 9999;
  51. img.style.pointerEvents = 'none';
  52. var bottomPosition = -150;
  53. var leftPosition = parseInt(img.style.left, 10);
  54. var sway = 50;
  55. var swayDirection = 1;
  56.  
  57. var interval = setInterval(function() {
  58. bottomPosition += 2;
  59. img.style.bottom = bottomPosition + 'px';
  60.  
  61. if (leftPosition > window.innerWidth - size || leftPosition < 0) {
  62. swayDirection *= -1;
  63. }
  64. leftPosition += 0.5 * swayDirection;
  65. img.style.left = leftPosition + 'px';
  66.  
  67. if (bottomPosition > window.innerHeight + 150) {
  68. clearInterval(interval);
  69. img.remove();
  70. }
  71. applyMouseForce(img);
  72.  
  73. }, 50);
  74.  
  75. document.body.appendChild(img);
  76. }
  77.  
  78. var imageUrl = 'https://i.imgur.com/jXsXO6T.png';
  79.  
  80. // Create 25 floating images at random intervals
  81. for (var i = 0; i < 50; i++) {
  82. // Random delay between 0 to 10 seconds
  83. var delay = Math.random() * 10000;
  84. setTimeout(function() {
  85. createFloatingImage(imageUrl);
  86. }, delay);
  87. }
  88. })();