Special Events Script

allows sounds to be played for special events (eg. T-Spin Double)

目前为 2019-11-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Special Events Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.94
  5. // @description allows sounds to be played for special events (eg. T-Spin Double)
  6. // @author Oki
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /**************************
  12. Special Events Script
  13. **************************/
  14. (function() {
  15. window.addEventListener('load', function(){
  16.  
  17.  
  18. //set url to "" if you dont want an extra sound
  19. Game['eventSounds'] = [
  20. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspinsingle.mp3",
  21. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspinminisingle.mp3",
  22. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear1.wav",
  23. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspindouble.mp3",
  24. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear2.mp3",
  25. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspintriple.mp3",
  26. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear3.mp3",
  27. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear4.mp3",
  28. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear5.mp3",
  29. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_perfectclear.mp3",
  30. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_b2btspin.wav",
  31. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_b2btetris.mp3",
  32. //sound for incoming garbage, see bottom of script
  33. ""
  34. ];
  35.  
  36. Game['eventVolumes'] = [1,1,1,1,1,1,1,1,1,1,1,1,1]
  37.  
  38.  
  39. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","CLEAR5","PERFECT_CLEAR"]
  40. window.enableB2B = true;
  41.  
  42.  
  43. Game["latestEv"]="";Game["sArray"]=[];localStorage.evVol=localStorage.evVol||"100";window.b2bBefore=false;
  44. Game["eventSounds"].map((x,i)=>{
  45. if(Game['eventSounds'][i]){
  46. Game["sArray"].push(document.createElement("audio"));Game["sArray"][i].src=x
  47. }else {
  48. Game["sArray"].push(document.createElement("audio"));Game["sArray"][i].src="blank.wav"
  49. }
  50. })
  51.  
  52.  
  53. var evVol = document.createElement("tr");
  54. evVol.innerHTML = `Special Events vol:&nbsp;<input id="volControl3" oninput="localStorage.evVol=volControl3.value;volSetting3.innerHTML=volControl3.value+'%'" type="range" min="0" max="100" value="`+localStorage.evVol+`" step="1" style="width:150px;display:inline-block;padding-top:9px">&nbsp;&nbsp;<span id="volSetting3">`+localStorage.evVol+`%</span>`
  55. tab_appear.appendChild(evVol);
  56.  
  57. if(typeof playSound != 'function') {
  58. window.playSound = function(S){s=Game.sArray[S];console.log(s);!s.paused&&0<s.currentTime?s.currentTime=0:(s.volume=Game['eventVolumes'][S]*localStorage.evVol/100,s.play())}
  59. }
  60.  
  61.  
  62. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","CLEAR5","PERFECT_CLEAR"]
  63.  
  64. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  65. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  66.  
  67.  
  68. var clcFunc = Game['prototype']['checkLineClears'].toString()
  69. var clcParams = getParams(clcFunc)
  70. searchFor = clcFunc.split("switch")[1].split("=")[2]
  71. searchFor = searchFor.substr(searchFor.indexOf("_0x"),searchFor.indexOf("]]["))
  72.  
  73. events.map((x,i)=>{
  74. replacement = searchFor.replace("[","[Game['btb']=this['isBack2Back'],console.log('"+x+"'),Game['latestEv']='"+x+"',")
  75. clcFunc=clcFunc.replace(searchFor,replacement)
  76. })
  77.  
  78. Game['prototype']["checkLineClears"] = new Function(...clcParams, trim(clcFunc));
  79.  
  80. var psFunc = Game['prototype']['playSound'].toString()
  81. var psParams = getParams(psFunc);
  82. psFunc = `
  83. if(Game["latestEv"]){
  84. sIndex=events.indexOf(Game["latestEv"]);
  85. console.log(sIndex)
  86. sound=sIndex;enableB2B&&Game.btb&&~[0,1,3,5,7,8].indexOf(sIndex)&&(sound=10+ +(7==sIndex));
  87. console.log(sound);
  88. Game.sArray[sound]&&playSound(sound);
  89. Game["latestEv"]="";
  90. }` + trim(psFunc)
  91.  
  92. Game['prototype']['playSound'] = new Function(...psParams, psFunc);
  93.  
  94. localStorage.mainVol = localStorage.mainVol || "100"
  95. document.getElementById("settingsSave").addEventListener("click", function(){
  96. localStorage.mainVol=document.getElementById('vol-control').value
  97. }, false);
  98.  
  99. Settings['prototype']['volumeChange'](+localStorage.mainVol)
  100.  
  101.  
  102.  
  103.  
  104. //Sounds for incoming garbage
  105. var garbageFunc = Game['prototype']['addGarbage'].toString()
  106. var garbageParams = getParams(garbageFunc)
  107. garbageFunc = garbageFunc.replace("}","};console.log("+garbageParams+");playSound(12);");
  108. Game['prototype']["addGarbage"] = new Function(...garbageParams, trim(garbageFunc));
  109.  
  110.  
  111.  
  112. });
  113. })();