Factorio mod downloader

Download mods from mods.factorio.com for free

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Factorio mod downloader
// @namespace    nipsuontop
// @version      1.1
// @description  Download mods from mods.factorio.com for free
// @author       Ruhto
// @match        https://mods.factorio.com/mod/*
// @icon         https://steamuserimages-a.akamaihd.net/ugc/793135197243665662/A9845DE547208C8293F60FB84B241C65A418E4B4/?imw=128&imh=128&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=true
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';


    const modUrlMatch = location.href.match(/^https:\/\/mods\.factorio\.com\/mod\/([^\/]+)/);
    if (!modUrlMatch) {
        return;
    }
    const modName = modUrlMatch[1];


    const loggedInButtons = document.querySelectorAll('.mod-download-section .mod-download-button a.button-green');
    for (const button of loggedInButtons) {

        if (button.innerText.trim() !== 'Download' || !button.classList.contains('disabled')) {
            continue;
        }


        button.innerText = 'Download';
        button.classList.remove('disabled');
        button.setAttribute('target', '_blank');
        button.setAttribute('title', '');
        button.setAttribute('href', `https://re146.dev/factorio/mods/en#https://mods.factorio.com/mod/${modName}`);
    }


    const buttons = document.getElementsByClassName('btn mod-download-button btn-download');
    for (const button of buttons) {
        if (button.innerText.trim() !== 'Download') {
            continue;
        }
        if (!button.getAttribute('href').startsWith('/login?next=')) {
            continue;
        }
        if (button.parentElement.tagName === 'DIV') {
            button.innerText = 'Download';
            button.setAttribute('target', '_blank');
            button.setAttribute('href', `https://re146.dev/factorio/mods/en#https://mods.factorio.com/mod/${modName}`);
        } else if (button.parentElement.tagName === 'TD') {
            const version = button.parentElement.parentElement.children[0].innerText;
            button.innerText = 'Download';
            button.setAttribute('target', '_blank');
            button.setAttribute('href', `https://re146.dev/factorio/mods/en#https://mods.factorio.com/mod/${modName}#${version}`);
        }
    }
})();