Minimal Tetris Friends

Reduces lag as much as possible by removing everything from the page except for the games themselves.

  1. // ==UserScript==
  2. // @name Minimal Tetris Friends
  3. // @namespace minimaltetrisfriends
  4. // @description Reduces lag as much as possible by removing everything from the page except for the games themselves.
  5. // @include http://*tetrisfriends.com/games/Ultra/game.php*
  6. // @include http://*tetrisfriends.com/games/Sprint/game.php*
  7. // @include http://*tetrisfriends.com/games/Live/game.php*
  8. // @grant none
  9. // @run-at document-start
  10. // @version 2016-03-06,4.0.1
  11. // @author knux
  12. // ==/UserScript==
  13.  
  14. var contentFlashSize = new Object();
  15.  
  16. function resizeContentFlash()
  17. {
  18. windowSizeRatio = innerHeight / innerWidth;
  19. contentFlashSizeRatio = contentFlashSize.originalHeight / contentFlashSize.originalWidth;
  20. if( contentFlashSizeRatio > windowSizeRatio )
  21. {
  22. updatedHeight = innerHeight;
  23. updatedWidth = Math.round( innerHeight / contentFlashSizeRatio );
  24. }
  25. else
  26. {
  27. updatedHeight = Math.round( innerWidth * contentFlashSizeRatio );
  28. updatedWidth = innerWidth;
  29. }
  30.  
  31. $(contentFlash).css("height", updatedHeight + "px");
  32. $(contentFlash).css("width", updatedWidth + "px");
  33. $(contentFlash).css("margin-top", -updatedHeight / 2 + "px");
  34. $(contentFlash).css("margin-left", -updatedWidth / 2 + "px");
  35. }
  36.  
  37. addEventListener("DOMContentLoaded",
  38. function()
  39. {
  40. contentFlashSize.originalWidth = contentFlash.width;
  41. contentFlashSize.originalHeight = contentFlash.height;
  42. resizeContentFlash();
  43.  
  44. var headStr = '<style> body { background: url(//tetrisow-a.akamaihd.net/data5_0_0_1/images/bg.jpg) repeat-x; font-family: "Trebuchet MS",Helvetica,Tahoma,Geneva,Verdana,Arial,sans-serif; font-size: 12px; color: #666; margin: 0; text-align: center; display: block; overflow: hidden} #contentFlash { visibility: visible !important; position: absolute; top: 50%; left: 50%; } * { margin: 0; padding: 0; outline: none; -moz-box-sizing: border-box; box-sizing: border-box; }</style>';
  45. var bodyStr = $(contentFlash).clone().removeAttr("height").removeAttr("width").append("<param name=quality value=low></object>").find("param[name=wmode]").attr("value", "direct").parent()[0].outerHTML;
  46. document.documentElement.innerHTML =
  47. '<head>' + headStr + '</head>' +
  48. '<body>' + bodyStr + '</body>';
  49. var startScript = 'gamePrerollComplete();if(contentFlash.outerHTML.indexOf("object") == -1){renderFlash()};';
  50. if( location.href.indexOf("/Live/game.php") != -1 )
  51. startScript += ';var sArenaTimes = 5; function startArena(){if(contentFlash.TotalFrames){try{contentFlash.as3_prerollDone()}catch(err){}}else{setTimeout(startArena, 1000); return}; sArenaTimes--; setTimeout(startArena, 1000)}; startArena()';
  52.  
  53. document.body.appendChild( document.createElement("script") ).innerHTML = startScript;
  54. }
  55. )
  56.  
  57. addEventListener("resize", resizeContentFlash);