Greasy Fork is available in English.

Steam创意工坊添加下载按钮

利用 steamworkshop.download 网站给 Steam 创意工坊添加下载按钮

// ==UserScript==
// @name      Steam创意工坊添加下载按钮
// @namespace https://openai.com/
// @version   1.1.1
// @description  利用 steamworkshop.download 网站给 Steam 创意工坊添加下载按钮
// @match     https://steamcommunity.com/sharedfiles/filedetails/?*id=*
// @grant     GM_addStyle
// @grant     GM_xmlhttpRequest
// @license   Unlicense
// @connect   steamworkshop.download
// ==/UserScript==

(function() {
    // Extract the id from the URL
    let itemId;
    const urlParams = new URLSearchParams(window.location.search);
    if (urlParams.has('id')) {
        itemId = urlParams.get('id');
    } else {
        console.log("URL doesn't contain an 'id' parameter");
        return;
    }

    // Find the subscribe button element by id
    let subscribeButton = document.querySelector('#SubscribeItemBtn');
    if (!subscribeButton) {
        console.log("Could not find the element with id 'SubscribeItemBtn'");
        return;
    }

    // Replace the existing button with our custom button
    const newButton = document.createElement('button');

    // Add the required classes
    newButton.classList.add("btn_green_white_innerfade", "btn_border_2px", "btn_medium");

    newButton.innerText = 'Download';
    newButton.onclick = () => {
        // Temporarily replace the button with a "waiting" indicator
        newButton.innerText = 'Loading...';
        newButton.disabled = true;

        GM_xmlhttpRequest({
            method: "POST",
            url: "http://steamworkshop.download/online/steamonline.php",
            data: `item=${encodeURIComponent(itemId)}&app=431960`,
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            onload({responseText}) {
                // Replace the button content with the response html
                newButton.outerHTML = responseText;
            }
        });
    };
    subscribeButton.parentNode.replaceChild(newButton, subscribeButton);
})();