Skip to content

Instantly share code, notes, and snippets.

@DaniilVysotskiy
Created April 21, 2020 15:02
Show Gist options
  • Save DaniilVysotskiy/65d7ae0821be2eee632e8feb5e71988e to your computer and use it in GitHub Desktop.
Save DaniilVysotskiy/65d7ae0821be2eee632e8feb5e71988e to your computer and use it in GitHub Desktop.
turnip.exchange best price opener
var blacklistTurnipCodes = ["40c4f327","c43c1e1a","74764c4f","56eca733","19b10f08"];
var stopWords = ["nmt","nugget","star","nook mile","diy","furniture","gold","rocket","flower"];
var includesStopWord = (str) => {
return stopWords.some(word => str.toLowerCase().includes(word));
};
var fetchIslands = () => {
fetch("https://api.turnip.exchange/islands/", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => {
return response.json();
}).then(result => {
const islands = result.islands.sort((a, b) => b.turnipPrice - a.turnipPrice).filter(island => {
return (blacklistTurnipCodes.includes(island.turnipCode) || includesStopWord(island.description)) ? false : true;
});
const bestPriceIsland = islands[0];
switch (true) {
case (bestPriceIsland.turnipPrice >= 500 && bestPriceIsland.turnipPrice < 600):
console.log('%c%s [%s]', 'color: green; font: 1.2rem/1 Tahoma;', bestPriceIsland.turnipPrice.toString(), bestPriceIsland.turnipCode);
break;
case (bestPriceIsland.turnipPrice >= 608):
console.log('%c%s [%s]', 'color: red; font: 1.2rem/1 Tahoma;', bestPriceIsland.turnipPrice.toString(), bestPriceIsland.turnipCode) ;
window.open(`https://turnip.exchange/island/${bestPriceIsland.turnipCode}`, '_blank');
clearInterval(interval);
break;
default:
console.log('%s [%s]', bestPriceIsland.turnipPrice, bestPriceIsland.turnipCode);
break;
}
});
}
var interval = setInterval(fetchIslands, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment