Factorio Mod Mirror ⚙️

Adds a mirror download button in Factorio mod pages (Forked from RE146.dev)

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Factorio Mod Mirror ⚙️
// @namespace    https://github.com/koyomitan3/factorio-mod-magnet
// @version      2024.05.30.1a
// @description  Adds a mirror download button in Factorio mod pages (Forked from RE146.dev)
// @match        https://mods.factorio.com/mod/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=re146.dev/factorio/mods
// @autor        koyomitan3
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

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

    // Create the button

    const downloadButton = NewButton(modName);

    // Adds hover effect

    downloadButton.onmouseover = function() {
        downloadButton.style.backgroundColor = '#c0392b';
    };
    downloadButton.onmouseout = function() {
        downloadButton.style.backgroundColor = '#e74c3c';
    };

    // Find the container to insert the button
    const container = document.querySelector('.mod-tags-download');
    if (container) {
        // Insert the button at the top of the container
        container.append(downloadButton);
    } else {
        console.warn('Could not find the container to insert the download button');
    }
})();
function NewButton(modName) {
    const downloadButton = document.createElement('a');
    downloadButton.innerText = 'Download Mirror Link';
    downloadButton.style.backgroundColor = '#e74c3c';
    downloadButton.style.color = '#ffffff';
    downloadButton.style.padding = '10px 20px';
    downloadButton.style.textDecoration = 'none';
    downloadButton.style.display = 'inline-block';
    downloadButton.style.borderRadius = '5px';
    downloadButton.style.fontSize = '16px';
    downloadButton.style.fontWeight = 'bold';
    downloadButton.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.1)';
    downloadButton.style.transition = 'background-color 0.3s ease';
    downloadButton.setAttribute('href', `https://re146.dev/factorio/mods/en#https://mods.factorio.com/mod/${modName}`);
    downloadButton.setAttribute('target', '_blank');
    return downloadButton;
}