Battledudes.io Menu Music Toggle

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();