Hung-Ya Forum Tweaks

Some tweaks on the Hung-Ya forum

当前为 2014-08-03 提交的版本,查看 最新版本

// ==UserScript==
// @name           Hung-Ya Forum Tweaks
// @description    Some tweaks on the Hung-Ya forum
// @include        http://bbs.bbs-tw.com/*
// @version 0.0.1.20140803022513
// @namespace https://greasyfork.org/users/2233
// ==/UserScript==

var wnd = window
var doc = wnd.document
var loc = location
var href = loc.href

if(/^http:\/\/bbs\.bbs-tw\.com\/.*\/postshow\.pl\b/.test(href))
{
    // Auto redirection upon failure
    if( (!doc.getElementById("BbsShow")) || (!doc.getElementById("BbsShowMenu")) ){ loc.href += "&_=" + +(new Date); throw 'exit' }

    // Remove scripts
    var scripts=doc.getElementsByTagName('script')
    for(var i=scripts.length-1; i>=0; i--){ try { scripts[i].parentNode.removeChild(scripts[i]) } catch(e){} }

    // Diable the <meta> refresh
    addEventListener("DOMContentLoaded", function(){ wnd.stop(); if( (!doc.getElementById("BbsShow")) || (!doc.getElementById("BbsShowMenu")) ){ loc.reload() } }, false)

    // Clear all timeouts/intervals
    setTimeout(function(){
        var id = setTimeout(function(){}, 0)
        while(id--){ clearTimeout(id) }
        var id = setInterval(function(){}, 0)
        while(id--){ clearInterval(id) }
    }, 100)

    // Reload broken images
    addEventListener("DOMContentLoaded", function(){
        var is_img_ok = function(img)
        {
            if(img.readyState!='complete'){ return false }
            if(('naturalHeight' in img)&&(img.naturalHeight+img.naturalWidth==0)){ return false }
            if(img.width+img.height==0){ return false }
            return true
        }
        var reloadImages=function(w){
            try {
                for(var i=0; img=w.document.images[i]; i++){ if(!is_img_ok(img)){ img.src=img.src } } // doc.images[j]... does not work, cuz doc isn't a member of a window object
                for(var j=0,F=null;F=w.frames[j];j++){ reloadImages(F) }
            } catch(e){}
        }
        reloadImages(wnd)
    }, false)
}