RandomList dtf.ru

07.06.2024, 16:15:47

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        RandomList dtf.ru
// @namespace   dtf
// @match       https://dtf.ru/*
// @grant       none
// @version     1.0
// @author      -
// @description 07.06.2024, 16:15:47
// @license MIT
// ==/UserScript==
// Функция для генерации случайного числа в заданном диапазоне
function randomInRange(min, max) {
    return Math.random() * (max - min) + min;
}

function startRandomMovement(elements) {
    const container = document.querySelector('.context-list--grid');
    container.style.height = '232px';

    elements.forEach(element => {
        element.style.position = 'absolute';
        let x = randomInRange(0, container.clientWidth - element.offsetWidth);
        let y = randomInRange(0, container.clientHeight - element.offsetHeight);
        let speedX = randomInRange(1, 5);
        let speedY = randomInRange(1, 5);

        function moveElement() {
            x += speedX;
            y += speedY;

            if (x <= 0 || x >= container.clientWidth - element.offsetWidth) {
                speedX *= -1;
            }
            if (y <= 0 || y >= container.clientHeight - element.offsetHeight) {
                speedY *= -1;
            }

            element.style.left = x + 'px';
            element.style.top = y + 'px';
        }

        setInterval(moveElement, 11);
    });
}

function checkAndStartAnimation() {
    const reactionElements = document.querySelectorAll('.icon--reaction_add');
    if (reactionElements.length > 0) {
        reactionElements.forEach(element => {
            element.parentElement.addEventListener('click', () => {
                const gridElements = document.querySelectorAll('.context-list--grid > .context-list-option--with-art');
                if (gridElements.length > 0) {
                    startRandomMovement(gridElements);
                }
            });
        });
        clearInterval(checkInterval);
    }
}

let checkInterval = setInterval(checkAndStartAnimation, 1000);

document.addEventListener('DOMContentLoaded', checkAndStartAnimation);