Songs Script

Plays songs in singleplayer or based on number of players

  1. // ==UserScript==
  2. // @name Songs Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Plays songs in singleplayer or based on number of players
  6. // @author Oki
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. window.addEventListener('load', function(){
  15.  
  16.  
  17. /**************************
  18. Songs Script
  19. **************************/
  20.  
  21.  
  22. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  23. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  24.  
  25.  
  26. localStorage.musicVol = localStorage.musicVol || "100";
  27. localStorage.SPvol = localStorage.SPvol || "100";
  28.  
  29. var musicVol = document.createElement("tr");
  30. musicVol.innerHTML = 'Music vol (MP):&nbsp;<input id="volControl" oninput="Game.setVol(volControl.value,1)" type="range" min="0" max="100" value="'+localStorage.musicVol+'" step="1" style="width:150px;display:inline-block;padding-top:9px">&nbsp;&nbsp;<span id="volSetting">'+localStorage.musicVol+'%</span>'
  31. tab_appear.appendChild(musicVol);
  32.  
  33. var spVol = document.createElement("tr");
  34. spVol.innerHTML = 'Music vol (SP):&nbsp;<input id="volControl2" oninput="Game.setVol(volControl2.value,0)" type="range" min="0" max="100" value="'+localStorage.SPvol+'" step="1" style="width:150px;display:inline-block;padding-top:9px">&nbsp;&nbsp;<span id="volSetting2">'+localStorage.SPvol+'%</span>'
  35. tab_appear.appendChild(spVol);
  36.  
  37.  
  38.  
  39. Game["setVol"] = function(vol,mode) {
  40. if(mode){
  41. localStorage.musicVol = vol
  42. volSetting.innerHTML=vol+'%';
  43. var musicVol=document.getElementById("volControl")
  44. Game["songs"].map(x=>{
  45. x.volume = (musicVol.value/100);
  46. })
  47. } else {
  48. localStorage.SPvol = vol
  49. volSetting2.innerHTML=vol+'%';
  50. var spVol=document.getElementById("volControl2")
  51. Game["song"].volume = spVol.value/100
  52. }
  53. }
  54.  
  55.  
  56. if(typeof Game != "undefined"){
  57.  
  58.  
  59. var songsMP = [
  60. "https://ecdldaiiere.github.io/Eddiez-Soundz/t99song1.mp3",
  61. "https://ecdldaiiere.github.io/Eddiez-Soundz/t99song2.mp3",
  62. "https://ecdldaiiere.github.io/Eddiez-Soundz/t99song3.mp3"
  63. ]
  64.  
  65. var songSP = "https://ecdldaiiere.github.io/Eddiez-Soundz/t99song1.mp3"
  66.  
  67. //Play song when only X*100% of players are left (first one is always 1)
  68. var songThresholds = [1, 0.6, 0.2]
  69.  
  70. Game['onlySprint'] = false;
  71.  
  72.  
  73. window.playSong = function(s) {
  74. Game["songs"].map(x=>{
  75. x.pause();
  76. x.currentTime = 0;
  77. })
  78. Game["song"].pause();
  79. Game["song"].currentTime = 0;
  80.  
  81. if(s != undefined){
  82. !s.paused&&0<s.currentTime?s.currentTime=0:s.play()
  83. }
  84. }
  85.  
  86. Game["songs"] = [];
  87. Game["maxPlayers"] = 0
  88. Game["songIndex"] = -1
  89.  
  90.  
  91. Game["song"] = document.createElement("audio");
  92. Game["song"].src = songSP;
  93. Game["song"].loop = true;
  94. Game["song"].volume = 1;
  95.  
  96. songsMP.map((x,i)=>{
  97. Game["songs"].push(document.createElement("audio"));
  98. Game["songs"][i].src = x;
  99. Game["songs"][i].loop = true;
  100. Game["songs"][i].volume = 1;
  101. })
  102.  
  103. Game["setVol"](localStorage.musicVol,1)
  104. Game["setVol"](localStorage.SPvol,0)
  105.  
  106.  
  107. Game["updateSong"] = function(i) {
  108.  
  109. if(i<0){
  110. Game["maxPlayers"] = 0
  111. playSong()
  112. Game["songIndex"] = -1
  113. }
  114.  
  115. if(i==0){
  116. Game["maxPlayers"]= -1
  117. playSong(Game["songs"][0])
  118. Game["songIndex"] = 0
  119. }
  120.  
  121. if(typeof i == "string"){
  122. if(Game["maxPlayers"]<0){
  123. Game["maxPlayers"]=parseInt(i)
  124. }
  125. var alivePercent = (parseInt(i)-1)/Game["maxPlayers"]
  126. if(alivePercent <= songThresholds[Game["songIndex"]+1]){
  127. console.log(Game["songIndex"])
  128. Game["songIndex"]++
  129. playSong(Game["songs"][Game["songIndex"]])
  130. }
  131. }
  132.  
  133. }
  134.  
  135. var gameOver99 = Game['prototype']['GameOver'].toString();
  136. gameOver99 = "Game['updateSong'](-1);Game['song'].pause();Game['song'].currentTime=0;" + trim(gameOver99)
  137. Game['prototype']['GameOver'] = new Function(gameOver99)
  138.  
  139. var printSlot99 = SlotView['prototype']['printSlotPlace'].toString()
  140. var printSlotParams = getParams(printSlot99);
  141. printSlot99 = `Game["updateSong"](this['slot']['gs']['p']['getPlaceColor'](${printSlotParams[0]})['str']);` + trim(printSlot99)
  142. SlotView['prototype']['printSlotPlace'] = new Function(...printSlotParams, printSlot99);
  143.  
  144.  
  145.  
  146. var readyGo99 = Game['prototype']['restart'].toString()
  147. readyGo99 = "if(this['pmode']+this['isPmode'](true)+this['isPmode'](false)==0){Game['updateSong'](0)}else{Game['updateSong'](-1);if(!Game['onlySprint']){playSong(Game['song'])}else{if(this['pmode']==1){playSong(Game['song'])}}};" + trim(readyGo99)
  148. Game['prototype']['restart'] = new Function(readyGo99);
  149.  
  150. var specMode99 = Live['prototype']['spectatorMode'].toString()
  151. var specParams = getParams(specMode99);
  152. specMode99 = `Game['updateSong'](-1);` + trim(specMode99)
  153. Live['prototype']['spectatorMode'] = new Function(...specParams, specMode99);
  154.  
  155. var paint99 = Game['prototype']['paintMatrixWithColor'].toString()
  156. var paintParams = getParams(paint99);
  157. paint99 = `Game['updateSong'](-1);` + trim(paint99)
  158. Game['prototype']['paintMatrixWithColor'] = new Function(...paintParams, paint99);
  159.  
  160. localStorage.mainVol = localStorage.mainVol || "100"
  161. document.getElementById("settingsSave").addEventListener("click", function(){
  162. localStorage.mainVol=document.getElementById('vol-control').value
  163. }, false);
  164.  
  165. Settings['prototype']['volumeChange'](+localStorage.mainVol)
  166.  
  167.  
  168. //remove these 3 lines if you dont want the music to stop for the countdown
  169. var readyGo992 = Game['prototype']['readyGo'].toString()
  170. readyGo992 = "Game['updateSong'](-1);" + trim(readyGo992)
  171. Game['prototype']['readyGo'] = new Function(readyGo992);
  172. }
  173.  
  174.  
  175. });
  176. })();