Steam Workshop Subscribe Button Injector

Enhances Steam Workshop browsing by adding subscribe buttons to items lacking them.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam Workshop Subscribe Button Injector
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Enhances Steam Workshop browsing by adding subscribe buttons to items lacking them.
// @author       Your Name
// @match        https://steamcommunity.com/workshop/browse/?*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to inject subscribe buttons into workshop items
    function injectSubscribeButtons() {
        // Selecting all workshop items on the page
        var items = document.querySelectorAll('.ugc');
        
        // Iterating through each item
        items.forEach(function(item) {
            // Retrieving item and app IDs
            var itemID = item.dataset.publishedfileid;
            var appID = item.dataset.appid;
            
            // Checking if IDs are present
            if (itemID && appID) {
                // Creating HTML for subscribe button and controls
                var controlsHTML = `
                    <div class="workshopItemSubscriptionControls aspectratio_square" style="position: relative; top: -35px;">
                        <span class="action_wait" id="action_wait_${itemID}" style="display: none;">
                            <img src="https://community.fastly.steamstatic.com/public/images/login/throbber.gif">
                        </span>
                        <span onclick="SubscribeInlineItem('${itemID}', '${appID}'); return false;" id="SubscribeItemBtn${itemID}" class="general_btn subscribe">
                            <div class="subscribeIcon"></div>
                        </span>
                    </div>
                `;
                
                // Inserting the subscribe button HTML into the item
                item.insertAdjacentHTML('beforeend', controlsHTML);
            }
        });
    }

    // Event listener for when the page finishes loading
    window.addEventListener('load', injectSubscribeButtons);

})();