Skip to content

Instantly share code, notes, and snippets.

@Earlopain
Last active June 22, 2020 19:44
Show Gist options
  • Save Earlopain/9cfb6d225264cc6c2b393f3c84d94963 to your computer and use it in GitHub Desktop.
Save Earlopain/9cfb6d225264cc6c2b393f3c84d94963 to your computer and use it in GitHub Desktop.
Steam Generate Gametable

Paste the content of generateJson.js into the browser console when you are on your guide page. Format like https://steamcommunity.com/sharedfiles/manageguide/?id=xyz The uploaded images must have their appid as filename.

Files named 1 through 5 will be used to display rating

Copy the resulting json into a text file called definition.json and run generateTable.ts with deno. It will write its output to guide.txt which you then can put into your guide.

result = {};
result.games = [];
result.rating = {};
for (const entry of document.getElementById("sortable_previews").children) {
if (entry.nodeName !== "DIV") {
continue;
}
const appid = parseInt(entry.children[1].children[0].title.split(".")[0]);
if (isNaN(appid)) {
continue;
}
const previewImg = entry.id.split("_")[1];
if (appid <= 5) {
result.rating[appid] = previewImg;
} else {
result.games.push({
appid: appid,
previewImg: previewImg,
story: 0,
gameplay: 0,
visual: 0,
soundtrack: 0,
extra: ""
});
}
}
console.log(result);
const definition: Definition = JSON.parse(Deno.readTextFileSync("definition.json"));
class Table {
private rows: TableRow[] = [];
private header: TableRow = new TableRow();
constructor(header: string[]) {
for (const headerString of header) {
this.header.add(headerString);
}
}
add(row: TableRow) {
this.rows.push(row);
}
toString(): string {
return "[table]\n" + this.header.toString("th") + "\n" + this.rows.map(e => e.toString("td")).join("\n") + "\n[/table]";
}
}
class TableRow {
private entries: string[] = [];
add(string: string) {
this.entries.push(string);
}
toString(code: string) {
return "[tr]\n\t" + this.entries.map(e => `[${code}]${e}[/${code}]`).join("\n\t") + "\n[/tr]";
}
}
class GameEntry {
private data: GameData;
constructor(data: GameData) {
this.data = data;
}
toTableRow(): TableRow {
const tr = new TableRow();
tr.add(`[previewimg=${this.data.previewImg};][/previewimg]`);
tr.add(`[url=https://store.steampowered.com/app/${this.data.appid}]Click[/url]`);
tr.add(Rating.toString(this.data.story));
tr.add(Rating.toString(this.data.gameplay));
tr.add(Rating.toString(this.data.visual));
tr.add(Rating.toString(this.data.soundtrack));
tr.add(this.data.extra);
return tr;
}
}
interface Definition {
games: GameData[];
rating: { [rating: string]: number }
}
interface GameData {
appid: number,
previewImg: number;
story: number;
gameplay: number;
visual: number;
soundtrack: number;
extra: string;
}
namespace Rating {
export function toString(rating: number): string {
if (rating === 0) {
return "UNRATED";
} else {
return `[previewimg=${definition.rating[rating.toString()]};][/previewimg]`;
}
}
}
const table = new Table(["Game         ", "Store", "Story", "Gameplay", "Visuals", "Soundtrack", "Extra"]);
for (const data of definition.games) {
const entry = new GameEntry(data);
table.add(entry.toTableRow());
}
Deno.writeTextFileSync("guide.txt", table.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment