Skip to content

Instantly share code, notes, and snippets.

@zencd
Last active May 22, 2024 20:55
Show Gist options
  • Save zencd/adc261db3f7ad36863766c9ed2a5e00c to your computer and use it in GitHub Desktop.
Save zencd/adc261db3f7ad36863766c9ed2a5e00c to your computer and use it in GitHub Desktop.
Copy steam games to an SG compilation
await (async function() {
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
async function rewriteAllGames(compId, gameIds) {
console.log('gameIds:', gameIds);
var formData = new FormData();
for (let i = 0; i < gameIds.length; i++) {
let gameId = gameIds[i];
formData.append('items[]', 'game/' + gameId);
formData.append('order[game/'+gameId+']', '' + i);
}
var resp = await fetch('https://stopgame.ru/ajax/collections/save-items/' + compId, {method: 'POST', body: formData});
if (resp.status !== 200) {
console.error('Не получилось перезаписать игры', resp);
let text = await resp.text();
console.error('text: ' + text);
}
}
function resolveGame(searchRes) {
if (!searchRes) return null;
let results = searchRes['results'];
if (!results) return null;
for (var i = 0; i < results.length; i++) {
let item = results[i];
if (item['type'] === 'game') {
return item
}
}
return null;
}
var m = document.location.href.match(/\/compilation\/(\d+)/);
if (!m) return;
var compId = m[1]; // like '1234'
var res = prompt('Вставьте текст CSV-файла', '');
var rows = res.split('\n');
var rowCnt = -1;
var gameIds = [];
for (var i = 0; i < rows.length; i++) {
rowCnt++;
var cells = rows[i].split(',');
if (cells.length < 1 || cells[0] === 'game') continue;
var title = cells[0].replace(/[^0-9a-zA-Zа-яА-ЯёЁ _-]+/g, '').trim();
var resp = await fetch('https://stopgame.ru/ajax/search/games/?term=' + encodeURIComponent(title));
if (resp.status !== 200) {
console.error('Не удалось найти игру: ' + title, resp);
continue;
}
var searchRes = await resp.json();
let game = resolveGame(searchRes);
if (!game) {
console.error('Не удалось найти игру: ' + title, resp);
continue;
}
let gameId = game['id']
let titleFound = game['title']
console.log(`${rowCnt}/${rows.length} ${title} => ${titleFound} #${gameId}`);
gameIds.push(gameId);
await new Promise(r => setTimeout(r, getRandomInt(1000, 3000)));
}
console.log('Перезаписываю все игры: ' + gameIds.length);
rewriteAllGames(compId, gameIds);
console.log('Готово. Можно сохранить лог и/или обновить страницу');
})();
@zencd
Copy link
Author

zencd commented May 22, 2024

Скрипт копирует игры из своей коллекции Steam в подборку на Стопгейме. Проверено на Windows 10 + Chrome, на 280 играх.

Получаем список игр со стима:

  • Убедиться что профиль стима публично доступен
  • Как узнать адрес своего стим-профиля:
    • в стиме ткнуть на свой юзернейм, там будет «Мой профиль», выглядит эта ссылка примерно так: https :// steamcommunity . com/profiles/11111111111/
  • Пройти на https://www.lorenzostanco.com/lab/steam/
  • Вставить ссылку на свой стим-профиль
  • Нажать «load library»
  • Нажать «export to csv»
  • Выскочит диалог, ещё раз нажать «export to csv»
  • Скачанный файл CSV открыть в блокноте (не в экселе)

Добавляем их на СГ:

  • На ПК залогиниться на СГ
  • Создать НОВУЮ подборку, т. к. то что там было очистится
  • Перейти в подборку, в адресной строке должно быть что-то типа https :// stopgame . ru/games/compilation/1111
  • Нажать Ctrl+Shift+I, откроется панелька
  • В ней перейти на вкладку Console (Консоль)
  • Скопировать текст скрипта https://gist.github.com/zencd/adc261db3f7ad36863766c9ed2a5e00c
  • Вставить его в консоль: Ctrl+V, Enter
  • Если попросят вбить команду «allow pasting» — сделать это, и повторить пред. пункт
  • Выскочит диалог с полем ввода, туда скопировать текст CSV, энтер
  • Скрипт начинает работать, прогресс работы отображается

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