TB Theme

Tetris Battle theme for Jstris

  1. // ==UserScript==
  2. // @name TB Theme
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.47
  5. // @description Tetris Battle theme for Jstris
  6. // @author Oki, Eddie
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. window.addEventListener('load', function(){
  16.  
  17. //Jstris Block Skin Change
  18. loadSkin("https://i.imgur.com/faP1Rp3.png",36);
  19. loadGhostSkin("https://i.imgur.com/R76ixGK.png",36);
  20.  
  21. //Jstris Custom Background Image
  22. document.head.getElementsByTagName("style")[0].innerHTML="";
  23. document.body.style.backgroundImage="url('https://i.imgur.com/wXJMZxq.png')";
  24. document.body.style.backgroundSize="100% 100%";
  25. document.getElementById("app").style.backgroundColor="rgba(0, 0, 0, 0)";
  26. document.getElementById("app").style.height="1000px";
  27.  
  28.  
  29. //Jstris SFX
  30. CustomSFXset.prototype = new BaseSFXset;
  31. loadSFX(new CustomSFXset);
  32.  
  33. });
  34. })();
  35.  
  36. function CustomSFXset(){
  37. this.volume=1;
  38. this.lock={url:"https://ecdldaiiere.github.io/Eddiez-Soundz/TB_lock.wav",abs:1};
  39. this.ready={url:"https://ecdldaiiere.github.io/Eddiez-Soundz/TB_ready.wav",abs:1,set:1};
  40. this.go={url:"https://ecdldaiiere.github.io/Eddiez-Soundz/TB_go.wav",abs:1,set:0};
  41. this.died={url:"https://ecdldaiiere.github.io/Eddiez-Soundz/TB_died.wav",abs:1,set:1};
  42. this.hold={url:"https://ecdldaiiere.github.io/Eddiez-Soundz/TB_hold.wav",abs:1,set:0};
  43. this.move={url:"https://ecdldaiiere.github.io/Eddiez-Soundz/TB_move.wav",abs:1,set:0};
  44. this.comboTones={url:"https://ecdldaiiere.github.io/Eddiez-Soundz/TBcombo.mp3",abs:1,set:2,duration:1000,spacing:500,cnt:20};
  45. this.linefall={url:"blank.wav",abs:1,set:0};
  46. };
  47.  
  48. /************************************
  49. TB Grid Script
  50. ************************************/
  51. (function() {
  52. window.addEventListener('load', function(){
  53.  
  54. customFieldBorder = true //change to false to disable
  55.  
  56. if(customFieldBorder){
  57. if(typeof Game != "undefined"){
  58.  
  59.  
  60.  
  61. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  62. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  63.  
  64. function atGameStart() {
  65. bgLayer.width = 550
  66. bgLayer.height = 650
  67. bgLayer.style.left = "-"+((880-248)/2)/2+"px"
  68. bgLayer.style.top = "-"+((1080-480)/2)/2+"px"
  69. this.drawBgGrid(1);
  70. var bgctx = bgLayer.getContext("2d");
  71. var img = new Image;
  72. img.onload = function(){
  73. bgctx.clearRect(0, 0, 880, 1080);
  74. bgctx.drawImage(img,47,107,479,560); // Or at whatever offset you like
  75. };
  76. img.src = "https://i.imgur.com/YoLNvEW.png";
  77. sprintInfo.style.zIndex = "100000";
  78. }
  79.  
  80. var initRandom = GameCore['prototype']['initRandomizer'].toString()
  81. var initRandomParams = getParams(initRandom)
  82. initRandom = trim(atGameStart.toString()) + trim(initRandom)
  83. GameCore['prototype']['initRandomizer'] = new Function(...initRandomParams, initRandom);
  84.  
  85.  
  86.  
  87. var queueC = queueCanvas.getBoundingClientRect();
  88.  
  89. for (var i = 0; i < 5; i++) {
  90. var qCC = document.createElement("canvas");
  91. qCC.id = "queueCopy" + i
  92. qCC.className = "queueCopy"
  93. qCC.style.position = "absolute";
  94. qCC.style.left = queueC.left+"px";
  95. qCC.style.top = queueC.top+(72*i)+"px";
  96. qCC.height=72
  97. i&&(qCC.style.transform = "translatey("+(72*i)+") ")
  98. qCC.width=queueCanvas.width
  99. document.body.appendChild(qCC)
  100.  
  101. }
  102.  
  103. var customStyleQueue=document.createElement("style");
  104. customStyleQueue.innerHTML='#queueCanvas {visibility:hidden;} .queueCopy {z-index:1} #holdCanvas {z-index:2}';
  105. document.body.appendChild(customStyleQueue);
  106.  
  107.  
  108. var updateQueueBoxFunc = Game['prototype']['updateQueueBox'].toString()
  109.  
  110. var inject = `;for (var i = 0; i < 5; i++) {
  111. var destCanvas = document.getElementById("queueCopy"+i)
  112. var destCtx = destCanvas.getContext('2d');
  113. destCtx.clearRect(0, 0, destCanvas.width, destCanvas.height);
  114. destCtx.drawImage(queueCanvas, 0, -i*72);}`
  115.  
  116. updateQueueBoxFunc = trim(updateQueueBoxFunc) + inject
  117.  
  118. Game['prototype']["updateQueueBox"] = new Function(updateQueueBoxFunc);
  119.  
  120. queueCopies = [queueCopy0,queueCopy1,queueCopy2,queueCopy3,queueCopy4]
  121.  
  122. //i=0
  123. //queueCopies.map(x=>{
  124. // x.style.transform = "scale(0.6,0.6) translate(13px,"+ (100+(-i*20)) +"px)"
  125. // i++
  126. //})
  127.  
  128. queueCopy0.style.transform = "scale(0.6,0.6) translate(13px, 30px)"
  129. queueCopy1.style.transform = "scale(0.6,0.6) translate(13px, 60px)"
  130. queueCopy2.style.transform = "scale(0.6,0.6) translate(13px, 70px)"
  131. queueCopy3.style.transform = "scale(0.6,0.6) translate(13px, 70px)"
  132. queueCopy4.style.transform = "scale(0.6,0.6) translate(13px, 60px)"
  133.  
  134.  
  135. holdCanvas.style.float = "none"
  136. holdCanvas.style.position = "absolute"
  137. holdCanvas.style.transform = "scale(0.6,0.6)"
  138. holdCanvas.style.top = "18px"
  139. holdCanvas.style.left = "11px"
  140.  
  141.  
  142. rInfoBox.style.position = "absolute"
  143. rInfoBox.style.zIndex = 100
  144. rInfoBox.style.marginLeft = "132px"
  145. rInfoBox.style.marginTop = "40px"
  146. rInfoBox.style.transform = "scale(0.8,0.8)"
  147.  
  148. stage.style.left = "112px"}
  149.  
  150. }
  151.  
  152.  
  153. });
  154. })();
  155.  
  156. /**************************
  157. Special Events Script
  158. **************************/
  159. (function() {
  160. window.addEventListener('load', function(){
  161.  
  162. Game['eventSounds'] = [
  163. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_tspinsingle.wav",
  164. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_tspinmini.wav",
  165. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_clear1.wav",
  166. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_tspindouble.wav",
  167. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_clear2.wav",
  168. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_clear3.wav",
  169. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_tspintriple.wav",
  170. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_clear4.wav",
  171. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_perfectclear.wav", //no sound exists for TB
  172. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_tspindouble.wav",
  173. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_clear4.wav"
  174. ];
  175.  
  176. Game['eventVolumes'] = [1,1,1,1,1,1,1,1,1,1,1]
  177.  
  178.  
  179. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","PERFECT_CLEAR"]
  180. window.enableB2B = true;
  181.  
  182.  
  183. Game["latestEv"]="";Game["sArray"]=[];localStorage.evVol=localStorage.evVol||"100";window.b2bBefore=false;
  184. 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)}})
  185.  
  186.  
  187. var evVol = document.createElement("tr");
  188. 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>`
  189. tab_sound.appendChild(evVol);
  190.  
  191. if(typeof playSound != 'function') {
  192. 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())}
  193. }
  194.  
  195.  
  196. window.events = ["TSPIN_SINGLE","TSPIN_MINI_SINGLE","CLEAR1","TSPIN_DOUBLE","CLEAR2","TSPIN_TRIPLE","CLEAR3","CLEAR4","PERFECT_CLEAR"]
  197.  
  198. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  199. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  200.  
  201.  
  202. var clcFunc = Game['prototype']['checkLineClears'].toString()
  203. var clcParams = getParams(clcFunc)
  204. searchFor = "[_" + clcFunc.split("switch")[1].split("]][_")[2]
  205.  
  206. events.map((x,i)=>{
  207. replacement = searchFor.replace("[","[Game['btb']=this['isBack2Back'],Game['latestEv']='"+x+"',")
  208. clcFunc=clcFunc.replace(searchFor,replacement)
  209. })
  210.  
  211. Game['prototype']["checkLineClears"] = new Function(...clcParams, trim(clcFunc));
  212.  
  213. var psFunc = Game['prototype']['playSound'].toString()
  214. var psParams = getParams(psFunc);
  215. psFunc = 'if(Game["latestEv"]){sIndex=events.indexOf(Game["latestEv"]);sound=sIndex;enableB2B&&Game.btb&&~[0,1,3,5,7].indexOf(sIndex)&&(sound=9+ +(7==sIndex));console.log(sound);Game.sArray[sound]&&playSound(sound);Game["latestEv"]="";}' + trim(psFunc)
  216. Game['prototype']['playSound'] = new Function(...psParams, psFunc);
  217.  
  218. localStorage.mainVol = localStorage.mainVol || "100"
  219. document.getElementById("settingsSave").addEventListener("click", function(){
  220. localStorage.mainVol=document.getElementById('vol-control').value
  221. }, false);
  222.  
  223. Settings['prototype']['volumeChange'](+localStorage.mainVol)
  224.  
  225. /**************************
  226. Rotation Sounds Script
  227. **************************/
  228.  
  229. Game['rotationSounds'] = [
  230. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_rotate.mp3", //rotate left
  231. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_rotate.mp3", //rotate right
  232. "https://ecdldaiiere.github.io/Eddiez-Soundz/TB_rotate.mp3" //rotate 180°
  233. ];
  234.  
  235. Game['rotationVolumes'] = [1,1,1]
  236.  
  237. localStorage.evVol=localStorage.evVol||"100"
  238.  
  239. Game["rArray"]=[];
  240. 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)}})
  241.  
  242.  
  243. 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())}
  244.  
  245.  
  246. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  247. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  248.  
  249. var rotFunc = Game['prototype']['rotateCurrentBlock'].toString()
  250. var rotParams = getParams(rotFunc)
  251.  
  252. var rotInsert = 'var rotPos=[0,0,1,2]['+rotParams[0]+'+1];console.log(rotPos);Game.rArray[rotPos]&&playRotSound(rotPos);'
  253.  
  254. rotFunc = rotInsert + trim(rotFunc)
  255.  
  256. Game['prototype']['rotateCurrentBlock'] = new Function(...rotParams, rotFunc);
  257.  
  258. /**************************
  259. Songs Script
  260. **************************/
  261.  
  262.  
  263. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  264. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  265.  
  266.  
  267. localStorage.musicVol = localStorage.musicVol || "100";
  268. localStorage.SPvol = localStorage.SPvol || "100";
  269.  
  270. var musicVol = document.createElement("tr");
  271. musicVol.innerHTML = 'Music vol (MP):&nbsp;<input id="volControl" oninput="Game.setVol(volControl.value,1)" type="range" min="0" max="100" value="'+localStorage.musicVol+'" step="1" style="width:150px;display:inline-block;padding-top:9px">&nbsp;&nbsp;<span id="volSetting">'+localStorage.musicVol+'%</span>'
  272. tab_sound.appendChild(musicVol);
  273.  
  274. var spVol = document.createElement("tr");
  275. spVol.innerHTML = 'Music vol (SP):&nbsp;<input id="volControl2" oninput="Game.setVol(volControl2.value,0)" type="range" min="0" max="100" value="'+localStorage.SPvol+'" step="1" style="width:150px;display:inline-block;padding-top:9px">&nbsp;&nbsp;<span id="volSetting2">'+localStorage.SPvol+'%</span>'
  276. tab_sound.appendChild(spVol);
  277.  
  278.  
  279.  
  280. Game["setVol"] = function(vol,mode) {
  281. if(mode){
  282. localStorage.musicVol = vol
  283. volSetting.innerHTML=vol+'%';
  284. var musicVol=document.getElementById("volControl")
  285. Game["songs"].map(x=>{
  286. x.volume = (musicVol.value/100);
  287. })
  288. } else {
  289. localStorage.SPvol = vol
  290. volSetting2.innerHTML=vol+'%';
  291. var spVol=document.getElementById("volControl2")
  292. Game["song"].volume = spVol.value/100
  293. }
  294. }
  295.  
  296.  
  297. if(typeof Game != "undefined"){
  298.  
  299.  
  300. var songsMP = [
  301. "https://ecdldaiiere.github.io/Eddiez-Soundz/TBsong1.mp3",
  302. ]
  303.  
  304. var songSP = "https://ecdldaiiere.github.io/Eddiez-Soundz/TBsong1.mp3"
  305.  
  306. var songThresholds = [1]
  307.  
  308. Game['onlySprint'] = false;
  309.  
  310.  
  311. window.playSong = function(s) {
  312. Game["songs"].map(x=>{
  313. x.pause();
  314. x.currentTime = 0;
  315. })
  316. Game["song"].pause();
  317. Game["song"].currentTime = 0;
  318.  
  319. if(s != undefined){
  320. !s.paused&&0<s.currentTime?s.currentTime=0:s.play()
  321. }
  322. }
  323.  
  324. Game["songs"] = [];
  325. Game["maxPlayers"] = 0
  326. Game["songIndex"] = -1
  327.  
  328.  
  329. Game["song"] = document.createElement("audio");
  330. Game["song"].src = songSP;
  331. Game["song"].loop = true;
  332. Game["song"].volume = 1;
  333.  
  334. songsMP.map((x,i)=>{
  335. Game["songs"].push(document.createElement("audio"));
  336. Game["songs"][i].src = x;
  337. Game["songs"][i].loop = true;
  338. Game["songs"][i].volume = 1;
  339. })
  340.  
  341. Game["setVol"](localStorage.musicVol,1)
  342. Game["setVol"](localStorage.SPvol,0)
  343.  
  344.  
  345. Game["updateSong"] = function(i) {
  346.  
  347. if(i<0){
  348. Game["maxPlayers"] = 0
  349. playSong()
  350. Game["songIndex"] = -1
  351. }
  352.  
  353. if(i==0){
  354. Game["maxPlayers"]= -1
  355. playSong(Game["songs"][0])
  356. Game["songIndex"] = 0
  357. }
  358.  
  359. if(typeof i == "string"){
  360. if(Game["maxPlayers"]<0){
  361. Game["maxPlayers"]=parseInt(i)
  362. }
  363. var alivePercent = (parseInt(i)-1)/Game["maxPlayers"]
  364. if(alivePercent <= songThresholds[Game["songIndex"]+1]){
  365. console.log(Game["songIndex"])
  366. Game["songIndex"]++
  367. playSong(Game["songs"][Game["songIndex"]])
  368. }
  369. }
  370.  
  371. }
  372.  
  373. var gameOver99 = Game['prototype']['GameOver'].toString();
  374. gameOver99 = "Game['updateSong'](-1);Game['song'].pause();Game['song'].currentTime=0;" + trim(gameOver99)
  375. Game['prototype']['GameOver'] = new Function(gameOver99)
  376.  
  377. var printSlot99 = SlotView['prototype']['printSlotPlace'].toString()
  378. var printSlotParams = getParams(printSlot99);
  379. printSlot99 = `Game["updateSong"](this['slot']['gs']['p']['getPlaceColor'](${printSlotParams[0]})['str']);` + trim(printSlot99)
  380. SlotView['prototype']['printSlotPlace'] = new Function(...printSlotParams, printSlot99);
  381.  
  382.  
  383.  
  384. var readyGo99 = Game['prototype']['restart'].toString()
  385. readyGo99 = "if(this['pmode']+this['isPmode'](true)+this['isPmode'](false)==0){Game['updateSong'](0)}else{Game['updateSong'](-1);if(!Game['onlySprint']){playSong(Game['song'])}else{if(this['pmode']==1){playSong(Game['song'])}}};" + trim(readyGo99)
  386. Game['prototype']['restart'] = new Function(readyGo99);
  387.  
  388. var specMode99 = Live['prototype']['spectatorMode'].toString()
  389. var specParams = getParams(specMode99);
  390. specMode99 = `Game['updateSong'](-1);` + trim(specMode99)
  391. Live['prototype']['spectatorMode'] = new Function(...specParams, specMode99);
  392.  
  393. var paint99 = Game['prototype']['paintMatrixWithColor'].toString()
  394. var paintParams = getParams(paint99);
  395. paint99 = `Game['updateSong'](-1);` + trim(paint99)
  396. Game['prototype']['paintMatrixWithColor'] = new Function(...paintParams, paint99);
  397.  
  398. localStorage.mainVol = localStorage.mainVol || "100"
  399. document.getElementById("settingsSave").addEventListener("click", function(){localStorage.mainVol=document.getElementById('vol-control').value}, false);
  400. Settings['prototype']['volumeChange'](+localStorage.mainVol)
  401.  
  402.  
  403. //remove these 3 lines if you dont want the music to stop for the countdown
  404. var readyGo992 = Game['prototype']['readyGo'].toString()
  405. readyGo992 = "Game['updateSong'](-1);" + trim(readyGo992)
  406. Game['prototype']['readyGo'] = new Function(readyGo992);
  407. }
  408.  
  409. });
  410. })();