Duolingo Button Animations

Adds cool animations to buttons in Duolingo

目前为 2024-11-28 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Duolingo Button Animations
  3. // @namespace http://tampermonkey.net/
  4. // @description Adds cool animations to buttons in Duolingo
  5. // @author Your Name
  6. // @match https://www.duolingo.com/*
  7. // @grant GM_addStyle
  8. // @license Redistribution prohibited
  9. // @version 0.5
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. GM_addStyle(`
  16. .button-animation {
  17. transition: transform 0.2s ease-in-out;
  18. border-radius: 8px;
  19. padding: 10px 20px;
  20. cursor: pointer;
  21. position: relative;
  22. }
  23. `);
  24.  
  25. document.addEventListener('mousemove', function(e) {
  26. const buttons = document.querySelectorAll('.button-animation');
  27. let closestButton = null;
  28. let closestDistance = Infinity;
  29.  
  30. buttons.forEach(button => {
  31. const rect = button.getBoundingClientRect();
  32. const distance = Math.sqrt((e.clientX - rect.left - rect.width / 2) ** 2 + (e.clientY - rect.top - rect.height / 2) ** 2);
  33. if (distance < 100 && distance < closestDistance) { // Установите радиус притяжения
  34. closestDistance = distance;
  35. closestButton = button;
  36. }
  37. });
  38.  
  39. buttons.forEach(button => {
  40. if (button === closestButton) {
  41. const rect = button.getBoundingClientRect();
  42. const x = (e.clientX - rect.left - rect.width / 2) * 0.3; // Увеличьте коэффициент для сильного притяжения
  43. const y = (e.clientY - rect.top - rect.height / 2) * 0.3;
  44. button.style.transform = `translate(${x}px, ${y}px)`;
  45. } else {
  46. button.style.transform = '';
  47. }
  48. });
  49. });
  50.  
  51. const observer = new MutationObserver(() => {
  52. const buttons = document.querySelectorAll('button');
  53. buttons.forEach(button => {
  54. if (!button.classList.contains('button-animation')) {
  55. button.classList.add('button-animation');
  56. }
  57. });
  58. });
  59.  
  60. observer.observe(document.body, { childList: true, subtree: true });
  61. })();

QingJ © 2025

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