Steam Workshop collection into last_mods statement

Displays a last_mods statement on Steam Workshop collection pages for easy synchronization of mod lists for multiplayer and stuff

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam Workshop collection into last_mods statement
// @namespace    https://greasyfork.org/en/users/3372-nixxquality
// @version      1.0.1
// @description  Displays a last_mods statement on Steam Workshop collection pages for easy synchronization of mod lists for multiplayer and stuff
// @author       nixx quality <[email protected]>
// @match        http://steamcommunity.com/sharedfiles/filedetails/?id=*
// @match        https://steamcommunity.com/sharedfiles/filedetails/?id=*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // First of all, is this an applicable Workshop page? The @match isn't enough
    // So, are we...
    // 1. A collection?
    // 2. In the Stellaris workshop? (maybe to be expanded)

    var navigation = document.getElementsByClassName("breadcrumbs")[0];
    if (navigation.children[0].innerText != "Stellaris")
    {
        return;
    }
    if (navigation.children[2].href.search("collections") == -1)
    {
        return;
    }

    // Okay, let's generate the list.

    var s = "last_mods={\r\n";
    [].forEach.call(document.getElementsByClassName("collectionItem"), function(item) {
        s += "\t\"mod/ugc_" + item.id.substr(11) + ".mod\"\r\n";
    });
    s += "}";

    // Now to display it to the user.

    var ourDiv = document.createElement("div");

    var helpfultext = document.createElement("p");
    helpfultext.innerHTML = "Your settings.txt can be found in Documents/Paradox Interactive/Stellaris.<br>Open it and look for the last_mods statement.<br>Replace it with this auto-generated thing:";
    ourDiv.appendChild(helpfultext);

    var textbox = document.createElement("textarea");
    textbox.value = s;
    textbox.style = "width: 100%; height: 100px; margin-bottom: 10px;";
    ourDiv.appendChild(textbox);

    document.getElementsByClassName("collectionChildren")[0].insertBefore(ourDiv, document.getElementsByClassName("collectionItem")[0]);
})();