Duolingo Button Animations

Adds cool animations to buttons in Duolingo

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Duolingo Button Animations
// @namespace    http://tampermonkey.net/
// @description  Adds cool animations to buttons in Duolingo
// @author       Your Name
// @match        https://www.duolingo.com/*
// @grant        GM_addStyle
// @license      Redistribution prohibited
// @version      0.5
// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(`
        .button-animation {
            transition: transform 0.2s ease-in-out;
            border-radius: 8px;
            padding: 10px 20px;
            cursor: pointer;
            position: relative;
        }
    `);

    document.addEventListener('mousemove', function(e) {
        const buttons = document.querySelectorAll('.button-animation');
        let closestButton = null;
        let closestDistance = Infinity;

        buttons.forEach(button => {
            const rect = button.getBoundingClientRect();
            const distance = Math.sqrt((e.clientX - rect.left - rect.width / 2) ** 2 + (e.clientY - rect.top - rect.height / 2) ** 2);
            if (distance < 100 && distance < closestDistance) { // Установите радиус притяжения
                closestDistance = distance;
                closestButton = button;
            }
        });

        buttons.forEach(button => {
            if (button === closestButton) {
                const rect = button.getBoundingClientRect();
                const x = (e.clientX - rect.left - rect.width / 2) * 0.3; // Увеличьте коэффициент для сильного притяжения
                const y = (e.clientY - rect.top - rect.height / 2) * 0.3;
                button.style.transform = `translate(${x}px, ${y}px)`;
            } else {
                button.style.transform = '';
            }
        });
    });

    const observer = new MutationObserver(() => {
        const buttons = document.querySelectorAll('button');
        buttons.forEach(button => {
            if (!button.classList.contains('button-animation')) {
                button.classList.add('button-animation');
            }
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();