The Ultimate Jstris Script alter-ver. 2

Multiple script code in one script

  1. // ==UserScript==
  2. // @name The Ultimate Jstris Script alter-ver. 2
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.40
  5. // @description Multiple script code in one script
  6. // @author julf, MattMayuga, Oki, Eddie
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. window.addEventListener('load', function(){
  17. /**************************
  18. APM & Attack in Replays Script
  19. **************************/
  20.  
  21. var website = "jstris.jezevec10.com"
  22. var url = window.location.href
  23. var parts = url.split("/")
  24.  
  25. Replayer["addStat"] = function(id,into) {
  26. var apmStat = document.createElement("tr");
  27. apmStat.innerHTML = '<td class="ter">APM</td><td class="sval"><span id="'+id+'">0</span></td>'
  28. into.appendChild(apmStat);
  29. }
  30.  
  31. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  32.  
  33. if(parts[3]=="replay" && parts[2].endsWith(website) && parts.length>4){
  34.  
  35. if(parts[4]=="1v1"){
  36. document.getElementsByClassName("ter")[1].innerHTML = "Attack"
  37. document.getElementsByClassName("ter")[6].innerHTML = "Attack"
  38. Replayer["addStat"]("apmElement1",document.getElementsByTagName("tbody")[0])
  39. Replayer["addStat"]("apmElement2",document.getElementsByTagName("tbody")[2])
  40.  
  41. } else {
  42. document.getElementsByClassName("ter")[2].innerHTML = "Attack"
  43. Replayer["addStat"]("apmElementP",document.getElementsByClassName("moreStats")[0])
  44. }
  45.  
  46. Replayer['prototype']['getAPM'] = function() {
  47. return ((this['gamedata']['linesSent'] / (this['clock'] / 6000))*10).toFixed(2)
  48. };
  49.  
  50. var oldTextBar = View.prototype.updateTextBar.toString();
  51. oldTextBar = trim(oldTextBar) + ';var cat = this.kppElement.id.slice(-1);eval("apmElement"+cat+"&&(apmElement"+cat+".innerHTML = this.g.getAPM())");'
  52. oldTextBar = oldTextBar.replace("this.sentElement.innerHTML=this.g.gamedata.lines,","")
  53. if(Replayer.prototype.checkLineClears.toString().indexOf("distr")<0){
  54. oldTextBar+="this.sentElement.innerHTML=this.g.gamedata.linesSent"
  55. }
  56. View.prototype.updateTextBar = new Function(oldTextBar);
  57.  
  58. }
  59.  
  60. //Jstris Custom Background Image
  61. document.head.getElementsByTagName("style")[0].innerHTML="";
  62. document.body.style.backgroundImage="url('https://i.imgur.com/48UEiDT.png')";
  63. document.body.style.backgroundSize="100%";
  64. document.getElementById("app").style.backgroundColor="rgba(0, 0, 0, 0.7)";
  65. document.getElementById("app").style.height="1000px";
  66.  
  67. loadSkin("https://i.imgur.com/ofXpOFG.png",36);
  68. //Jstris Block Skin Change
  69. loadGhostSkin("https://i.imgur.com/R76ixGK.png",36);
  70.  
  71. //Jstris SFX
  72. CustomSFXset.prototype = new BaseSFXset;
  73. loadSFX(new CustomSFXset);
  74.  
  75. });
  76. })();
  77.  
  78. function CustomSFXset(){
  79. this.volume=1;
  80. this.lock={url:"https://julf0.github.io/jstris-sfx/US_lock.mp3",abs:1};
  81. this.ready={url:"https://julf0.github.io/jstris-sfx/US_ready.mp3",abs:1,set:1};
  82. this.go={url:"https://julf0.github.io/jstris-sfx/US_go.mp3",abs:1,set:0};
  83. this.died={url:"https://julf0.github.io/jstris-sfx/US_died.mp3",abs:1,set:1};
  84. this.hold={url:"https://julf0.github.io/jstris-sfx/US_hold.mp3",abs:1,set:0};
  85. this.move={url:"https://julf0.github.io/jstris-sfx/US_move.mp3",abs:1,set:0};
  86. this.linefall={url:"blank.wav",abs:1,set:0};
  87. this.comboTones={url:"https://julf0.github.io/jstris-sfx/US_combo.mp3",abs:1,set:2,duration:4500,spacing:500,cnt:8};
  88. };
  89.  
  90. /**************************
  91. Opponent's Field Grid Script
  92. **************************/
  93.  
  94. var customStyle=document.createElement("style");
  95. customStyle.innerHTML='.players .bgLayer{display:none;}';
  96. document.body.appendChild(customStyle);
  97.  
  98. /**************************
  99. Special Events Script
  100. **************************/
  101. (function() {
  102. window.addEventListener('load', function(){
  103.  
  104. Game['eventSounds'] = [
  105. "https://julf0.github.io/jstris-sfx/US_tspinsingle.mp3",
  106. "https://julf0.github.io/jstris-sfx/US_tspinmini.mp3",
  107. "blank.wav",
  108. "https://julf0.github.io/jstris-sfx/US_tspindouble.mp3",
  109. "https://julf0.github.io/jstris-sfx/US_clear2.mp3",
  110. "https://julf0.github.io/jstris-sfx/US_clear3.mp3",
  111. "https://julf0.github.io/jstris-sfx/US_tspintriple.mp3",
  112. "https://julf0.github.io/jstris-sfx/US_tetris.mp3",
  113. "blank.wav",
  114. "blank.wav",
  115. "https://julf0.github.io/jstris-sfx/US_b2btspin.mp3",
  116. "https://julf0.github.io/jstris-sfx/US_b2btetris.mp3"
  117. ];
  118.  
  119. Game['eventVolumes'] = [1,1,1,1,1,1,1,1,1,1,1,1]
  120.  
  121.  
  122. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","CLEAR5","PERFECT_CLEAR"]
  123. window.enableB2B = true;
  124.  
  125.  
  126. Game["latestEv"]="";Game["sArray"]=[];localStorage.evVol=localStorage.evVol||"100";window.b2bBefore=false;
  127. 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)}})
  128.  
  129.  
  130. var evVol = document.createElement("tr");
  131. 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>`
  132. tab_sound.appendChild(evVol);
  133.  
  134. if(typeof playSound != 'function') {
  135. 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())}
  136. }
  137.  
  138.  
  139. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","CLEAR5","PERFECT_CLEAR"]
  140.  
  141. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  142. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  143.  
  144.  
  145. var clcFunc = Game['prototype']['checkLineClears'].toString()
  146. var clcParams = getParams(clcFunc)
  147. searchFor = "[_" + clcFunc.split("switch")[1].split("]][_")[2]
  148.  
  149. events.map((x,i)=>{
  150. replacement = searchFor.replace("[","[Game['btb']=this['isBack2Back'],console.log('"+x+"'),Game['latestEv']='"+x+"',")
  151. clcFunc=clcFunc.replace(searchFor,replacement)
  152. })
  153.  
  154. Game['prototype']["checkLineClears"] = new Function(...clcParams, trim(clcFunc));
  155.  
  156. var psFunc = Game['prototype']['playSound'].toString()
  157. var psParams = getParams(psFunc);
  158. psFunc = `
  159. if(Game["latestEv"]){
  160. sIndex=events.indexOf(Game["latestEv"]);
  161. console.log(sIndex)
  162. sound=sIndex;enableB2B&&Game.btb&&~[0,1,3,5,7,8].indexOf(sIndex)&&(sound=10+ +(7==sIndex));
  163. console.log(sound);
  164. Game.sArray[sound]&&playSound(sound);
  165. Game["latestEv"]="";
  166. }` + trim(psFunc)
  167.  
  168. Game['prototype']['playSound'] = new Function(...psParams, psFunc);
  169.  
  170. localStorage.mainVol = localStorage.mainVol || "100"
  171. document.getElementById("settingsSave").addEventListener("click", function(){
  172. localStorage.mainVol=document.getElementById('vol-control').value
  173. }, false);
  174.  
  175. Settings['prototype']['volumeChange'](+localStorage.mainVol)
  176.  
  177. /**************************
  178. Rotation Sounds Script
  179. **************************/
  180.  
  181. Game['rotationSounds'] = [
  182. "https://julf0.github.io/jstris-sfx/US_rotate.mp3", //rotate left
  183. "https://julf0.github.io/jstris-sfx/US_rotate.mp3", //rotate right
  184. "https://julf0.github.io/jstris-sfx/US_rotate.mp3" //rotate 180°
  185. ];
  186.  
  187. Game['rotationVolumes'] = [1,1,1]
  188.  
  189. localStorage.evVol=localStorage.evVol||"100"
  190.  
  191. Game["rArray"]=[];
  192. 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)}})
  193.  
  194.  
  195. 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())}
  196.  
  197.  
  198. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  199. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  200.  
  201. var rotFunc = Game['prototype']['rotateCurrentBlock'].toString()
  202. var rotParams = getParams(rotFunc)
  203.  
  204. var rotInsert = 'var rotPos=[0,0,1,2]['+rotParams[0]+'+1];console.log(rotPos);Game.rArray[rotPos]&&playRotSound(rotPos);'
  205.  
  206. rotFunc = rotInsert + trim(rotFunc)
  207.  
  208. Game['prototype']['rotateCurrentBlock'] = new Function(...rotParams, rotFunc);
  209.  
  210.  
  211. /**************************
  212. Keyboard Display Script
  213. **************************/
  214.  
  215. if(typeof Game != "undefined"){
  216. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  217.  
  218. document['addEventListener']('keydown', press);
  219. document['addEventListener']('keyup', press);
  220.  
  221. function press(e) {
  222. if(~Game['set2ings'].indexOf(e.keyCode)){
  223. var corresponding = [6,8,1,2,3,5,4,0][Game['set2ings'].indexOf(e.keyCode)]
  224. document.getElementsByClassName("kbkey")[corresponding].style.backgroundColor = ["lightgoldenrodyellow",""][+(e.type=="keyup")]
  225. }
  226. }
  227.  
  228. var kbhold=document.createElement("div");
  229. kbhold.id="keyboardHolder";
  230. kbhold.style.position="absolute"
  231. kbhold.style.left = (myCanvas.getBoundingClientRect().left - 300) + "px";
  232. kbhold.style.top = (myCanvas.getBoundingClientRect().top + 100) + "px";
  233. document.body.appendChild(kbhold);
  234.  
  235. var f='<R>M{text-align:center;position: absolute;font-size:15px`{]-Q:QIspacing:0;Nred`td|th|Uwp8o_000000;]:inherit`UT_34ff34`Ujy2k_f8a102`UO_f8ff00;}</RYbo"Yps"KPJV"Ptr^Tq180~TqSD~TqHDZ[CCWZXtr^OqHL~OqCWZ[&lt;[v[&gt;X/JK>~</td^|{padding:10px 5pxIR:solidIwidth:2px`q kbkey">`;}M.tg _{]-N#^PtdV-]border[~jy2kqZ~wp8o">YPdiv id="kX</tdP/trPV class="tgU.tg-Ttc3eRstyleQcollapseP><Op39mNcolor:M#kbo KP/divJtableI;]-';var g=0;var i=0;for(i in g='IJKMNOPQRTUVXYZ[]^_`q|~')var e=f.split(g[i]),f=e.join(e.pop())
  236. keyboardHolder.innerHTML = f
  237.  
  238. var set2ings = Game['prototype']['readyGo'].toString()
  239. set2ings = "Game['set2ings']=this.Settings.controls;" + trim(set2ings)
  240. Game['prototype']['readyGo'] = new Function(set2ings);
  241.  
  242. var updateTextBarFunc = Game['prototype']['updateTextBar'].toString()
  243. updateTextBarFunc = trim(updateTextBarFunc) + ";kps.innerHTML='KPS: '+(this.getKPP()*this.placedBlocks/this.clock).toFixed(2)"
  244. Game['prototype']['updateTextBar'] = new Function(updateTextBarFunc);
  245.  
  246. }
  247.  
  248. /**************************
  249. Opponents Left Script
  250. **************************/
  251.  
  252. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  253. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  254. if(typeof Game != "undefined"){
  255.  
  256. var aliveHold=document.createElement("div");
  257. aliveHold.id="aliveHolder";
  258. aliveHold.style.position="absolute"
  259. aliveHold.style.left = (myCanvas.getBoundingClientRect().left - 200) + "px";
  260. aliveHold.style.top = (myCanvas.getBoundingClientRect().top + 400) + "px";
  261. document.body.appendChild(aliveHold);
  262.  
  263. var f='<div id="lrem"><div id="aliveNum"></div></div><div id="sprintText"><div id="stLrem" style="display: block;">opponents remaining</div></div>'
  264. aliveHolder.innerHTML = f
  265. aliveHolder.style.display='none'
  266.  
  267. var printAlive = SlotView['prototype']['printSlotPlace'].toString()
  268. var printAliveParams = getParams(printAlive);
  269. printAlive = `aliveHolder.style.display='block';aliveNum.innerHTML=parseInt(this['slot']['gs']['p']['getPlaceColor'](${printAliveParams[0]})['str'])-1;` + trim(printAlive)
  270. SlotView['prototype']['printSlotPlace'] = new Function(...printAliveParams, printAlive);
  271.  
  272. var readyGoAlive = Game['prototype']['restart'].toString()
  273. readyGoAlive = "if(this['pmode']+this['isPmode'](true)+this['isPmode'](false)==0){aliveHolder.style.display='block';aliveNum.innerHTML='all'};" + trim(readyGoAlive)
  274. Game['prototype']['restart'] = new Function(readyGoAlive);
  275.  
  276. }
  277.  
  278.  
  279. /**************************
  280. Chat Timestamp Script
  281. **************************/
  282.  
  283. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  284. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  285.  
  286. var insertChat = ';var s=document.createElement("span");s.style="color:gray";s.innerHTML = "["+new Date().toTimeString().slice(0,8)+"] ";var c=document.getElementsByClassName("chl");c[c.length-1].prepend(s);'
  287.  
  288. var sicFunc = Live['prototype']['showInChat'].toString()
  289. var paramsChat = getParams(sicFunc)
  290.  
  291. sicFunc = trim(sicFunc) + insertChat
  292.  
  293. Live['prototype']["showInChat"] = new Function(...paramsChat, sicFunc);
  294.  
  295. });
  296. })();