Undo unrelated style changes.

This should be done in another PR :P
master
Pi-Hsun Shih 5 years ago
parent fb7fbe55e3
commit 9aca6465c2

@ -1,14 +1,14 @@
//Reusable Fields //Reusable Fields
const getSellFields = function () { const getSellFields = function () {
let fields = []; let fields = []
for (var i = 2; i < 14; i++) { for (var i = 2; i < 14; i++) {
fields.push($("#sell_" + i)[0]); fields.push($("#sell_" + i)[0])
} }
return fields; return fields
}; }
const sell_inputs = getSellFields(); const sell_inputs = getSellFields()
const buy_input = $("#buy"); const buy_input = $("#buy")
const first_buy_field = $("#first_buy"); const first_buy_field = $("#first_buy");
//Functions //Functions
@ -16,9 +16,9 @@ const fillFields = function (prices, first_buy) {
first_buy_field.prop("checked", first_buy); first_buy_field.prop("checked", first_buy);
buy_input.focus(); buy_input.focus();
buy_input.val(prices[0] || ''); buy_input.val(prices[0] || '')
buy_input.blur(); buy_input.blur();
const sell_prices = prices.slice(2); const sell_prices = prices.slice(2)
sell_prices.forEach((price, index) => { sell_prices.forEach((price, index) => {
if (!price) { if (!price) {
@ -30,16 +30,16 @@ const fillFields = function (prices, first_buy) {
element.blur(); element.blur();
} }
}) })
}; }
const initialize = function () { const initialize = function () {
try { try {
const prices = getPrices(); const prices = getPrices()
const first_buy = getFirstBuyState(); const first_buy = getFirstBuyState();
if (prices === null) { if (prices === null) {
fillFields([], first_buy); fillFields([], first_buy)
} else { } else {
fillFields(prices, first_buy); fillFields(prices, first_buy)
} }
$(document).trigger("input"); $(document).trigger("input");
} catch (e) { } catch (e) {
@ -50,22 +50,22 @@ const initialize = function () {
first_buy_field.prop('checked', false); first_buy_field.prop('checked', false);
$("input").val(null).trigger("input"); $("input").val(null).trigger("input");
}) })
}; }
const updateLocalStorage = function (prices, first_buy) { const updateLocalStorage = function (prices, first_buy) {
try { try {
if (prices.length !== 14) throw "The data array needs exactly 14 elements to be valid" if (prices.length !== 14) throw "The data array needs exactly 14 elements to be valid"
localStorage.setItem("sell_prices", JSON.stringify(prices)); localStorage.setItem("sell_prices", JSON.stringify(prices))
localStorage.setItem("first_buy", JSON.stringify(first_buy)); localStorage.setItem("first_buy", JSON.stringify(first_buy));
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}; }
const isEmpty = function (arr) { const isEmpty = function (arr) {
const filtered = arr.filter(value => value !== null && value !== '' && !isNaN(value)); const filtered = arr.filter(value => value !== null && value !== '' && !isNaN(value))
return filtered.length == 0; return filtered.length == 0
}; }
const getFirstBuyState = function () { const getFirstBuyState = function () {
return JSON.parse(localStorage.getItem('first_buy')); return JSON.parse(localStorage.getItem('first_buy'));
@ -109,8 +109,8 @@ const getSellPrices = function () {
//Checks all sell inputs and returns an array with their values //Checks all sell inputs and returns an array with their values
return res = sell_inputs.map(function (input) { return res = sell_inputs.map(function (input) {
return parseInt(input.value || ''); return parseInt(input.value || '');
}); })
}; }
const calculateOutput = function (data, first_buy) { const calculateOutput = function (data, first_buy) {
if (isEmpty(data)) { if (isEmpty(data)) {
@ -128,11 +128,11 @@ const calculateOutput = function (data, first_buy) {
} }
} }
out_line += `<td class="one">${poss.weekMin}</td><td class="one">${poss.weekMax}</td></tr>`; out_line += `<td class="one">${poss.weekMin}</td><td class="one">${poss.weekMax}</td></tr>`;
output_possibilities += out_line; output_possibilities += out_line
} }
$("#output").html(output_possibilities); $("#output").html(output_possibilities)
}; }
const update = function () { const update = function () {
const sell_prices = getSellPrices(); const sell_prices = getSellPrices();
@ -142,12 +142,11 @@ const update = function () {
buy_input.prop('disabled', first_buy); buy_input.prop('disabled', first_buy);
const prices = [buy_price, buy_price, ...sell_prices]; const prices = [buy_price, buy_price, ...sell_prices];
if (!window.price_from_query) { if (!window.price_from_query) {
updateLocalStorage(prices, first_buy); updateLocalStorage(prices, first_buy);
} }
calculateOutput(prices, first_buy); calculateOutput(prices, first_buy);
}; }
$(document).ready(initialize); $(document).ready(initialize);
$(document).on("input", update); $(document).on("input", update);

Loading…
Cancel
Save