Simple Faster Flash

Faster flash from simple way.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Simple Faster Flash
// @name:zh-CN   Flash 简单优化
// @namespace    https://greatest.deepsurf.us/users/159546
// @version      1.0.1
// @description  Faster flash from simple way.
// @description:zh-CN 略微提升 Flash 元素的性能。
// @author       LEORChn
// @include      *
// @run-at       document-start
// @grant        none
// ==/UserScript==
var done=0,countdown=10 *5;// 10 sec
(function(){
	recheck();
})();
function recheck(){
    __object();
    __embed();
    if(pageloaded() && finaly())return;
    setTimeout(recheck,200);
}
function __object(){
    try{
    for(var i=0,v=document.getElementsByTagName('object'),len=v.length;i<len;i++)
        if(v[i].type.toLowerCase().includes('flash')){
            var qNode;
            for(var i2=0,v2=v[i].childNodes,l2=v2.length;i2<l2;i2++)
                if(v2[i2].name && v2[i2].name.includes('quality')){//maybe multi object elements nesting. Like news.163.com
                    qNode=v2[i2];
                    break;
                }
            if(qNode==undefined){
                qNode=document.createElement('param');
                qNode.name='quality';
                v[i].appendChild(qNode);
            }
            if(qNode.value!='low'){
                qNode.value='low';
                done++;
            }
        }
    }catch(e){}
}
function __embed(){
    for(var i=0,v=document.getElementsByTagName('embed'),len=v.length;i<len;i++)
        if(v[i].type.toLowerCase().includes('flash') && !v[i].outerHTML.includes('quality="low"')){
            v[i].outerHTML=v[i].outerHTML.replace('<embed','<embed quality="low"');
            done++;
        }
}
function pageloaded(){ return document.readyState.toLowerCase()=='complete'; }
function finaly(){
    countdown--;//Use count down because some flash element using js to add in page. Like live.bilibili.com...
    if(countdown>0)return false;
    try{console.log('Simple Faster Flash: Faster '+done+' flash element(s).');}catch(e){}
    return true;
}