Force Flash Wmode GPU

Force flash video playback to use wmode=gpu to allow hardware acceleration, based on Mikhoul's userscripts.

目前為 2017-02-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// jshint esversion: 6
// @name Force Flash Wmode GPU
// @namespace edsgerlin.com
// @description Force flash video playback to use wmode=gpu to allow hardware acceleration, based on Mikhoul's userscripts. 
// @author      Chin-Yuan Lin
// @version     0.0.1
// @include http://www.youtube.com/watch*
// @include http://youtube.com/watch*
// @include https://www.youtube.com/watch*
// @include https://youtube.com/watch*
// @include	http://dailymotion.com*
// @include	http://www.dailymotion.com*
// @include	https://dailymotion.com*
// @include	https://www.dailymotion.com*
// @include	http://vimeo.com*
// @include	http://www.vimeo.com*
// @include	https://vimeo.com*
// @include	https://www.vimeo.com*
// @include	http://metacafe.com*
// @include	http://www.metacafe.com*
// @include	https://metacafe.com*
// @include	https://www.metacafe.com*
// @include	http://funnyordie.com*
// @include	http://www.funnyordie.com*
// @include	https://funnyordie.com*
// @include	https://www.funnyordie.com*
// @include	http://videojug.com*
// @include	http://www.videojug.com*
// @include	https://videojug.com*
// @include	https://www.videojug.com*
// @include	http://blip.tv*
// @include	http://www.blip.tv*
// @include	https://blip.tv*
// @include	https://www.blip.tv*
// @include	http://vevo.com*
// @include	http://www.vevo.com*
// @include	https://vevo.com*
// @include	https://www.vevo.com*
// @include http://megavideo.com/*v=*
// @include	http://www.megavideo.com/*v=*
// @include	http://megaporn.com/video/*v=*
// @include	http://www.megaporn.com/video/*v=*
// @include	http://facebook.com/*video*
// @include	http://www.facebook.com/*video*
// @include	http://www.collegehumor.com/video/*
// @include	http://redtube.com/*
// @include	http://www.redtube.com/*
// @include	http://youporn.com/*watch*
// @include	http://www.youporn.com/*watch*
// @include	http://pornhub.com/*video*
// @include	http://www.pornhub.com/*video*
// @include	http://pornotube.com/*media*
// @include	http://www.pornotube.com/*media*
// @include	http://pornotube.com/*m=*
// @include	http://www.pornotube.com/*m=*
// @include	http://xvideos.com/*video*
// @include	http://www.xvideos.com/*video*
// @include	http://www.keezmovies.com/*
// @include	http://keezmovies.com/*
// @include	http://www.tube8.com/*
// @include	http://www.twitch.tv/*
// @include http://*.bilibili.com/*
// @include http://*.acfun.cn/*
// @include http://www.iqiyi.com/*
// @include https://v.qq.com/*
// @include http://v.qq.com/*
// @grant none
// ==/UserScript==

(() => {
    'use strict';

    const targetNode = document.body;
    const matchSelector = "object[type='application/x-shockwave-flash']";
    const onMatch = node => {
        const wmodeParam = node.querySelector("object>param[name='wmode']");
        if(wmodeParam){
            wmodeParam.value="gpu";
            return true;
        }
    };
    const MutationObserver=window.MutationObserver;
    // Polyfill for Element.matches().
    if (!Element.prototype.matches) {
        Element.prototype.matches =
            Element.prototype.matchesSelector ||
            Element.prototype.mozMatchesSelector ||
            Element.prototype.msMatchesSelector ||
            Element.prototype.oMatchesSelector ||
            Element.prototype.webkitMatchesSelector ||
            s => {
            const matches = (this.document || this.ownerDocument).querySelectorAll(s);
            let i = matches.length;
            while (--i >= 0 && matches.item(i) !== this) {}
            return i > -1;
        };
    }
    const observer = new MutationObserver(mutations => {
        mutations.some(mutation => {
            const addedNodes=Array.from(mutation.addedNodes||[]);
            return addedNodes.some(node => {
                if(node.nodeType!==Node.ELEMENT_NODE){
                    return;
                }
                else if(!node.matches(matchSelector)) {
                    return;
                }
                return onMatch(node);
            });
        });
    });
    const options={childList: true, subtree: true};
    observer.observe(targetNode, options);
})();