Added parameters first-time and previous-pattern.

Added text box to notify that values will not be saved.

Valid first-time options are:
yes/true/1
no/false/0.

Valid first-time options are:
0/fluctuating
1/large-spike
2/decreasing
3/small-spike
anything else defaults to unknown.

Test with:
https://turnipprophet.io/?pattern=large-spike&prices=90.91..93.94..&first=true
master
Blake Felt 4 years ago
parent 8afadbddeb
commit a62a86235c

@ -273,6 +273,13 @@
<p>This app is still in development, but will improve over time!</p>
</div>
<div class="dialog-box" id="from_query" style="visibility: hidden;">
<h2 class="dialog-box__name">Daisy Mae</h2>
<p>I see you are have entered some parameters.
I will not save any changes for now.
</p>
</div>
<div class="dialog-box">
<h2 class="dialog-box__name">Daisy Mae</h2>
<p>

@ -65,9 +65,10 @@ const fillFields = function (prices, first_buy, previous_pattern) {
const initialize = function () {
try {
const prices = getPrices()
const first_buy = getFirstBuyState();
const previous_pattern = getPreviousPatternState();
const previous = getPrevious();
const first_buy = previous[0];
const previous_pattern = previous[1];
const prices = previous[2];
if (prices === null) {
fillFields([], first_buy, previous_pattern)
} else {
@ -101,14 +102,65 @@ const isEmpty = function (arr) {
return filtered.length == 0
}
const getFirstBuyState = function () {
const getFirstBuyStateFromQuery = function (param) {
try {
const params = new URLSearchParams(window.location.search.substr(1));
const firstbuy_str = params.get(param);
if (firstbuy_str == null) {
return null;
}
firstbuy = null;
if (firstbuy_str == "1" || firstbuy_str == "yes" || firstbuy_str == "true") {
firstbuy = true;
} else if (firstbuy_str == "0" || firstbuy_str == "no" || firstbuy_str == "false") {
firstbuy = false;
}
return firstbuy;
} catch (e) {
return null;
}
}
const getFirstBuyStateFromLocalstorage = function () {
return JSON.parse(localStorage.getItem('first_buy'))
}
const getPreviousPatternState = function () {
const getPreviousPatternStateFromLocalstorage = function () {
return JSON.parse(localStorage.getItem('previous_pattern'))
}
const getPreviousPatternStateFromQuery = function (param) {
try {
const params = new URLSearchParams(window.location.search.substr(1));
const pattern_str = params.get(param);
if (pattern_str == null) {
return null;
}
if (pattern_str == "0" || pattern_str == "fluctuating") {
pattern = 0;
} else if (pattern_str == "1" || pattern_str == "large-spike") {
pattern = 1;
} else if (pattern_str == "2" || pattern_str == "decreasing") {
pattern = 2;
} else if (pattern_str == "3" || pattern_str == "small-spike") {
pattern = 3;
} else {
pattern = -1;
}
return pattern;
} catch (e) {
return null;
}
}
const getPricesFromLocalstorage = function () {
try {
const sell_prices = JSON.parse(localStorage.getItem("sell_prices"));
@ -123,10 +175,10 @@ const getPricesFromLocalstorage = function () {
}
};
const getPricesFromQuery = function () {
const getPricesFromQuery = function (param) {
try {
const params = new URLSearchParams(window.location.search.substr(1));
const sell_prices = params.get("prices").split(".").map((x) => parseInt(x, 10));
const sell_prices = params.get(param).split(".").map((x) => parseInt(x, 10));
if (!Array.isArray(sell_prices)) {
return null;
@ -141,15 +193,52 @@ const getPricesFromQuery = function () {
sell_prices.push(0);
}
window.price_from_query = true;
return sell_prices;
} catch (e) {
return null;
}
};
const getPrices = function () {
return getPricesFromQuery() || getPricesFromLocalstorage();
const getPreviousFromQuery = function () {
const queries = [
["first", getFirstBuyStateFromQuery],
["pattern", getPreviousPatternStateFromQuery],
["prices", getPricesFromQuery]
];
found = null; /* value to save if we found any parameters */
ret = [];
for (q of queries) {
val = q[1](q[0]); /* run the function with the parameter */
found = found || val;
ret.push(val);
}
if (found != null) { /* if we found any parameter */
window.from_query = true;
document.getElementById("from_query").style.visibility = "visible";
return ret;
}
return null;
};
const getPreviousFromLocalstorage = function () {
return [
getFirstBuyStateFromLocalstorage(),
getPreviousPatternStateFromQuery(),
getPricesFromLocalstorage()
];
};
/**
* Gets previous values. First tries to parse parameters,
* if none of them match then it looks in local storage.
* @return {[first time, previous pattern, prices]}
*/
const getPrevious = function () {
return getPreviousFromQuery() || getPreviousFromLocalstorage();
};
const getSellPrices = function () {
@ -187,13 +276,13 @@ const update = function () {
const buy_price = parseInt(buy_input.val());
const first_buy = getCheckedRadio(first_buy_radios) == 'true';
const previous_pattern = parseInt(getCheckedRadio(previous_pattern_radios));
buy_input[0].disabled = first_buy;
buy_input[0].placeholder = first_buy ? '—' : '...'
const prices = [buy_price, buy_price, ...sell_prices];
if (!window.price_from_query) {
if (!window.from_query) {
updateLocalStorage(prices, first_buy, previous_pattern);
}

Loading…
Cancel
Save