Greasy Fork

来自缓存

Greasy Fork is available in English.

Geoguessr Duels Notification

Plays a sound when you find a duel

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Geoguessr Duels Notification
// @description  Plays a sound when you find a duel
// @version      1.2
// @author       Tyow#3742
// @match        *://*.geoguessr.com/*
// @license      MIT
// @namespace    http://greasyfork.icu/users/1011193
// ==/UserScript==

const audio = document.createElement('audio');

/* ############################################################################### */
/* ##### DON'T MODIFY ANYTHING ABOVE HERE UNLESS YOU KNOW WHAT YOU ARE DOING ##### */
/* ############################################################################### */

audio.volume = 0.5; // Can be replaced by any number between 0 and 1

// The below can be replaced by any link that goes directly to an mp3 file, to change the sound played on join
audio.src = 'https://www.dropbox.com/scl/fi/5lzk0a5gsh56l2nrqjy28/mixkit-alert-quick-chime-766.mp3?rlkey=mb2o7bde7zquyxbmxw84nx368&dl=1';

/* ############################################################################### */
/* ##### DON'T MODIFY ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ##### */
/* ############################################################################### */

audio.id = "duelSoundAudioPlayer";
audio.preload = 'auto';


const addAudio = () => {
    document.body.appendChild(audio);
}

const playSound = () => {
    audio.play();
}

/*
* Sound is played when inLobby is true and the game_layout class is visible
* This happens when you move from the lobby to a game
* When the sound is played, it sets inLobby to false, and played to true
* While the game_layout class is visible and played is true, nothing happens
* When game is no longer visible, played is reset to false
* Which brings the values of inLobby and played back to the original values
* Allowing for the next game
*/
let inLobby = false;
let played = false

const checkStatus = () => {
    let lobbyRoot = document.querySelector("[class^='matchmaking-lobby_queueRoot__']");
    let game = document.querySelector("[class^='duels_root__']");
    let finished = document.querySelector("[class^='game-finished-ranked_container__']");
    if (played && game) {
        return
    } else if (played) {
        played = false;
    }
     if (lobbyRoot && !inLobby) {
         console.log("primed");
         inLobby = true;
         played = false;
         addAudio();
         return;
     } else if (game && !finished && inLobby) {
         console.log("playing");
         playSound();
         played = true;
         inLobby = false;
    }
}

// For testing

//document.addEventListener('mousedown', () => {
//    addAudio();
//    playSound();
//});

new MutationObserver(async (mutations) => {
    checkStatus();
}).observe(document.body, { subtree: true, childList: true });