Diep.io audio beta

Please sent me game music ideas in the feedback! Plays background music with custom controls for skipping tracks, adjusting volume, and playing/pausing the music.

当前为 2023-03-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Diep.io audio beta
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Please sent me game music ideas in the feedback! Plays background music with custom controls for skipping tracks, adjusting volume, and playing/pausing the music.
  6. // @author -{Abyss⌬}-ora
  7. // @match https://diep.io
  8. // @license GNU GPLv3
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const audioPlayer = document.createElement("audio");
  15. audioPlayer.id = "audioPlayer";
  16. audioPlayer.controls = false;
  17. audioPlayer.loop = true;
  18. audioPlayer.autoplay = true;
  19. audioPlayer.volume = 0.05;
  20.  
  21. const sources = [
  22. "https://github.com/Abyss-ora/dpaudio/raw/main/8-bit-arcade-138828.mp3",
  23. "https://github.com/Abyss-ora/dpaudio/raw/main/kim-lightyear-angel-eyes-chiptune-edit-110226.mp3",
  24. "https://github.com/Abyss-ora/dpaudio/raw/main/kim-lightyear-legends-109307.mp3"
  25. ];
  26.  
  27. let currentTrack = 0;
  28.  
  29. audioPlayer.src = sources[currentTrack];
  30. document.body.appendChild(audioPlayer);
  31.  
  32. const container = document.createElement("div");
  33. container.style.display = "flex";
  34. container.style.alignItems = "center";
  35. container.style.justifyContent = "center";
  36. container.style.position = "fixed";
  37. container.style.bottom = "20px";
  38. container.style.left = "20px";
  39. container.style.backgroundColor = "white";
  40. container.style.borderRadius = "10px";
  41. container.style.padding = "10px";
  42. document.body.appendChild(container);
  43.  
  44. const previousButton = document.createElement("button");
  45. previousButton.innerText = "◄";
  46. previousButton.style.fontSize = "24px";
  47. previousButton.style.marginRight = "10px";
  48. container.appendChild(previousButton);
  49.  
  50. const playButton = document.createElement("button");
  51. playButton.innerText = "▶️";
  52. playButton.style.fontSize = "24px";
  53. playButton.style.marginRight = "10px";
  54. container.appendChild(playButton);
  55.  
  56. const volumeBar = document.createElement("input");
  57. volumeBar.type = "range";
  58. volumeBar.min = "0";
  59. volumeBar.max = "1";
  60. volumeBar.step = "0.01";
  61. volumeBar.value = audioPlayer.volume;
  62. volumeBar.style.width = "100px";
  63. volumeBar.style.marginRight = "10px";
  64. container.appendChild(volumeBar);
  65.  
  66. const skipButton = document.createElement("button");
  67. skipButton.innerText = "►";
  68. skipButton.style.fontSize = "24px";
  69. skipButton.style.marginRight = "10px";
  70. container.appendChild(skipButton);
  71.  
  72. function playPause() {
  73. if (audioPlayer.paused) {
  74. audioPlayer.play();
  75. playButton.innerText = "⏸";
  76. } else {
  77. audioPlayer.pause();
  78. playButton.innerText = "▶️";
  79. }
  80. }
  81.  
  82. function previousTrack() {
  83. currentTrack = (currentTrack - 1 + sources.length) % sources.length;
  84. audioPlayer.src = sources[currentTrack];
  85. audioPlayer.play();
  86. playButton.innerText = "⏸";
  87. }
  88.  
  89. function skipTrack() {
  90. currentTrack = (currentTrack + 1) % sources.length;
  91. audioPlayer.src = sources[currentTrack];
  92. audioPlayer.play();
  93. playButton.innerText = "⏸";
  94. }
  95.  
  96. playButton.addEventListener("click", playPause);
  97. previousButton.addEventListener("click", previousTrack);
  98. skipButton.addEventListener("click", skipTrack);
  99. volumeBar.addEventListener("input", function() {
  100. audioPlayer.volume = volumeBar.value;
  101. });
  102. })();