Last active
February 11, 2018 18:00
-
-
Save burdiuz/6032471666f476c1c49204c6605e7fac to your computer and use it in GitHub Desktop.
Script that allows to create trades from all unused games ion your IndieGala account, trades for any other game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Login to your IndieGala accountand launch this script in console. | |
It asks to trade for any game. | |
*/ | |
((window, document) => { | |
let alertsCount = 0; | |
const alert = (content) => { | |
console.warn('Alert:', content); | |
alertsCount++; | |
}; | |
const wasAlerted = () => !!alertsCount; | |
const resetAlerted = () => alertsCount = 0; | |
const waitUntil = (condition) => new Promise((resolve) => { | |
const id = setInterval(() => { | |
const result = condition(); | |
if (result) { | |
clearInterval(id); | |
resolve(result); | |
} | |
}, 250); | |
}); | |
const getSection = () => $('.accordion-toggle[href="#collapseTrades"]'); | |
const getCollapsedSection = () => $('.accordion-toggle.collapsed[href="#collapseTrades"]'); | |
const getFormBtn = () => $('a.open-new-trade-form'); | |
const getFormContainer = () => $('div.new-trade-profile-cont'); | |
const getTradeTitleInput = () => $('input.trade_title'); | |
const getLoadBundlesBtn = () => getFormContainer().find('.btn-get-owned-games-list[rel="bundle"]'); | |
const getFirstSelectItem = () => $('#owned-games-list li:not(:has(.btn-add-rel-game.disabled)):has(.btn-add-rel-game[disabled!="disabled"]):first'); | |
const getFirstSelectBtn = () => getFirstSelectItem().find('.btn-add-rel-game'); | |
const getFirstSelectTitle = () => getFirstSelectItem().find('.game-title'); | |
const getSelectItem = (i) => $('#owned-games-list li:nth-child('+i+')'); | |
const getSelectBtn = (i) => getSelectItem(i).find('.btn-add-rel-game'); | |
const getSelectTitle = (i) => getSelectItem(i).find('.game-title'); | |
let index = 0; | |
const nextSelectItem = () => { | |
console.log('next index: ', ++index); | |
}; | |
const getCurrentSelectItem = (i) => getSelectItem(index); | |
const getCurrentSelectBtn = (i) => getSelectBtn(index); | |
const getCurrentSelectTitle = (i) => getSelectTitle(index); | |
const getDescrField = () => $('textarea.trade_description'); | |
const getTTLSelect = () => $('select.trade_life'); | |
const getSaveBtn = () => $('.btn-save-new-trade'); | |
const getReceiveContainer = () => $('div.row:has(span:contains("STEP 4"))'); | |
const getReceiveInput = () => getReceiveContainer().find('input'); | |
const getReceiveBtn = () => getReceiveContainer().find('.btn-retrive-game-data'); | |
const getReceiveTitle = () => getReceiveContainer().find('.game-title'); | |
const getReceiveConfirmBtn = () => getReceiveContainer().find('.btn-add-rel-game'); | |
const openSection = () => { | |
!getCollapsedSection().length && getSection().click(); | |
getCollapsedSection().length && getCollapsedSection().click(); | |
}; | |
const expandForm = () => { | |
if (getFormContainer().css('display') === 'none') { | |
getFormBtn().click(); | |
} | |
}; | |
const prepareTrade = () => { | |
!getFirstSelectItem().length && getLoadBundlesBtn().click(); | |
getReceiveInput().val('http://store.steampowered.com/app/304930'); | |
getReceiveBtn().click(); | |
getTradeTitleInput().val('For any game I DONT HAVE of comparable value'); | |
getDescrField().val('*Note*: Requested game is just a placeholder. \nWill trade FOR ANY GAME I DO NOT HAVE OF COMPARABLE VALUE. \nSteam only. \nGames I have you can find here: http://steamcommunity.com/id/a_w/games/?tab=all'); | |
return waitUntil(() => (getFirstSelectItem().length && getReceiveTitle().length)) | |
.then(() => { | |
getReceiveConfirmBtn().click(); | |
getTTLSelect().val('7'); | |
sendTrade(); | |
}); | |
}; | |
const sendTrade = () => { | |
/* | |
getFirstSelectBtn().click(); | |
getTradeTitleInput().val('"' + getFirstSelectTitle().text() + '" for any game I don\'t have of comparable value.'); | |
*/ | |
getCurrentSelectBtn().click(); | |
setTimeout(() => getSaveBtn().click(), 100); | |
}; | |
const waitTradeToFinish = () => waitUntil(() => (wasAlerted() || getFormContainer().css('display') === 'none')) | |
.then(() => { | |
sendTradeQueue(wasAlerted()); | |
}); | |
const sendTradeQueue = (shortTrade) => { | |
expandForm(); | |
nextSelectItem(); | |
resetAlerted(); | |
if(shortTrade) { | |
$('#selected-owned-game .selected-rel-game-row .btn-remove-selected-rel-game').each((i, item) => item.click()); | |
sendTrade(); | |
waitTradeToFinish(); | |
} else { | |
prepareTrade() | |
.then(waitTradeToFinish); | |
} | |
}; | |
window.alert = alert; | |
openSection(); | |
sendTradeQueue(); | |
})(window, document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('input.input-block-level.keys') | |
.each((i,element) => { | |
element.style.cursor = 'pointer'; | |
}).click((e) => { | |
const element = e.target; | |
e.preventDefault(); | |
e.stopImmediatePropagation(); | |
window.open(`https://store.steampowered.com/account/registerkey?key=${element.value}`); | |
element.style.backgroundColor = '#aaaaaa'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment