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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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;
    }});

}());