Greasy Fork is available in English.

iframe redirector

iframe

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name           iframe redirector
// @namespace      http://efcl.info/
// @include        http://ow.ly/*
// @include        http://ht.ly/*
// @include        http://oneclip.jp/*
// @include        http://am6.jp/*
// @version 0.0.1.20140518104350
// @description iframe
// ==/UserScript==
(function() {
    /* URL : Xpath */
    var hashURL = {
        'http://ow.ly/' : 'id("hootFrame")',
        'http://oneclip.jp/' : 'id("close")/a',
        'http://am6.jp/' : 'id("infoFrame")/a[text()="閉じる"])',
        'http://ht.ly/' : 'id("hootFrame")'
    };
    var sourceURL = getCloseURL();
    if (sourceURL) {
        location.href = sourceURL;
    }
    function getCloseURL() {
        var nURL = location.href;
        for (var i in hashURL) {
            var linkTag = $x(document, hashURL[i])[0];
            if (linkTag) {
                if (linkTag.tagName == "IFRAME") {
                    return linkTag.src;
                } else { // aTag
                    return linkTag.href;
                }
            } else {
                return getOriginalIframe().src;
            }
        }
        return false;
    }

    /*
     Redirect to the iframed URL
     http://userscripts.org/scripts/show/66765
     Takayuki Miwa (http://wp.serpere.info)
     The MIT License; http://www.opensource.org/licenses/mit-license.php
     */
    function isLargeEnough(elm) {
        var ratio = 0.5;
        var body = $x(document, '/html/body')[0];
        return elm.offsetWidth > body.offsetWidth * ratio &&
                elm.offsetHeight > body.offsetHeight * ratio;
    }

    function getOriginalIframe() {
        var iframes = $x(document, '/html/body//iframe');
        for (var i = 0; i < iframes.length; ++i) {
            if (isLargeEnough(iframes[i])) {
                return iframes[i];
            }
        }
        return false;
    }

    function $x(context, exp) {
        context || (context = document);
        var expr = (context.ownerDocument || context).createExpression(exp, function (prefix) {
            return document.createNSResolver(context.documentElement || context).lookupNamespaceURI(prefix) ||
                    context.namespaceURI || document.documentElement.namespaceURI || "";
        });

        var result = expr.evaluate(context, XPathResult.ANY_TYPE, null);
        switch (result.resultType) {
            case XPathResult.STRING_TYPE : return result.stringValue;
            case XPathResult.NUMBER_TYPE : return result.numberValue;
            case XPathResult.BOOLEAN_TYPE: return result.booleanValue;
            case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
                // not ensure the order.
                var ret = [], i = null;
                while (i = result.iterateNext()) ret.push(i);
                return ret;
        }
        return null;
    }
})();