JSFiddle - React, Tailwind, and code Playground
by andypotanin
JavaScript
// should be "window.location.search"
var _url = "?wpp_search%5Bpagination%5D=on&wpp_search%5Bper_page%5D=10&wpp_search%5Bstrict_search%5D=false&wpp_search%5Bproperty_type%5D=rent%2Csale&wpp_search%5Brandom_75%5D=-1&wpp_search%5Bbedrooms%5D%5Bmin%5D=1&wpp_search%5Bbedrooms%5D%5Bmax%5D=3&wpp_search%5Bbathrooms%5D%5Bmin%5D=&wpp_search%5Bbathrooms%5D%5Bmax%5D=&wpp_search%5Bprice%5D%5Bmin%5D=&wpp_search%5Bprice%5D%5Bmax%5D=&wpp_search%5Bneighborhood%5D=-1&fuck=you"
function getJsonFromUrl(_url) {
function QueryData(_1, _2) {
if (_1 == undefined) {
_1 = location.search ? location.search : "";
}
if (_1.charAt(0) == "?") {
_1 = _1.substring(1);
}
if (_1.length > 0) {
_1 = _1.replace(/\+/g, " ");
var _3 = _1.split(/[&;]/g);
for (var _4 = 0; _4 < _3.length; _4++) {
var _5 = _3[_4].split("=");
var _6 = decodeURIComponent(_5[0]);
var _7 = _5.length > 1 ? decodeURIComponent(_5[1]) : "";
if (_2) {
if (!(_6 in this)) {
this[_6] = [];
}
this[_6].push(_7);
} else {
this[_6] = _7;
}
}
}
};
var getData = new QueryData(_url || window.location.search, true);
return getData;
}
console.clear();
console.log(getJsonFromUrl(_url));