Coolrom, direct download

With this, the download link will point to the direct download url, allowing to download without opening popups windows and without downloading downloader executables.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Coolrom, direct download
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  With this, the download link will point to the direct download url, allowing to download without opening popups windows and without downloading downloader executables.
// @include      *://coolrom.com/roms/*
// @include      *://www.coolrom.com/roms/*
// @include      *://coolrom.com.au/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    var appendInterval, iframeInterval, idInterval, iframe, query, setTime, downloadUrl;

    iframe = document.createElement('iframe');
    iframe.style = 'display:none';
    query = "";
    idInterval = setInterval(function () {
        var element = document.querySelector('a[href*="/dlpop.php"], a[href*="/downloader"]');
        if (element) {
            element = document.querySelector('a[href*="/downloader"]');
            if (element) {
                query = element.href.split("?", 2)[1];
            } else {
                element = document.querySelector('a[href*="/dlpop.php"]');
                if (element) {
                    query = element.href.replace(/[^\?]+\?([^']+).*/, "$1");
                }
            }
            iframe.src = '/dlpop.php?' + query;
            clearInterval(idInterval);
        }
    }, 1);

    appendInterval = setInterval(function () {
        if (document.body) {
            document.body.appendChild(iframe);
            clearInterval(appendInterval);
        }
    }, 1);

    iframeInterval = setInterval(function () {
        var links, input;

        if (iframe.contentWindow && !setTime) {
            Object.defineProperty(iframe.contentWindow, 'time', {value: 0});
            setTime = true;
        }

        input = iframe.contentDocument && iframe.contentDocument.getElementsByTagName('input')[0];
        if (input) {
            clearInterval(iframeInterval);
            downloadUrl = input.parentNode.action;
            links = document.querySelectorAll('a[href*="/dlpop.php"], a[href*="/downloader"]');
            Array.prototype.forEach.call(links, function (a) {
                a.href = downloadUrl;
            });
            var center = document.querySelectorAll('center')[1];
            if (center && center.textContent && (center.textContent.indexOf('Este título está protegido') > -1 || center.textContent.indexOf("title is protected") > -1)) {
                var div = document.createElement('center');
                div.innerHTML = '<div class="container"><style>.download-button {position: absolute;top: 50%;left: 54.5%;transform: translate(-50%, -50%);font-family: Verdana;font-style: bold;font-size: 18px;color: #FFFFFF;}</style><a class="download_link" href="' + downloadUrl + '"><img src="/images/download_button2.png" alt="download" style="width:300px;"><div class="download-button">DOWNLOAD</div></a></div>';
                center.insertBefore(div, center.childNodes[13]);
                center.removeChild(center.childNodes[14]);
            }
            console.log(downloadUrl);
            iframe.src = 'about:blank';
        }
    }, 1);


    Object.defineProperty(window, 'open', {value: function (url) {
        var inter;
        if (url.substr(0, 10) === '/dlpop.php') {
            inter = setInterval(function () {
                if (downloadUrl) {
                    window.location = downloadUrl;
                    clearInterval(inter);
                }
            }, 10);
        } else {
            window.location = url;
        }
        return true;
    }});

}());