Fullscreen Flash objects

This userscript adds fullscreen buttons to Flash movies and games that otherwise wouldn't allow it.

当前为 2017-09-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Fullscreen Flash objects
  3. // @namespace samuelphillips.net
  4. // @include http://www.mspaintadventures.com/*
  5. // @include https://www.mspaintadventures.com/*
  6. // @include http://www.newgrounds.com/portal/view/*
  7. // @include https://www.newgrounds.com/portal/view/*
  8. // @include http://www.miniclip.com/games/*/*/*
  9. // @include https://www.miniclip.com/games/*/*/*
  10. // @include http://www.engineering.com/GamesPuzzles/Motherload/tabid/4708/Default.aspx
  11. // @include http://www.kongregate.com/games/*/*
  12. // @include https://www.kongregate.com/games/*/*
  13. // @version 2
  14. // @grant none
  15. // @description This userscript adds fullscreen buttons to Flash movies and games that otherwise wouldn't allow it.
  16. // ==/UserScript==
  17.  
  18. // Generated by LiveScript 1.4.0
  19. (function(){
  20. (window.dofsfload = function(){
  21. var selTargets, st, observeDom, handleFlashObjects, fscHandler;
  22. selTargets = "embed, object, iframe";
  23. console.log("Fullscreen Flash Objects loaded!");
  24. st = document.createElement('style');
  25. st.type = 'text/css';
  26. st.appendChild(document.createTextNode(".fullscreen {\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: black;\n}\n\n.fullscreen .hide-when-fs {\n display: none;\n}\n.fullscreen::before {\n display: none;\n}\n.fullscreen::after {\n display: none;\n}\n.user-fullscreen-button {\n " + (/mspaintadventures\.com/.test(location.href) ? "" : "position: absolute;\nbottom: 100%;") + "\n}"));
  27. document.head.appendChild(st);
  28. observeDom = function(){
  29. var MutationObserver, ref$, eventListenerSupported;
  30. MutationObserver = (ref$ = window.MutationObserver) != null
  31. ? ref$
  32. : window.WebKitMutationObserver;
  33. eventListenerSupported = window.addEventListener;
  34. return function(obj, callback){
  35. var obs;
  36. if (MutationObserver != null) {
  37. obs = new MutationObserver(function(mutations, observer){
  38. if (mutations[0].addedNodes.length || mutations[0].removedNodes.length) {
  39. return callback();
  40. }
  41. });
  42. obs.observe(obj, {
  43. childList: true,
  44. subtree: true
  45. });
  46. } else if (eventListenerSupported) {
  47. obj.addEventListener('DOMNodeInserted', callback, false);
  48. obj.addEventListener('DOMNodeRemoved', callback, false);
  49. }
  50. };
  51. }();
  52. handleFlashObjects = function(place){
  53. var embeds, i$, len$;
  54. embeds = place.querySelectorAll(selTargets);
  55. for (i$ = 0, len$ = embeds.length; i$ < len$; ++i$) {
  56. (fn$.call(this, embeds[i$]));
  57. }
  58. function fn$(embed){
  59. var btn;
  60. if (embed.getAttribute('data-has-fs-btn')) {
  61. return;
  62. }
  63. embed.setAttribute('data-has-fs-btn', 'true');
  64. btn = document.createElement('button');
  65. btn.innerHTML = "Fullscreen";
  66. btn.setAttribute('class', 'user-fullscreen-button hide-when-fs');
  67. embed.parentNode.insertBefore(btn, embed);
  68. btn.addEventListener('click', function(){
  69. var pn, bind;
  70. pn = embed.parentNode;
  71. window.myCurrentFullscreenEmbed = embed;
  72. bind = function(obj, k){
  73. if ((obj != null ? obj[k] : void 8) != null) {
  74. return function(){
  75. return obj[k].apply(obj);
  76. };
  77. } else {
  78. return null;
  79. }
  80. };
  81. if (pn.requestFullscreen != null) {
  82. pn.requestFullscreen();
  83. } else if (pn.mozRequestFullScreen != null) {
  84. pn.mozRequestFullScreen();
  85. } else if (pn.webkitRequestFullScreen != null) {
  86. pn.webkitRequestFullScreen();
  87. } else if (pn.msRequestFullScreen != null) {
  88. pn.msRequestFullScreen();
  89. } else {
  90. console.log("No requestFullscreen");
  91. }
  92. }, false);
  93. }
  94. };
  95. handleFlashObjects(document);
  96. observeDom(document.body, function(){
  97. handleFlashObjects(document);
  98. });
  99. fscHandler = function(){
  100. var fse, emb, hratio, wratio, ratio, height, width, embeds, i$, len$;
  101. fse = document.fullscreenElement;
  102. if (fse == null) {
  103. fse = document.mozFullScreenElement;
  104. }
  105. if (fse == null) {
  106. fse = document.webkitFullScreenElement;
  107. }
  108. if (fse == null) {
  109. fse = document.msFullscreenElement;
  110. }
  111. if (fse) {
  112. fse.classList.add('fullscreen');
  113. emb = window.myCurrentFullscreenEmbed;
  114. console.log('fullscreen on!');
  115. hratio = screen.height / emb.getAttribute('height');
  116. wratio = screen.width / emb.getAttribute('width');
  117. ratio = Math.min(hratio, wratio);
  118. console.log("Setting data-orig-* on %o", fse);
  119. emb.setAttribute('data-orig-width', emb.getAttribute('width'));
  120. emb.setAttribute('data-orig-height', emb.getAttribute('height'));
  121. height = ratio * emb.getAttribute('height');
  122. emb.setAttribute('height', height);
  123. width = ratio * emb.getAttribute('width');
  124. if (width === screen.width) {
  125. width -= 1;
  126. }
  127. emb.setAttribute('width', width);
  128. document.body.focus();
  129. } else {
  130. document.querySelector('.fullscreen').classList.remove('fullscreen');
  131. console.log('fullscreen off!');
  132. embeds = document.querySelectorAll(selTargets);
  133. for (i$ = 0, len$ = embeds.length; i$ < len$; ++i$) {
  134. emb = embeds[i$];
  135. try {
  136. emb.setAttribute('width', emb.getAttribute('data-orig-width'));
  137. emb.setAttribute('height', emb.getAttribute('data-orig-height'));
  138. } finally {
  139. 0;
  140. }
  141. }
  142. }
  143. };
  144. document.addEventListener('fullscreenchange', fscHandler, false);
  145. document.addEventListener('mozfullscreenchange', fscHandler, false);
  146. document.addEventListener('webkitfullscreenchange', fscHandler, false);
  147. document.addEventListener('msfullscreenchange', fscHandler, false);
  148. })();
  149. }).call(this);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址