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.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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;
    }});

}());