You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ac-nh-turnip-prices/js/scripts.js

75 lines
1.8 KiB
JavaScript

$(document).ready(function () {
// load sell_prices from local storage
try {
const sell_prices = JSON.parse(localStorage.getItem("sell_prices"));
if (!Array.isArray(sell_prices) || sell_prices.length !== 14) {
return;
}
sell_prices.forEach((sell_price, index) => {
if (!sell_price) {
return;
}
const buyInput = $("#buy");
if (index === 0) {
buyInput.focus();
buyInput.val(sell_price);
buyInput.blur();
return;
}
const element = $("#sell_" + index);
if (element.length) {
element.focus();
element.val(sell_price);
element.blur();
}
});
$(document).trigger("input");
} catch (e) {
console.error(e);
}
$("#reset").on("click", function() {
$("input").val(null).trigger("input");
})
});
$(document).on("input", function() {
// Update output on any input change
var buy_price = parseInt($("#buy").val());
var sell_prices = [buy_price, buy_price];
for (var i = 2; i < 14; i++) {
sell_prices.push(parseInt($("#sell_" + i).val()));
}
localStorage.setItem("sell_prices", JSON.stringify(sell_prices));
const is_empty = sell_prices.every(sell_price => !sell_price);
if (is_empty) {
$("#output").html("");
return;
}
let output_possibilities = "";
for (let poss of analyze_possibilities(sell_prices)) {
var out_line = "<tr><td>" + poss.pattern_description + "</td>"
for (let day of poss.prices.slice(1)) {
if (day.min !== day.max) {
out_line += `<td>${day.min}..${day.max}</td>`;
} else {
out_line += `<td class="one">${day.min}</td>`;
}
}
out_line += `<td class="one">${poss.weekMin}</td><td class="one">${poss.weekMax}</td></tr>`;
output_possibilities += out_line
}
$("#output").html(output_possibilities)
});