Geoguessr Duels Notification

Plays a sound when you find a duel

  1. // ==UserScript==
  2. // @name Geoguessr Duels Notification
  3. // @description Plays a sound when you find a duel
  4. // @version 1.2
  5. // @author Tyow#3742
  6. // @match *://*.geoguessr.com/*
  7. // @license MIT
  8. // @namespace https://greasyfork.org/users/1011193
  9. // ==/UserScript==
  10.  
  11. const audio = document.createElement('audio');
  12.  
  13. /* ############################################################################### */
  14. /* ##### DON'T MODIFY ANYTHING ABOVE HERE UNLESS YOU KNOW WHAT YOU ARE DOING ##### */
  15. /* ############################################################################### */
  16.  
  17. audio.volume = 0.5; // Can be replaced by any number between 0 and 1
  18.  
  19. // The below can be replaced by any link that goes directly to an mp3 file, to change the sound played on join
  20. audio.src = 'https://www.dropbox.com/scl/fi/5lzk0a5gsh56l2nrqjy28/mixkit-alert-quick-chime-766.mp3?rlkey=mb2o7bde7zquyxbmxw84nx368&dl=1';
  21.  
  22. /* ############################################################################### */
  23. /* ##### DON'T MODIFY ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ##### */
  24. /* ############################################################################### */
  25.  
  26. audio.id = "duelSoundAudioPlayer";
  27. audio.preload = 'auto';
  28.  
  29.  
  30. const addAudio = () => {
  31. document.body.appendChild(audio);
  32. }
  33.  
  34. const playSound = () => {
  35. audio.play();
  36. }
  37.  
  38. /*
  39. * Sound is played when inLobby is true and the game_layout class is visible
  40. * This happens when you move from the lobby to a game
  41. * When the sound is played, it sets inLobby to false, and played to true
  42. * While the game_layout class is visible and played is true, nothing happens
  43. * When game is no longer visible, played is reset to false
  44. * Which brings the values of inLobby and played back to the original values
  45. * Allowing for the next game
  46. */
  47. let inLobby = false;
  48. let played = false
  49.  
  50. const checkStatus = () => {
  51. let lobbyRoot = document.querySelector("[class^='matchmaking-lobby_queueRoot__']");
  52. let game = document.querySelector("[class^='duels_root__']");
  53. let finished = document.querySelector("[class^='game-finished-ranked_container__']");
  54. if (played && game) {
  55. return
  56. } else if (played) {
  57. played = false;
  58. }
  59. if (lobbyRoot && !inLobby) {
  60. console.log("primed");
  61. inLobby = true;
  62. played = false;
  63. addAudio();
  64. return;
  65. } else if (game && !finished && inLobby) {
  66. console.log("playing");
  67. playSound();
  68. played = true;
  69. inLobby = false;
  70. }
  71. }
  72.  
  73. // For testing
  74.  
  75. //document.addEventListener('mousedown', () => {
  76. // addAudio();
  77. // playSound();
  78. //});
  79.  
  80. new MutationObserver(async (mutations) => {
  81. checkStatus();
  82. }).observe(document.body, { subtree: true, childList: true });