The Ultimate Jstris Script alter-ver. 2

Multiple script code in one script

当前为 2020-01-28 提交的版本,查看 最新版本

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