Jstris Stats Script

change the color of stats

目前為 2020-04-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Jstris Stats Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description change the color of stats
  6. // @author jezevec10
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /**************************
  12. Jstris Stats Script
  13. **************************/
  14.  
  15. (function() {
  16. window.addEventListener('load', function(){
  17.  
  18. //default color is #808080 for both
  19. colorhex_numbers = "#FFB600"
  20. colorhex_text = "#B6FFAA"
  21.  
  22. function hexToRgb(hex) {
  23. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  24. return result ? [parseInt(result[1], 16),parseInt(result[2], 16),parseInt(result[3], 16)] : null
  25. }
  26.  
  27. //canvas2d
  28. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  29. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  30.  
  31. var fastFont = FastFont2D['prototype']['draw'].toString()
  32. var params = getParams(fastFont)
  33. fastFont = trim(fastFont).split("=")
  34. fastFont[2] = fastFont[2].split(";")
  35. fastFont[2][0] = "'"+colorhex_numbers+"'"
  36. fastFont[2] = fastFont[2].join(";")
  37. fastFont = fastFont.join("=")
  38.  
  39. FastFont2D['prototype']['draw'] = new Function(...params, fastFont);
  40.  
  41. rgb = hexToRgb(colorhex_numbers)
  42. oldcolor = "[128/ 255,128/ 255,128/ 255,1]"
  43. newcolor = "["+rgb[0]+"/ 255, "+rgb[1]+" / 255, "+rgb[2]+" / 255, 1]"
  44.  
  45. //webgl
  46. window.resetColor = true;
  47.  
  48. fastFont = FastFont['prototype']['draw'].toString()
  49. params = getParams(fastFont)
  50. fastFont = trim(fastFont).replace(oldcolor,newcolor)
  51. fastFont = "if(resetColor){this['glParamsSet']=false;resetColor=0};" + fastFont
  52.  
  53. FastFont['prototype']['draw'] = new Function(...params, fastFont);
  54.  
  55. //changes the color of the texts
  56. statLabels.style.color = colorhex_text
  57. });
  58. })();