let vote = {"72":["534380","1245620","1332010","1593500","1938090"],"73":["1592190","1659040","1782330","1849900","1987080"],"74":["570","108600","275850","548430","1091500"],"75":["648800","1144200","1446780","1818750","1938090"],"76":["698670","1063660","1313140","1817190","1954200"],"77":["261550","1167630","1332010","1533420","1637320"],"78":["493520","529340","1142710","1245620","1811260"],"79":["1061910","1237320","1462040","1687950","1761390"],"80":["1182900","1593500","1659420","1703340","1817070"],"81":["920210","1290000","1401590","1455840","1657630"],"82":["1449850","1794680","1850570","1942280","1997040"]};
let sha1 = (login, cb) => window.crypto.subtle.digest({name: "SHA-1"}, new Uint8Array(login.match(/.{1}/g).map(s => s.charCodeAt()))).then(result => cb([...new Uint8Array(result)].map(n => n.toString(16)).join(''))),
chrome_id = `${chrome.runtime.id}_id`;
chrome.runtime.sendMessage('getAccs', accs => {
let steamawards = (ids, cb) => {
if(ids.length){
let id = ids.shift(),
acc = accs.find(acc => acc.id == id);
console.log(acc.login);
console.log(`${accs.length - ids.length} of ${accs.length}`);
req('get', 'https://store.steampowered.com/steamawards/', null, {[chrome_id]: id}).done(data => {
let sessionid = data.match(/var g_sessionID = "([a-f0-9]{24})";/);
sessionid = sessionid && sessionid[1];
if(sessionid){
let salevote = voteids => {
if(voteids.length){
let voteid = voteids.shift();
req('post', 'https://store.steampowered.com/salevote', {
sessionid, voteid, appid: vote[voteid][Math.floor(Math.random() * 4)], developerid: 0
}, {[chrome_id]: id}).done(() => {
salevote(voteids);
}).fail(() => {
setTimeout(() => salevote([...voteids, voteid]), Math.floor(Math.random() * 5000));
});
}else{
setTimeout(() => steamawards(ids, cb), Math.floor(Math.random() * 3000));
}
};
salevote(Object.keys(vote));
}else{
setTimeout(() => steamawards(ids, cb), Math.floor(Math.random() * 3000));
}
}).fail(() => {
if(acc.err++ < 5){
setTimeout(() => steamawards(ids.concat(id), cb), Math.floor(Math.random() * 5000));
}else{
setTimeout(() => steamawards(ids, cb), Math.floor(Math.random() * 5000));
}
});
}else{
cb();
}
};
let ids = [];
for(let acc of accs){
sha1(acc.login, id => {
ids.push(id);
acc.id = id;
acc.err = 0;
if(accs.length == ids.length){
steamawards(ids, () => console.log(true));
}
})
}
});