Skip to content

Instantly share code, notes, and snippets.

@Humberd
Last active February 15, 2019 19:58
Show Gist options
  • Save Humberd/11485740eae64078b0685e47f0cf561c to your computer and use it in GitHub Desktop.
Save Humberd/11485740eae64078b0685e47f0cf561c to your computer and use it in GitHub Desktop.
Paste this script directly in the URL of your erepublik tab and you will be redirected to one of the active love boosted AIR battles. If it finds nothing it will retry by itself in 10 seconds.
javascript:async function loop() { async function getBattles() { const response = await fetch( 'https://www.erepublik.com/en/military/campaigns-new/'); const data = await response.json(); const battleIds = Object.keys(data.battles); const airBattleIds = battleIds.filter( it => data.battles[it].type === 'aircraft', ); return airBattleIds; } async function hasLoveBoost(battleId) { const response = await fetch( `https://www.erepublik.com/en/military/nbp-stats/${battleId}/4`); const data = await response.json(); return data.battleEffects.valentinesDay.is_active; } function printLinks(battleId) { return `https://www.erepublik.com/en/military/battlefield/${battleId}`; } console.log('Loop triggered'); const battles = await getBattles(); const results = await Promise.all(battles.map(hasLoveBoost)); const boostedBattles = results.map((val, index) => { if (val) { return battles[index]; } return val; }) .filter(it => it) .map(printLinks); if (boostedBattles.length > 0) { location.replace(boostedBattles[0]); } console.log(boostedBattles); } loop(); setInterval(loop, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment