Battledudes.io Menu Music Toggle

Add custom menu music to Battledudes.io with a toggle button

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Battledudes.io Menu Music Toggle
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Add custom menu music to Battledudes.io with a toggle button
// @author       trịnh HƯng
// @match        https://battledudes.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Replace 'YOUR_AUDIO_FILE_URL' with the actual URL of your audio file
    var audioFileUrl = 'https://surviv-halloween.pro/audio/ambient/menu_music_01.mp3';

    // Create an audio element
    var audioElement = document.createElement('audio');
    audioElement.src = audioFileUrl;
    audioElement.loop = true;

    // Append the audio element to the body
    document.body.appendChild(audioElement);

    // Play the audio when the script runs
    audioElement.play();

    // Function to toggle the audio on and off
    function toggleAudio() {
        if (audioElement.paused) {
            // If paused, play the audio
            audioElement.play();
        } else {
            // If playing, pause the audio
            audioElement.pause();
        }
    }

    // Create a toggle button
    var toggleButton = document.createElement('button');
    toggleButton.innerHTML = 'Toggle Music';
    toggleButton.style.position = 'fixed';
    toggleButton.style.top = '10px';
    toggleButton.style.right = '10px';
    toggleButton.style.zIndex = '9999';
    toggleButton.addEventListener('click', toggleAudio);

    // Append the button to the body
    document.body.appendChild(toggleButton);
})();