Factorio Free Mods Downloader

Changes all the links for download on https://mods.factorio.com/ if you haven't authorized

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Factorio Free Mods Downloader
// @namespace    https://re146.dev/
// @version      1.1
// @description  Changes all the links for download on https://mods.factorio.com/ if you haven't authorized
// @author       You
// @match        https://mods.factorio.com/mod/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=re146.dev/factorio/mods
// @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 buttons = document.getElementsByClassName('button-green');
    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 from re146.dev';
            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') {
            button.innerText = 'Download from re146.dev';
            button.setAttribute('target', '_blank');
            const version = button.parentElement.parentElement.children[0].innerText;
            button.setAttribute('href', `https://re146.dev/factorio/mods/en#https://mods.factorio.com/mod/${modName}#${version}`);
        }
    }
})();