Emmet's Direct Factorio Mods Downloader 2024

Directly download any of the latest mods from https://mods.factorio.com with just one click. No authorization needed.

当前为 2024-11-13 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Emmet's Direct Factorio Mods Downloader 2024
// @version      2.0.0
// @description  Directly download any of the latest mods from https://mods.factorio.com with just one click. No authorization needed.
// @author       Discord @EmmetPotet
// @match        https://*.factorio.com*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=re146.dev/factorio/mods
// @grant        none
// @license      MIT
// @namespace https://re146.dev/
// ==/UserScript==

const parser = new DOMParser()
const getModVersionFromName = async (modName) => {
    return new Promise(async (resolve, reject) => {
        fetch(`https://mods.factorio.com/mod/${modName}`, {
            "method": "GET",
        }).then(async (res) => {
            let modPage = parser.parseFromString(await res.text(), 'text/html');
            for (const dd of modPage.querySelectorAll('dt')) {
                if (dd.innerHTML == "Latest Version:") {
                    resolve(dd.nextElementSibling.innerHTML.trim().split(" ")[0]);
                }
            }
        }).catch((e) => {
            console.log(e)
            reject()
        });
    });
}
const hijackButton = async (button, modName, version) => {
    version = (typeof version === 'undefined') ? await getModVersionFromName(modName) : version;
    button.classList.remove("disabled");
    button.setAttribute('href', `https://mods-storage.re146.dev/${modName}/${version}.zip?anticache=${Math.random()}`);
    button.setAttribute('title', `You don't need to own Factorio to download mods. ;3`);
}

(async function() {
    'use strict';

    let currentURL = new URL(location.href)
    if (currentURL.searchParams.has("next")) {
        let redirect = currentURL.searchParams.get("next");
        if (redirect.startsWith("/mod/")) {
            location.href = "https://mods.factorio.com" + redirect
        } else {
            location.href = "https://mods.factorio.com/"
        }
    }
    
    let isVersionSelectionPage = currentURL.href.endsWith('/downloads');
    for (const button of document.getElementsByClassName("button-green text-center")) {
        if (button.href == "") location.href = "https://mods.factorio.com/logout" // does not work while logged in.
        let buttonURL = new URL(button.href)
        let redirect = buttonURL.searchParams.get("next")
        if (redirect.startsWith("/mod/")) {
            let modName = redirect.split("/")[2];
            if (isVersionSelectionPage && button.parentNode.nodeName == "TD") {
                hijackButton(button, modName, button.parentNode.parentNode.firstElementChild.innerHTML)
            } else {
                hijackButton(button, modName)
            }
        }

    }
    
})();