The Ultimate Jstris Script alter-ver. 2

Multiple script code in one script

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

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