Haxball Avatar Auto Change

Automatically change avatar every second in Haxball

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Haxball Avatar Auto Change
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically change avatar every second in Haxball
// @author       Your Name
// @match        https://www.haxball.com/play
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';

    // Array of emojis to use as avatars
    const avatars = ['👊🏿', '😝', '🖕🏿', '😢', '🍆', '😍', '💩', '😎', '🤡', '🥳', '👋🏿', '🤬', '❄️', '🤣', '👶🏻', '🤫', '👄', '😴'];
    let currentIndex = 0; // Index to track the current avatar

    // Function to change the avatar
    const changeAvatar = function(key) {
        let inputHax = document.querySelector('.input input');
        let buttonHax = document.querySelector('.input button');
        inputHax.value = '/avatar ' + key;
        buttonHax.click();
        removeAvatarSet();
    };

    // Function to remove the "Avatar set" notice
    const removeAvatarSet = function() {
        let noticeList = document.querySelectorAll('div.log p.notice');
        for (let i = 0; i < noticeList.length; i++) {
            if (noticeList[i].innerText === 'Avatar set') {
                noticeList[i].parentNode.removeChild(noticeList[i]);
            }
        }
    };

    // Function to cycle through avatars
    const cycleAvatars = function() {
        changeAvatar(avatars[currentIndex]);
        currentIndex = (currentIndex + 1) % avatars.length;
    };

    // Set an interval to change the avatar every second
    setInterval(cycleAvatars, 1000);

})();