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.35
  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. "https://julf0.github.io/US_b2btspin.mp3",
  71. "https://julf0.github.io/US_b2btetris.mp3"
  72. ];
  73.  
  74. Game['eventVolumes'] = [1,1,1,1,1,1,1,1,1,1,1,1]
  75.  
  76.  
  77. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","PERFECT_CLEAR"]
  78. window.enableB2B = true;
  79.  
  80.  
  81. Game["latestEv"]="";Game["sArray"]=[];localStorage.evVol=localStorage.evVol||"100";window.b2bBefore=false;
  82. 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)}})
  83.  
  84.  
  85. var evVol = document.createElement("tr");
  86. 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>`
  87. tab_appear.appendChild(evVol);
  88.  
  89. if(typeof playSound != 'function') {
  90. 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())}
  91. }
  92.  
  93.  
  94. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","PERFECT_CLEAR"]
  95.  
  96. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  97. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  98.  
  99.  
  100. var clcFunc = Game['prototype']['checkLineClears'].toString()
  101. var clcParams = getParams(clcFunc)
  102. searchFor = "[_" + clcFunc.split("switch")[1].split("]][_")[2]
  103.  
  104. events.map((x,i)=>{
  105. replacement = searchFor.replace("[","[Game['btb']=this['isBack2Back'],console.log('"+x+"'),Game['latestEv']='"+x+"',")
  106. clcFunc=clcFunc.replace(searchFor,replacement)
  107. })
  108.  
  109. Game['prototype']["checkLineClears"] = new Function(...clcParams, trim(clcFunc));
  110.  
  111. var psFunc = Game['prototype']['playSound'].toString()
  112. var psParams = getParams(psFunc);
  113. psFunc = `
  114. if(Game["latestEv"]){
  115. sIndex=events.indexOf(Game["latestEv"]);
  116. console.log(sIndex)
  117. sound=sIndex;enableB2B&&Game.btb&&~[0,1,3,5,7,8].indexOf(sIndex)&&(sound=10+ +(7==sIndex));
  118. console.log(sound);
  119. Game.sArray[sound]&&playSound(sound);
  120. Game["latestEv"]="";
  121. }` + trim(psFunc)
  122.  
  123. Game['prototype']['playSound'] = new Function(...psParams, psFunc);
  124.  
  125. localStorage.mainVol = localStorage.mainVol || "100"
  126. document.getElementById("settingsSave").addEventListener("click", function(){
  127. localStorage.mainVol=document.getElementById('vol-control').value
  128. }, false);
  129.  
  130. Settings['prototype']['volumeChange'](+localStorage.mainVol)
  131.  
  132. /**************************
  133. Rotation Sounds Script
  134. **************************/
  135.  
  136. Game['rotationSounds'] = [
  137. "https://julf0.github.io/US_rotate.mp3", //rotate left
  138. "https://julf0.github.io/US_rotate.mp3", //rotate right
  139. "https://julf0.github.io/US_rotate.mp3" //rotate 180°
  140. ];
  141.  
  142. Game['rotationVolumes'] = [1,1,1]
  143.  
  144. localStorage.evVol=localStorage.evVol||"100"
  145.  
  146. Game["rArray"]=[];
  147. 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)}})
  148.  
  149.  
  150. 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())}
  151.  
  152.  
  153. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  154. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  155.  
  156. var rotFunc = Game['prototype']['rotateCurrentBlock'].toString()
  157. var rotParams = getParams(rotFunc)
  158.  
  159. var rotInsert = 'var rotPos=[0,0,1,2]['+rotParams[0]+'+1];console.log(rotPos);Game.rArray[rotPos]&&playRotSound(rotPos);'
  160.  
  161. rotFunc = rotInsert + trim(rotFunc)
  162.  
  163. Game['prototype']['rotateCurrentBlock'] = new Function(...rotParams, rotFunc);
  164.  
  165.  
  166. /**************************
  167. Keyboard Display Script
  168. **************************/
  169.  
  170. if(typeof Game != "undefined"){
  171. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  172.  
  173. document['addEventListener']('keydown', press);
  174. document['addEventListener']('keyup', press);
  175.  
  176. function press(e) {
  177. if(~Game['set2ings'].indexOf(e.keyCode)){
  178. var corresponding = [6,8,1,2,3,5,4,0][Game['set2ings'].indexOf(e.keyCode)]
  179. document.getElementsByClassName("kbkey")[corresponding].style.backgroundColor = ["lightgoldenrodyellow",""][+(e.type=="keyup")]
  180. }
  181. }
  182.  
  183. var kbhold=document.createElement("div");
  184. kbhold.id="keyboardHolder";
  185. kbhold.style.position="absolute"
  186. kbhold.style.left = (myCanvas.getBoundingClientRect().left - 300) + "px";
  187. kbhold.style.top = (myCanvas.getBoundingClientRect().top + 100) + "px";
  188. document.body.appendChild(kbhold);
  189.  
  190. 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())
  191. keyboardHolder.innerHTML = f
  192.  
  193. var set2ings = Game['prototype']['readyGo'].toString()
  194. set2ings = "Game['set2ings']=this.Settings.controls;" + trim(set2ings)
  195. Game['prototype']['readyGo'] = new Function(set2ings);
  196.  
  197. var updateTextBarFunc = Game['prototype']['updateTextBar'].toString()
  198. updateTextBarFunc = trim(updateTextBarFunc) + ";kps.innerHTML='KPS: '+(this.getKPP()*this.placedBlocks/this.clock).toFixed(2)"
  199. Game['prototype']['updateTextBar'] = new Function(updateTextBarFunc);
  200.  
  201. }
  202.  
  203. /**************************
  204. Opponents Left Script
  205. **************************/
  206.  
  207. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  208. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  209. if(typeof Game != "undefined"){
  210.  
  211. var aliveHold=document.createElement("div");
  212. aliveHold.id="aliveHolder";
  213. aliveHold.style.position="absolute"
  214. aliveHold.style.left = (myCanvas.getBoundingClientRect().left - 200) + "px";
  215. aliveHold.style.top = (myCanvas.getBoundingClientRect().top + 400) + "px";
  216. document.body.appendChild(aliveHold);
  217.  
  218. var f='<div id="lrem"><div id="aliveNum"></div></div><div id="sprintText"><div id="stLrem" style="display: block;">opponents remaining</div></div>'
  219. aliveHolder.innerHTML = f
  220. aliveHolder.style.display='none'
  221.  
  222. var printAlive = SlotView['prototype']['printSlotPlace'].toString()
  223. var printAliveParams = getParams(printAlive);
  224. printAlive = `aliveHolder.style.display='block';aliveNum.innerHTML=parseInt(this['slot']['gs']['p']['getPlaceColor'](${printAliveParams[0]})['str'])-1;` + trim(printAlive)
  225. SlotView['prototype']['printSlotPlace'] = new Function(...printAliveParams, printAlive);
  226.  
  227. var readyGoAlive = Game['prototype']['restart'].toString()
  228. readyGoAlive = "if(this['pmode']+this['isPmode'](true)+this['isPmode'](false)==0){aliveHolder.style.display='block';aliveNum.innerHTML='all'};" + trim(readyGoAlive)
  229. Game['prototype']['restart'] = new Function(readyGoAlive);
  230.  
  231. }
  232.  
  233. /**************************
  234. APM & Attack in Replays Script
  235. **************************/
  236.  
  237. var website = "jstris.jezevec10.com"
  238. var url = window.location.href
  239. var parts = url.split("/")
  240.  
  241. Replayer["addStat"] = function(id,into) {
  242. var apmStat = document.createElement("tr");
  243. apmStat.innerHTML = '<td class="ter">APM</td><td class="sval"><span id="'+id+'">0</span></td>'
  244. into.appendChild(apmStat);
  245. }
  246.  
  247. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  248.  
  249. if(parts[3]=="replay" && parts[2].endsWith(website) && parts.length>4){
  250.  
  251. if(parts[4]=="1v1"){
  252. document.getElementsByClassName("ter")[1].innerHTML = "Attack"
  253. document.getElementsByClassName("ter")[6].innerHTML = "Attack"
  254. Replayer["addStat"]("apmElement1",document.getElementsByTagName("tbody")[0])
  255. Replayer["addStat"]("apmElement2",document.getElementsByTagName("tbody")[2])
  256.  
  257. } else {
  258. document.getElementsByClassName("ter")[2].innerHTML = "Attack"
  259. Replayer["addStat"]("apmElementP",document.getElementsByClassName("moreStats")[0])
  260. }
  261.  
  262. Replayer['prototype']['getAPM'] = function() {
  263. return ((this['gamedata']['linesSent'] / (this['clock'] / 6000))*10).toFixed(2)
  264. };
  265.  
  266. var oldTextBar = View.prototype.updateTextBar.toString();
  267. oldTextBar = trim(oldTextBar) + ';var cat = this.kppElement.id.slice(-1);eval("apmElement"+cat+"&&(apmElement"+cat+".innerHTML = this.g.getAPM())");'
  268. oldTextBar = oldTextBar.replace("this.sentElement.innerHTML=this.g.gamedata.lines,","")
  269. if(Replayer.prototype.checkLineClears.toString().indexOf("distr")<0){
  270. oldTextBar+="this.sentElement.innerHTML=this.g.gamedata.linesSent"
  271. }
  272. View.prototype.updateTextBar = new Function(oldTextBar);
  273.  
  274. }
  275.  
  276. /**************************
  277. Chat Timestamp Script
  278. **************************/
  279.  
  280. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  281. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  282.  
  283. 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);'
  284.  
  285. var sicFunc = Live['prototype']['showInChat'].toString()
  286. var paramsChat = getParams(sicFunc)
  287.  
  288. sicFunc = trim(sicFunc) + insertChat
  289.  
  290. Live['prototype']["showInChat"] = new Function(...paramsChat, sicFunc);
  291.  
  292. });
  293. })();