Rotation Sounds Script

plays different sounds for rotations

  1. // ==UserScript==
  2. // @name Rotation Sounds Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description plays different sounds for rotations
  6. // @author Oki
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /**************************
  12. Rotation Sounds Script
  13. **************************/
  14. (function() {
  15. window.addEventListener('load', function(){
  16.  
  17.  
  18. Game['rotationSounds'] = [
  19. "https://ecdldaiiere.github.io/Eddiez-Soundz/TF_rotate.mp3", //rotate left
  20. "https://ecdldaiiere.github.io/Eddiez-Soundz/TF_rotate.mp3", //rotate right
  21. "https://ecdldaiiere.github.io/Eddiez-Soundz/TF_rotate.mp3" //rotate 180°
  22. ];
  23.  
  24. Game['rotationVolumes'] = [1,1,1]
  25.  
  26. localStorage.evVol=localStorage.evVol||"100"
  27.  
  28. Game["rArray"]=[];
  29. Game["rotationSounds"].map((x,i)=>{if(Game['rotationSounds'][i]){Game["rArray"].push(document.createElement("audio"));Game["rArray"][i].src=x}else{Game["rArray"].push(null)}})
  30.  
  31.  
  32. window.playRotSound = function(S){s=Game.rArray[S];!s.paused&&0<s.currentTime?s.currentTime=0:(s.volume=Game['rotationVolumes'][S]*localStorage.evVol/100,s.play())}
  33.  
  34.  
  35. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  36. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  37.  
  38. var rotFunc = Game['prototype']['rotateCurrentBlock'].toString()
  39. var rotParams = getParams(rotFunc)
  40.  
  41. var rotInsert = 'var rotPos=[0,0,1,2]['+rotParams[0]+'+1];console.log(rotPos);Game.rArray[rotPos]&&playRotSound(rotPos);'
  42.  
  43. rotFunc = rotInsert + trim(rotFunc)
  44.  
  45. Game['prototype']['rotateCurrentBlock'] = new Function(...rotParams, rotFunc);
  46.  
  47. });
  48. })();