-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqs.js
37 lines (33 loc) · 999 Bytes
/
qs.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
37
(function(w, _cxApi) {
var noop = function() {};
var re = /^experiment=([\w-]+):(\d+)/;
var _cxApiObject = w["_cxApiObject"] || _cxApi;
var _cxApiProxy = w[_cxApiObject];
var params = (w.location.hash || w.location.search)
.replace(/.*\?/, "")
.split("&")
.reduce(function(result, param) {
var matches = param.match(re);
if (matches !== null) {
result[matches[1]] = parseInt(matches[2]);
}
return result;
}, {})
w[_cxApiObject] = function(experimentId, methodName, methodArgs, config, callback, errback) {
switch (methodName) {
case "getChosenVariation":
case "setChosenVariation":
case "chooseVariation":
try {
if (params.hasOwnProperty(experimentId)) {
(callback || noop)(params[experimentId]);
break;
}
} catch (e) {
(errback || noop)(e);
}
default:
_cxApiProxy.apply(this, arguments);
}
}
})(window, "_cxApi");