add saving of prices on local storage

add loading of prices from local storage on page load
add a reset button to clear the form

close #2
master
Naji Astier 4 years ago
parent a7acb18b32
commit e4b31bd3d6
No known key found for this signature in database
GPG Key ID: A6C58B00E7C468F6

@ -111,6 +111,7 @@
<input type="number" id="sell_13">
</label>
</p>
<button id="reset">Reset</button>
</form>
<p>

@ -522,6 +522,42 @@ function* generate_possibilities(sell_prices) {
yield* generate_pattern_3(sell_prices);
}
$(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;
}
if (index === 0) {
$("#buy").val(sell_price);
return;
}
const element = $("#sell_" + index);
if (element.length) {
element.val(sell_price);
}
});
$(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
@ -532,6 +568,14 @@ $(document).on("input", function() {
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;
}
var output_possibilities = "";
for (let poss of generate_possibilities(sell_prices)) {
var out_line = "<tr><td>" + poss.pattern_description + "</td>"

Loading…
Cancel
Save