Skip to content

Instantly share code, notes, and snippets.

@elboletaire
Created August 10, 2020 00:21
Show Gist options
  • Save elboletaire/e9654139cbd20ee9873e3e0360c0a2f6 to your computer and use it in GitHub Desktop.
Save elboletaire/e9654139cbd20ee9873e3e0360c0a2f6 to your computer and use it in GitHub Desktop.
Steam Workshop download button User Script
// ==UserScript==
// @name Steam Workshop Downloader
// @version 0.1
// @description Downloads steam workshop items using steamworkshopdownloader api
// @author El Boletaire
// @include *steamcommunity.com/sharedfiles/filedetails/?*id=*
// @include *steamcommunity.com/workshop/filedetails/?*id=*
// @grant GM_xmlhttpRequest
// @namespace https://github.com/elboletaire
// ==/UserScript==
(function() {
'use strict'
addButton()
})();
function post(url, data) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: url,
data: data,
headers: {
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': 'https://steamworkshopdownloader.io/',
},
onload: resolve,
})
})
}
function downloadButton(text) {
return `<span>${text}</span>`
}
function addButton() {
const a = document.createElement('a')
a.classList.add('btn_darkblue_white_innerfade')
a.classList.add('btn_border_2px')
a.classList.add('btn_medium')
a.id = 'worshop-download-btn'
a.innerHTML = downloadButton('Download')
a.onclick = () => {
a.innerHTML = downloadButton('Downloading...')
download(getFileID(),a)
}
const element = document.getElementById('SubscribeItemBtn')
element.style.float = 'left'
element.style.width = '100%'
a.style.float = 'left'
a.style.width = '100%'
const [title] = document.querySelectorAll('.game_area_purchase_game h1')
title.style.width = '900px'
element.parentNode.insertBefore(a, element.nextSibling);
}
function getFileID() {
const url_string = window.location.href
const url = new URL(url_string)
const id = url.searchParams.get('id')
return id
}
let str = 'retrieving'
function statusPost(uuid) {
post('https://api.steamworkshopdownloader.io/api/download/status', JSON.stringify({uuids: [uuid]})).then((res) => {
JSON.parse(res.responseText, (key, value) => {
if (key === 'status' && value === 'prepared') {
str = value
}
})
})
return str
}
function downloadRequestData(itemId) {
return JSON.stringify({
publishedFileId: parseInt(itemId, 10),
collectionId: null,
extract: true,
hidden: true,
direct: false,
})
}
function download(itemId) {
post('https://api.steamworkshopdownloader.io/api/download/request', downloadRequestData(itemId)).then((res) => {
const [,,,uuid] = res.responseText.split('\"')
const request = `https://api.steamworkshopdownloader.io/api/download/transmit?uuid=${uuid}`
const timer = () => {
if (statusPost(uuid) === 'prepared') {
document.getElementById('worshop-download-btn').innerHTML = downloadButton('Download')
const element = document.createElement('a')
element.href = request
document.body.appendChild(element)
element.click()
element.remove()
return
}
setTimeout(timer, 250)
}
timer()
})
}
@CommunityWorkshop
Copy link

CommunityWorkshop commented Aug 13, 2022

New Link: https://exe.io/GitHub or if that doesnt work then https://github.com/Community-Workshop-Downloader/CommunityWorkshopMain

-- GamingNerdLeith#2591 (Community Workshop Downloader) --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment