Hung-Ya Forum Tweaks

Some tweaks on the Hung-Ya forums.

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

// ==UserScript==
// @name           Hung-Ya Forum Tweaks
// @description    Some tweaks on the Hung-Ya forums.
// @include        http://bbs.bbs-tw.com/*
// @version 0.0.1.20140805075712
// @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\//.test(href))
{
    if(/\/postshow\.pl\?/.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)
    }
    else if(/\/postlist\.pl\?/.test(href))
    {
        var lnks = doc.getElementsByTagName('A')
        for(var i=lnks.length-1; i>=0; i--)
        {
            lnks[i].target = '_blank'
        }
    }
}