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 提交的版本,檢視 最新版本

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

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

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

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

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

    }
    
})();