Merge pull request #7 from na-ji/feat/local-storage-saving

Add saving of prices on local storage
master
Mike Bryant 4 years ago committed by GitHub
commit 014adefc25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -522,6 +522,42 @@ function* generate_possibilities(sell_prices) {
yield* generate_pattern_3(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() { $(document).on("input", function() {
// Update output on any input change // Update output on any input change
@ -532,6 +568,14 @@ $(document).on("input", function() {
sell_prices.push(parseInt($("#sell_" + i).val())); 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 = ""; var output_possibilities = "";
for (let poss of generate_possibilities(sell_prices)) { for (let poss of generate_possibilities(sell_prices)) {
var out_line = "<tr><td>" + poss.pattern_description + "</td>" var out_line = "<tr><td>" + poss.pattern_description + "</td>"

Loading…
Cancel
Save