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

Loading…
Cancel
Save