Tetris Friends Tweaks

Some tweaks on TetrisFriends.com.

  1. // ==UserScript==
  2. // @name Tetris Friends Tweaks
  3. // @description Some tweaks on TetrisFriends.com.
  4. // @grant unsafeWindow
  5. // @include http://www.tetrisfriends.com/*
  6. // @version 0.0.1.20150409093204
  7. // @namespace https://greasyfork.org/users/2233
  8. // ==/UserScript==
  9.  
  10. /*** Settings ***/
  11. if(typeof remove_ads == 'undefined') { var remove_ads = false }
  12. /*** End of Settings ***/
  13.  
  14. var wnd = window
  15. var doc = wnd.document
  16. var loc = location
  17. var href = loc.href
  18.  
  19. if(/^http:\/\/www\.tetrisfriends\.com\//.test(href))
  20. {
  21. if(typeof unsafeWindow != 'undefined') { wnd = unsafeWindow }
  22. if(/\/leaderboard\/index\.php$/.test(href))
  23. {
  24. var goto_sprint_leaderboard = function() { loc.href = 'javascript:window.leaderboardChange("3", "84", 2, "0", 0, "Sprint")' }
  25. if(doc.readyState == 'complete') { goto_sprint_leaderboard() } else { addEventListener('load', goto_sprint_leaderboard, false) }
  26. throw 'exit'
  27. }
  28. if(remove_ads) {
  29. if(!/\/game\.php\b/.test(href)) { throw 'exit' }
  30. wnd.stop()
  31. if(/Live\/game\.php$/.test(href)) { wnd.stop(); loc.href = href + '?das=117&ar=17&ihs=true&irs=true'; throw 'exit' }
  32. var tweak_flash = function() {
  33. loc.href = 'javascript:gamePrerollComplete()'
  34. var game_swf = ''
  35. if(/Sprint\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Sprint/OWGameSprint.swf?version=3' }
  36. else if(/Live\b/.test(href)) { game_swf = 'http://www.tetrisfriends.com/data/games/Live/OWGameTetrisLive.swf?livebust=0165?version=0' }
  37. else if(/Ultra\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Ultra/OWGameUltra.swf?version=3' }
  38. else if(/Marathon\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Marathon/OWGameMarathon.swf?version=3' }
  39. else if(/Mono\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Mono/OWGameColorBlind.swf?version=3' }
  40. else if(/Survival\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Survival/OWGameSurvival.swf?version=3' }
  41. else if(/NBlox\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/NBlox/nbloxWebsite.swf?version=3' } // doesn't work
  42. else if(/Battle2P\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Battle2P/OWGameBattle2pMaps.swf?version=0' }
  43. else if(/Battle6P\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Battle6P/OWGameBattle6P.swf?version=0' }
  44. else if(/Rally8P\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Rally8P/OWRally8P.swf?version=0' }
  45. else if(/Sprint5P\b/.test(href)) { game_swf = 'http://tetrisow-a.akamaihd.net/data4_0_0_1/games/Sprint5P/OWGameSprint5p.swf?version=0' }
  46. else { game_swf = doc.getElementsByTagName('OBJECT')[0].data }
  47. if(game_swf == '') { return }
  48.  
  49. var w = '643', h = '381'
  50. //if(/Live\b/.test(href)) { w = '800', h = '600' }
  51. var margin_top = (wnd.innerHeight-h)/2 + 'px'
  52. doc.head.innerHTML = '' // remove unwanted style sheets. another way: for(var i=doc.styleSheets.length-1; i>=0; i--) { doc.styleSheets[i].disabled=true; }
  53. doc.body.innerHTML = '<object type="application/x-shockwave-flash" allowscriptaccess="always" data="' + game_swf + '" width="' + w + '" height="' + h + '" id="contentFlash" style="visibility: visible; display: block; margin-left: auto; margin-right: auto; margin-top:' + margin_top + '">' + '<param name="wmode" value="window">' + doc.getElementsByName("flashvars")[0].outerHTML + '<param name="quality" value="low">' + '</object>'
  54.  
  55. // only needed when the <OBJECT> id is 'contentFlash'?
  56. for(var i=0; i<10; i++) { setTimeout('contentFlash.style.visibility = "visible"; contentFlash.as3_prerollDone()', i*1000) }
  57.  
  58. // buggy
  59. var flash_obj = doc.getElementById('contentFlash')
  60. if(flash_obj)
  61. {
  62. flash_obj.addEventListener('keydown', function(evt) { if(evt.keyCode==73) { flash_obj.as3_tetrisGameRestart(); } }, false)
  63. }
  64. else
  65. {
  66. flash_obj = doc.getElementsByTagName('OBJECT')[0]
  67. flash_obj.addEventListener('keydown', function(evt) { if(evt.keyCode==73) { flash_obj.as3_tetrisGameRestart(); } }, false)
  68. }
  69.  
  70. //if(/Live\b/.test(href)) { // if one can't connect to arena after a predefined time, reload the page.
  71. //}
  72. }
  73. //if(doc.readyState == 'interactive') { tweak_flash() } else { addEventListener('DOMContentLoaded', tweak_flash, false) }
  74. if(doc.readyState == 'complete') { tweak_flash() } else { addEventListener('DOMContentLoaded', tweak_flash, false) }
  75. }
  76. }