forked from KrisDavie/alttptracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
36 lines (30 loc) · 959 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(function (window) {
'use strict';
window.buildString = "21003";
// based on https://github.com/medialize/URI.js/blob/gh-pages/src/URI.js
window.uri_query = memoize(function () {
var q, href = location.href + '',
qi = href.indexOf('?'),
hi = href.indexOf('#');
q = hi >= 0 ? href.substring(0, hi) : href;
q = qi >= 0 ? href.substring(qi) : '';
// clean out leading question, trim amps, and consecutive amps
return q.replace(/&+/g, '&').replace(/^\?*&*|&+$/g, '')
.split('&').reduce(function (items, param) {
var name, value,
v = param.split('=', 2);
name = decodeURIComponent(v.shift());
value = v[0] ? decodeURIComponent(v.shift()) : true;
items[name] = value;
return items;
}, {});
});
function memoize(func) {
var memoized = function (value) {
var cache = memoized._cache;
return cache[value] || (cache[value] = func(value));
};
memoized._cache = {};
return memoized;
};
}(window));