|
|
|
@ -1,14 +1,14 @@
|
|
|
|
|
//Reusable Fields
|
|
|
|
|
const getSellFields = function () {
|
|
|
|
|
let fields = [];
|
|
|
|
|
let fields = []
|
|
|
|
|
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 buy_input = $("#buy");
|
|
|
|
|
const sell_inputs = getSellFields()
|
|
|
|
|
const buy_input = $("#buy")
|
|
|
|
|
const first_buy_field = $("#first_buy");
|
|
|
|
|
|
|
|
|
|
//Functions
|
|
|
|
@ -16,9 +16,9 @@ const fillFields = function (prices, first_buy) {
|
|
|
|
|
first_buy_field.prop("checked", first_buy);
|
|
|
|
|
|
|
|
|
|
buy_input.focus();
|
|
|
|
|
buy_input.val(prices[0] || '');
|
|
|
|
|
buy_input.val(prices[0] || '')
|
|
|
|
|
buy_input.blur();
|
|
|
|
|
const sell_prices = prices.slice(2);
|
|
|
|
|
const sell_prices = prices.slice(2)
|
|
|
|
|
|
|
|
|
|
sell_prices.forEach((price, index) => {
|
|
|
|
|
if (!price) {
|
|
|
|
@ -30,16 +30,16 @@ const fillFields = function (prices, first_buy) {
|
|
|
|
|
element.blur();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initialize = function () {
|
|
|
|
|
try {
|
|
|
|
|
const prices = getPrices();
|
|
|
|
|
const prices = getPrices()
|
|
|
|
|
const first_buy = getFirstBuyState();
|
|
|
|
|
if (prices === null) {
|
|
|
|
|
fillFields([], first_buy);
|
|
|
|
|
fillFields([], first_buy)
|
|
|
|
|
} else {
|
|
|
|
|
fillFields(prices, first_buy);
|
|
|
|
|
fillFields(prices, first_buy)
|
|
|
|
|
}
|
|
|
|
|
$(document).trigger("input");
|
|
|
|
|
} catch (e) {
|
|
|
|
@ -50,22 +50,22 @@ const initialize = function () {
|
|
|
|
|
first_buy_field.prop('checked', false);
|
|
|
|
|
$("input").val(null).trigger("input");
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const updateLocalStorage = function (prices, first_buy) {
|
|
|
|
|
try {
|
|
|
|
|
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));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isEmpty = function (arr) {
|
|
|
|
|
const filtered = arr.filter(value => value !== null && value !== '' && !isNaN(value));
|
|
|
|
|
return filtered.length == 0;
|
|
|
|
|
};
|
|
|
|
|
const filtered = arr.filter(value => value !== null && value !== '' && !isNaN(value))
|
|
|
|
|
return filtered.length == 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getFirstBuyState = function () {
|
|
|
|
|
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
|
|
|
|
|
return res = sell_inputs.map(function (input) {
|
|
|
|
|
return parseInt(input.value || '');
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const calculateOutput = function (data, first_buy) {
|
|
|
|
|
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>`;
|
|
|
|
|
output_possibilities += out_line;
|
|
|
|
|
output_possibilities += out_line
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#output").html(output_possibilities);
|
|
|
|
|
};
|
|
|
|
|
$("#output").html(output_possibilities)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const update = function () {
|
|
|
|
|
const sell_prices = getSellPrices();
|
|
|
|
@ -142,12 +142,11 @@ const update = function () {
|
|
|
|
|
buy_input.prop('disabled', first_buy);
|
|
|
|
|
|
|
|
|
|
const prices = [buy_price, buy_price, ...sell_prices];
|
|
|
|
|
|
|
|
|
|
if (!window.price_from_query) {
|
|
|
|
|
updateLocalStorage(prices, first_buy);
|
|
|
|
|
}
|
|
|
|
|
calculateOutput(prices, first_buy);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).ready(initialize);
|
|
|
|
|
$(document).on("input", update);
|
|
|
|
|