Skip to content

Instantly share code, notes, and snippets.

@Saturate
Created October 4, 2022 16:56
Show Gist options
  • Save Saturate/1519244dee074f3b6afdea349580f0e0 to your computer and use it in GitHub Desktop.
Save Saturate/1519244dee074f3b6afdea349580f0e0 to your computer and use it in GitHub Desktop.
Project Zomboid - Generate WorkshopItems from Steam Workshop Collection

Project Zomboid - Generate WorkshopItems from Steam Workshop Collection

This snippet will generate a list suited for the Project Zomboid config from a Steam Workshop Collection.

How to use:

  1. Navigate to your collection (eg. https://steamcommunity.com/sharedfiles/filedetails/?id=2871262277)
  2. Copy the code in console.js
  3. Open the devtools for your browser (F12)
  4. Paste and run the code
  5. Copy the output
  6. Paste the config line into your config.

The output will look like this:

WorkshopItems=2625625421;2619072426;2423906082;2618213077;2522173579;2870394916;2846036306;2811383142;2805630347;2772575623;2642541073;2566953935;2516123638;2489148104;2441990998;2169435993;2478768005;2392709985;2490220997
var modIds = Array.from(document.querySelectorAll('[id^="sharedfile_"]')).map(mod => {
return mod.id.replace('sharedfile_','');
})
console.log(`This list contains ${modIds.length} mods, copy it to your PZ config.`)
console.log(`WorkshopItems=${modIds.join(';')}`)
@FlintMcgy
Copy link

FlintMcgy commented Mar 28, 2024

Here is a better snippet made using @contrid code with ChatGPT that is faster and also gives you a Numbered List of all the Mods with their Id's

const URLS = Array.from(document.querySelectorAll('[id^="sharedfile_"]')).map(mod => 
    "https://steamcommunity.com/sharedfiles/filedetails/?id=" + mod.id.replace('sharedfile_', '')
);

async function getIDS(URLS) {
    return Promise.all(URLS.map(async (url, index) => {
        try {
            console.log(`processing #${index + 1}/${URLS.length}: ${url}`);
            const res = await fetch(url);
            const html = await res.text();
            
            const extractMatches = (pattern) => (html.match(new RegExp(pattern, "gmi")) || []).map(wks => wks.split(": ")[1]);
            
            const ids = extractMatches(/Workshop ?ID: (\d*)/);
            const names = extractMatches(/Mod ?ID: (\d*\w*\d*\w*\d*\.*\d*)/);

            return { ids, names };
        } catch (error) {
            console.error(`Error processing #${index + 1}: ${error.message}`);
            return { ids: [], names: [] };
        }
    }));
}

async function main() {
    const results = await getIDS(URLS);
    const modList = results.map(({ ids, names }, index) => `${index + 1}. WorkshopID:[${ids[0]}] ModIDs[${names.join(", ")}]`);
    const IDS = results.flatMap(({ ids }) => ids);
    const NAMES = results.flatMap(({ names }) => names);

    console.log(`WorkshopItems=${IDS.join(";")}`);
    console.log(`Mods=${NAMES.join(";")}`);
    console.log(`ModList=${modList.join(", ")}`);
}

main();

@sbwns
Copy link

sbwns commented Apr 17, 2024

Made this site so that it's user friendly
https://www.pzutil.com/

Does not log unprocessed URLs yet but will add that shortly

@Motzumoto
Copy link

Made this site so that it's user friendly https://www.pzutil.com/

Does not log unprocessed URLs yet but will add that shortly

Wonderful!

@GamingDaveUk
Copy link

Thanks guys, I was looking at amp and trying to work out what i need to put in these sections:
image
The site is going to help with 2 and 3, the code further up, I think I can use to know what to put into 1.

Going to look at it all when more awake, but I just wanted to say you have turned a task I was dreading, and was making me wonder if i wanted to set up a server into something that should be quite simple. Your time on these projects is GREATLY appreciated! Thank you

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