Skip to content

Instantly share code, notes, and snippets.

@burritosoftware
Created June 15, 2022 06:57
Show Gist options
  • Save burritosoftware/3454510bd4a665207acb674a096277d6 to your computer and use it in GitHub Desktop.
Save burritosoftware/3454510bd4a665207acb674a096277d6 to your computer and use it in GitHub Desktop.
Steam Workshop Download Button (soon to be used with my steamwsauto program)
// ==UserScript==
// @name Steam Workshop Download Button
// @author Burrito (forked)
// @description Adds a button to the Steam Workshop pages that lets you open steamwsauto to begin downloading. Also provides fixes for the Subscribe button to fix patches with the Download button.
// @include *steamcommunity.com/sharedfiles/filedetails/?id=*
// @grant GM_addStyle
// @version 1.0.0
// ==/UserScript==
var patt=new RegExp("[0-9]{2,15}");
var id = patt.exec(document.URL);
GM_addStyle(".subscribeOption { display: none; } .subscribeOption.selected { display: block; line-height: 30px; } #SubscribeItemBtn:hover .subscribeOption.selected + .subscribeOption.remove { display: block; line-height: 30px; }")
const siblings = (elem) => {
// create an empty array
let siblings = [];
// if no parent, return empty list
if (!elem.parentNode) {
return siblings;
}
// first child of the parent node
let sibling = elem.parentNode.firstElementChild;
// loop through next siblings until `null`
do {
// push sibling to array
if (sibling != elem) {
siblings.push(sibling);
}
} while (sibling = sibling.nextElementSibling);
return siblings;
};
var subButton = document.getElementById("SubscribeItemBtn");
var button = subButton.cloneNode(true);
// Change text in box
subButton.parentNode.parentNode.getElementsByTagName("h1")[0].getElementsByTagName("span")[0].innerHTML = "Subscribe or download";
// Change icon
var icon = button.getElementsByClassName("subscribeIcon")[0];
icon.setAttribute('style', 'top: 8px; background-image: url(https://store.cloudflare.steamstatic.com/public/shared/images/header/btn_header_installsteam_download.png?v=1);');
// Change button gradient
var spanStyle = "color: #91eaf7 !important; background: #417B9C; background: -webkit-linear-gradient( top, #5AA9D6 5%, #417B9C 95%); background: linear-gradient( to bottom, #5AA9D6 5%, #417B9C 95%);";
var innerFade = "background: #57749e; background: -webkit-linear-gradient( top, #66C0F4 5%, #417B9C 95%); background: linear-gradient( to bottom, #66C0F4 5%, #417B9C 95%);";
button.setAttribute('style', 'position: relative; ' + innerFade);
var span = button.querySelector('span');
span.setAttribute('style', spanStyle);
// Get appid
var inputElement = document.querySelector('input[name="appid"]');
var appid = inputElement.getAttribute('value')
button.removeAttribute('onclick');
button.setAttribute('href', 'steamwsauto://' + appid + '%20' + id);
button.setAttribute('id', 'DownloadItemBtn');
button.classList.add('selected');
var buttonText = button.querySelector('#SubscribeItemOptionAdd');
buttonText.setAttribute('id', 'DownloadItemOption')
buttonText.innerHTML = "Download";
var nodes = siblings(buttonText);
nodes.forEach(node => node.remove());
// append the element after the real subscribe button
if (subButton.nextSibling)
{
subButton.parentNode.insertBefore(button, subButton.nextSibling);
}
else
{
subButton.parentNode.appendChild(button);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment