Flash Accelerate

开启FlashPlayer硬件渲染加速

Fra og med 06.02.2015. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Flash Accelerate
// @namespace   [email protected]
// @description 开启FlashPlayer硬件渲染加速
// @include     *
// @version     1.04
// @grant       none
// ==/UserScript==

//创意来自 gpu-accelerated-flash-player 扩展!
//是否有加速效果作者也不知道。
//只有当不存在 wmode 参数时才会开启加速
//关于wmode参数的解释:http://helpx.adobe.com/flash/kb/flash-object-embed-tag-attributes.html
//
//以下是脚本可选项:
var force_all = false; //默认 false,当为true时始终开启加速,忽略wmode是否存在,会覆盖下一个选项
var force_direct_gpu = false; //默认 false,当存在且wmode = direct 时开启加速
var wmodeValue = 'gpu'; //默认 gpu,可以是 direct。

setTimeout(function () {
  var objects = document.getElementsByTagName('object');
  var embeds = document.getElementsByTagName('embed');
  var has_wmode;
  var toggle = function (o) {
    //console.log(o.id);
    if (o) {
      o.style.display = 'none';
      setTimeout(function () {
        o.style.display = 'block';
      }, 0);
    }
  };
  //console.log(objects);
  if (objects.length > 0) {
    for (var i = 0; i < objects.length; i++) {
      has_wmode = false;
      for (var ii = 0; ii < objects[i].childNodes.length; ii++) {
        if (objects[i].childNodes[ii].name.toLowerCase() == 'wmode') {
          has_wmode = true;
          if (force_all) {
            objects[i].childNodes[ii].value = wmodeValue;
            toggle(objects[i]);
          } 
          else if (force_direct_gpu && objects[i].childNodes[ii].value == 'direct') {
            objects[i].childNodes[ii].value = wmodeValue;
            toggle(objects[i]);
          }
          break;
        }
      }
      if (!has_wmode) {
        var param = document.createElement('param');
        param.name = 'wmode';
        param.value = wmodeValue;
        objects[i].appendChild(param);
        toggle(objects[i]);
      }
    }
  }
  if (embeds.length > 0) {
    for (var i = 0; i < embeds.length; i++) {
      if (force_all) {
        embeds[i].setAttribute('wmode', wmodeValue);
        toggle(embeds[i]);
      }
      else if (force_direct_gpu && embeds[i].getAttribute('wmode') == 'direct') {
        embeds[i].setAttribute('wmode', wmodeValue);
        toggle(embeds[i]);
      }
      else if (!embeds[i].getAttribute('wmode')) {
        embeds[i].setAttribute('wmode', wmodeValue);
        toggle(embeds[i]);
      }
    }
  }
}, 1024); //延时时间可能存在问题。