Twitch Loot Script

Automatically claim Twitch Drops, activate or deactivate button left on send message to chat.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Twitch Loot Script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automatically claim Twitch Drops, activate or deactivate button left on send message to chat.
// @author       Entyen
// @match        https://www.twitch.tv/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=twitch.tv
// @grant        none
// @license      MIT
// @namespace    https://greasyfork.org/users/1290894
// ==/UserScript==


window.addEventListener('load', function() {

    if (localStorage.btClick === undefined) {
        localStorage.btClick = false;
    }


    function twClick() {
        const twitchBtn = Array.from(document.querySelectorAll('button')).filter(element => element.className.match(/ScCoreButtonSuccess*\S+/))
        if (!JSON.parse(localStorage.btClick)) return
        if (twitchBtn.length == 0) return
        twitchBtn.forEach(element => element.click())
    }

    setInterval(twClick, 5000)


    const SettingButton = document.querySelector('button[data-a-target="chat-settings"]')

    const autoLootDiv = document.createElement('div');
    autoLootDiv.style.setProperty('display', 'inline-flex', 'important');

    const autoLootDivIns = document.createElement('div');
    autoLootDivIns.style.setProperty('position', 'relative', 'important');
    autoLootDivIns.style.top = '4px'

    const autoLootButton = document.createElement('button');
    autoLootButton.style.display = 'inline-flex';
    autoLootButton.style.alignItems = 'center';
    autoLootButton.style.justifyContent = 'center';
    autoLootButton.style.userSelect = 'none';
    autoLootButton.style.borderRadius = 'var(--border-radius-medium)';
    autoLootButton.style.height = 'var(--button-size-default)';
    autoLootButton.style.width = 'var(--button-size-default)';
    autoLootButton.style.color = 'var(--color-fill-button-icon)';
    autoLootButton.onclick = function() {
        const isActive = JSON.parse(localStorage.btClick);
        autoLootButton.style.backgroundColor = isActive ? '#ffffff' : '#ffd700';
        localStorage.btClick = JSON.stringify(!isActive);
    };

    autoLootButton.style.backgroundColor = JSON.parse(localStorage.btClick) ? '#ffd700' : '#ffffff';

    autoLootButton.innerHTML = `<svg width="20" height="20" viewBox="0 0 20 20" focusable="false" aria-hidden="true" role="presentation"><path fill-rule="evenodd" d="M4 3h12l2 4v10H2V7l2-4zm.236 4H8v1a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1V7h3.764l-1-2H5.236l-1 2zM16 9h-2.17A3.001 3.001 0 0 1 11 11H9a3.001 3.001 0 0 1-2.83-2H4v6h12V9z" clip-rule="evenodd"></path></svg>`;

    const parentElement = SettingButton.parentElement.parentElement.parentElement;
    parentElement.appendChild(autoLootDiv);
    autoLootDiv.appendChild(autoLootDivIns);
    autoLootDivIns.appendChild(autoLootButton);
});