Special Events Script

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

目前为 2019-09-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Special Events Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.91
  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. Game['eventSounds'] = [
  19. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspinsingle.mp3",
  20. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspinminisingle.mp3",
  21. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear1.wav",
  22. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspindouble.mp3",
  23. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear2.mp3",
  24. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_tspintriple.mp3",
  25. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear3.mp3",
  26. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear4.mp3",
  27. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_clear5.mp3",
  28. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_perfectclear.mp3",
  29. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_b2btspin.wav",
  30. "https://ecdldaiiere.github.io/Eddiez-Soundz/TOP_b2btetris.mp3"
  31. ];
  32.  
  33. Game['eventVolumes'] = [1,1,1,1,1,1,1,1,1,1,1]
  34.  
  35.  
  36. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","CLEAR5","PERFECT_CLEAR"]
  37. window.enableB2B = true;
  38.  
  39.  
  40. Game["latestEv"]="";Game["sArray"]=[];localStorage.evVol=localStorage.evVol||"100";window.b2bBefore=false;
  41. Game["eventSounds"].map((x,i)=>{if(Game['eventSounds'][i]){Game["sArray"].push(document.createElement("audio"));Game["sArray"][i].src=x}else{Game["sArray"].push(null)}})
  42.  
  43.  
  44. var evVol = document.createElement("tr");
  45. 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>`
  46. tab_appear.appendChild(evVol);
  47.  
  48. if(typeof playSound != 'function') {
  49. 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())}
  50. }
  51.  
  52.  
  53. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","CLEAR5","PERFECT_CLEAR"]
  54.  
  55. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  56. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  57.  
  58.  
  59. var clcFunc = Game['prototype']['checkLineClears'].toString()
  60. var clcParams = getParams(clcFunc)
  61. searchFor = clcFunc.split("switch")[1].split("=")[2]
  62. searchFor = searchFor.substr(searchFor.indexOf("_0x"),searchFor.indexOf("]]["))
  63.  
  64. events.map((x,i)=>{
  65. replacement = searchFor.replace("[","[Game['btb']=this['isBack2Back'],console.log('"+x+"'),Game['latestEv']='"+x+"',")
  66. clcFunc=clcFunc.replace(searchFor,replacement)
  67. })
  68.  
  69. Game['prototype']["checkLineClears"] = new Function(...clcParams, trim(clcFunc));
  70.  
  71. var psFunc = Game['prototype']['playSound'].toString()
  72. var psParams = getParams(psFunc);
  73. psFunc = `
  74. if(Game["latestEv"]){
  75. sIndex=events.indexOf(Game["latestEv"]);
  76. console.log(sIndex)
  77. sound=sIndex;enableB2B&&Game.btb&&~[0,1,3,5,7,8].indexOf(sIndex)&&(sound=10+ +(7==sIndex));
  78. console.log(sound);
  79. Game.sArray[sound]&&playSound(sound);
  80. Game["latestEv"]="";
  81. }` + trim(psFunc)
  82.  
  83. Game['prototype']['playSound'] = new Function(...psParams, psFunc);
  84.  
  85. localStorage.mainVol = localStorage.mainVol || "100"
  86. document.getElementById("settingsSave").addEventListener("click", function(){
  87. localStorage.mainVol=document.getElementById('vol-control').value
  88. }, false);
  89.  
  90. Settings['prototype']['volumeChange'](+localStorage.mainVol)
  91.  
  92. });
  93. })();