Change from hash to query string.

master
Pi-Hsun Shih 5 years ago
parent 02d600e62d
commit adc538b3ff

@ -8,8 +8,8 @@ function get_prices_from_localstorage() {
return sell_prices;
}
function get_prices_from_hash() {
const params = new URLSearchParams(window.location.hash.substr(1));
function get_prices_from_query() {
const params = new URLSearchParams(window.location.search.substr(1));
const sell_prices = params.get("prices").split(".").map((x) => parseInt(x, 10));
if (!Array.isArray(sell_prices) || sell_prices.length !== 14) {
@ -22,7 +22,7 @@ function get_prices_from_hash() {
$(document).ready(function () {
try {
// load sell_prices from URL hash first, then local storage
const sell_prices = get_prices_from_hash() || get_prices_from_localstorage();
const sell_prices = get_prices_from_query() || get_prices_from_localstorage();
if (sell_prices == null) {
return;
@ -71,7 +71,8 @@ $(document).on("input", function() {
localStorage.setItem("sell_prices", JSON.stringify(sell_prices));
const params = {"prices": sell_prices.map((x) => isNaN(x) ? "" : x).join(".")};
window.location.hash = (new URLSearchParams(params)).toString();
const query_string = `?${new URLSearchParams(params).toString()}`;
window.history.replaceState(null, null, query_string);
const is_empty = sell_prices.every(sell_price => !sell_price);
if (is_empty) {

Loading…
Cancel
Save