RandomList dtf.ru

07.06.2024, 16:15:47

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==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);