Full Screen Kongregate *OLD*

Play games at full browser size

当前为 2017-11-13 提交的版本,查看 最新版本

  1. //=============================================================================
  2. // ==UserScript==
  3.  
  4. // @name Full Screen Kongregate *OLD*
  5.  
  6. // @namespace Kongregate
  7.  
  8. // @description Play games at full browser size
  9. // @version 12+
  10. // @include *://kongregate.com/games/*
  11. // @include *://www.kongregate.com/games/*
  12. // @include *://a.kongregate.com/games/*/*
  13.  
  14. // ==/UserScript==
  15.  
  16. // Since Kongregate flash elements take a while to load, the following code
  17. // keeps trying to access elements by their ID until it succeeds.
  18.  
  19.  
  20. //=============================================================================
  21. //=Globals
  22.  
  23. var oldstyle = false,
  24. newstyle = false;
  25.  
  26. //=============================================================================
  27. //=Functions
  28.  
  29. // Once the element with the given ID is loaded, pass it to the given function.
  30. function Push(id, fun) {
  31. try {
  32. var elm = document.getElementById(id);
  33. if (elm == null)
  34. setTimeout(function() { Push(id, fun); }, 200);
  35. else fun(elm);
  36. } catch (e) { alert(e); }
  37. }
  38.  
  39. function Reset(elm)
  40. {
  41. elm.removeAttribute('width');
  42. elm.removeAttribute('height');
  43. elm.style['margin' ] = 0;
  44. elm.style['padding' ] = 0;
  45. elm.style['left' ] = 0;
  46. elm.style['top' ] = 0;
  47. elm.style['right' ] = '';
  48. elm.style['bottom' ] = '';
  49. elm.style['textAlign' ] = 'left';
  50. elm.style['position' ] = 'relative';
  51. elm.style['overflow' ] = 'hidden';
  52. }
  53.  
  54. // Resize an inner element based on style.
  55. function Resize(elm) {
  56. Reset(elm);
  57. elm.style['width' ] = '100%';
  58. if (elm.className == 'game_table')
  59. {
  60. var linkcell = document.getElementById('quicklinks').parentNode,
  61. fcontent = document.getElementById('flashframecontent');
  62. elm.style['height'] = (fcontent.offsetHeight - linkcell.offsetHeight)
  63. + 'px';
  64. }
  65. else
  66. elm.style['height'] = '100%';
  67. }
  68.  
  69. function PushResize(id) { Push(id, Resize); }
  70.  
  71. // Resize the main div according to the client dimensions.
  72. function ResizeClientRoot() {
  73. var doc = document.documentElement,
  74. floating = document.getElementById('floating_game_holder'),
  75. linkrow = document.getElementById('quicklinks').parentNode.parentNode,
  76. gamecell = document.getElementById('gameholder'),
  77. table = gamecell.parentNode.parentNode.parentNode,
  78. fcontent = document.getElementById('flashframecontent');
  79. floating.style.width = (doc.clientWidth-5+300)+'px';
  80. floating.style.height = (doc.clientHeight-10)+'px';
  81. floating.scrollIntoView(true);
  82. }
  83.  
  84. function ResizeDescend(elmstart, elmend) {
  85. for (var elm = elmstart; elm != elmend; elm = elm.parentNode)
  86. Resize(elm);
  87. }
  88.  
  89. //=============================================================================
  90. //=Main code
  91.  
  92. // Do property modifications.
  93.  
  94. try {
  95. var ResizeAll = function() {
  96. var gamediv = document.getElementById('gamediv'),
  97. gameiframe = document.getElementById('gameiframe');
  98. oldstyle = gameiframe != null;
  99. newstyle = gamediv != null && gamediv.nodeName == 'OBJECT';
  100. if (!(oldstyle || newstyle)) {
  101. setTimeout(ResizeAll, 200);
  102. return;
  103. }
  104. Push('play', function(elm) {
  105. elm.style['overflow'] = 'scroll'; });
  106. Push('primarywrap', function(elm) {
  107. elm.style['padding'] = 0;
  108. elm.style['width'] = 'auto'; });
  109.  
  110. var floating = document.getElementById('floating_game_holder');
  111. Reset(floating);
  112. if (newstyle)
  113. ResizeDescend(gamediv, floating);
  114. else {
  115. gameiframe.scrolling = 'no';
  116. ResizeDescend(gameiframe, floating);
  117. }
  118.  
  119. // Resize listener.
  120. ResizeClientRoot();
  121. window.addEventListener('resize', ResizeAll, false);
  122. Push('chat_container_cell', function(elm) {
  123. elm.style['width'] = '300px';
  124. elm.style['height'] = '100%'; });
  125. PushResize('chat_container');
  126. };
  127. ResizeAll();
  128. setTimeout(ResizeAll, 500);
  129. } catch (e) { alert(e); }