-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage-frame-1.18.html
More file actions
282 lines (231 loc) · 10 KB
/
storage-frame-1.18.html
File metadata and controls
282 lines (231 loc) · 10 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<!-- saved from url=(0114)https://z15ba20153.webengage.co/storage-frame-1.18.htm?cdn=y&cbf=webengage-engagement-callback-frame&lc=~15ba20153 -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><meta http-equiv="x-ua-compatible" content="IE=Edge"><script>// Storage frame simply stores whatever data is given to it as localStorage[name] = value
// or returns the data again as event.data.name, event.data.value pairs
(function (window, document) {
// gzip flag
var isGzip = false;
// ** helper routines
function getParamValue (paramName) {
var paramValue = '';
var regex = new RegExp('[\\?&]' + paramName + '=([^&#]*)');
var qs = regex.exec(location.href);
if (qs !== null) {
paramValue = qs[1];
}
return paramValue;
}
function bind (element, event, listener) {
if (element.addEventListener) {
element.addEventListener(event, listener);
} else if (element.attachEvent) {
element.attachEvent('on' + event, listener);
}
}
function escapeForRegExp (text) {
return (text + '').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
function stringify (object) {
if (typeof(JSON) !== 'undefined' && typeof(JSON.stringify) === 'function') {
return JSON.stringify(object);
} else {
var type = typeof(object);
if (type !== 'undefined' && type !== 'function') {
if (type != 'object' || object === null) {
// simple data type
if (type == 'string') {
object = object.replace(/[\\]/g, '\\\\')
.replace(/[\"]/g, '\\\"')
.replace(/[\/]/g, '\\/')
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, '\\t');
object = '"' + object + '"';
}
return String(object);
} else {
var json, n, val;
if (typeof(object.toJSON) === 'function') {
return stringify(object.toJSON());
} else if (object.constructor == Array) {
json = [];
for (n = 0; n < object.length; n++) {
val = stringify(object[n]);
json.push(typeof(val) === 'undefined' ? 'null' : val);
}
return '[' + String(json) + ']';
} else {
json = [];
for (n in object) {
if (object.hasOwnProperty(n)) {
val = stringify(object[n]);
if (typeof(val) !== 'undefined') {
json.push(stringify(n) + ':' + val);
}
}
}
return '{' + String(json) + '}';
}
}
}
}
}
function detectLocalStorageSupport () {
try {
var _localStorageFlag = (typeof(Storage) !== 'undefined' && 'localStorage' in window && window.localStorage !== null);
if (_localStorageFlag) {
// for iOS tablet, even though it supports localStorage it throws QuotaExceedError
window.localStorage['_we_dm_ios_sup_f_'] = 'true';
window.localStorage.removeItem('_we_dm_ios_sup_f_');
}
return _localStorageFlag;
} catch (e) {
return false;
}
}
var CALLBACK_FRAME_NAME = getParamValue('cbf') || 'wkCBStorageFrame';
function postMessage (msg, name, value) {
if (window.parent.frames[CALLBACK_FRAME_NAME]) {
window.parent.frames[CALLBACK_FRAME_NAME].postMessage(stringify({
name : name,
msg : msg,
value : value
}), '*');
}
}
function init (vconfig) {
function isValidOrigin (origin) {
// checking domain validity
origin = origin.replace(/https?:\/\//, ''); // getting rid off the scheme
var flag = false;
var originHost = origin.split(":")[0];
var originPort = origin.split(":")[1];
var domains = [];
var regexps = [];
if (vconfig.sites === undefined || !vconfig.sites) {
vconfig.sites = {};
vconfig.sites[vconfig.domain] = 'DOMAIN';
}
for (var key in vconfig.sites) {
var _publisherDomain = key,
_publisherDomainPort;
if (vconfig.sites[key] == 'DOMAIN') {
domains[domains.length] = _publisherDomain;
if (_publisherDomain.match(/^www\./i)) {
_publisherDomain = _publisherDomain.substring(4, _publisherDomain.length);
}
if (_publisherDomain.match(/\:[\d]*$/)) {
_publisherDomainPort = _publisherDomain.substring(_publisherDomain.indexOf(':') + 1, _publisherDomain.length);
_publisherDomain = _publisherDomain.substring(0, _publisherDomain.indexOf(':'));
}
if ((originHost.match(new RegExp(escapeForRegExp(_publisherDomain) + '$', 'gi')) && (!_publisherDomainPort || _publisherDomainPort == originPort))) {
flag = true;
break;
}
} else if (vconfig.sites[key] == 'REGEXP') {
var matcherExp = _publisherDomain;
regexps[regexps.length] = _publisherDomain;
if ((origin.match(matcherExp))) {
flag = true;
break;
}
}
}
return flag;
}
var readKeys = {};
bind(window, 'message', function (event) {
event = event || this.event;
if (isValidOrigin(event.origin)) {
var name = event.data.name;
var value = event.data.value;
var action = event.data.action;
switch (action) {
case 'store':
localStorage.setItem(name, value);
// postMessage('update', name, localStorage[name]);
break;
case 'read':
readKeys[name] = true;
postMessage('new-data', name, localStorage[name]);
break;
case 'delete':
localStorage.removeItem(name);
break;
}
} else {
// TODO - send invalid request
}
});
// listen changes in localStorage values
bind(window, 'storage', function(event) {
if (readKeys.hasOwnProperty(event.key)) {
postMessage('update', event.key, event.newValue);
}
});
if (vconfig) {
postMessage('init', 'init', {
status: 'success',
webengage_fs_configurationMap: vconfig,
isGzip: isGzip
});
} else {
postMessage('init', 'init', {
status: 'failed'
});
}
}
var windowUnloading = false;
bind(window, 'beforeunload', function () {
windowUnloading = true;
});
bind(window, 'load', function () {
if (!detectLocalStorageSupport()) {
return init();
}
var vscript = document.createElement('script');
vscript.type = 'text/javascript';
vscript.charset = 'UTF-8';
var lc = getParamValue('lc');
let script = null
if (getParamValue('cdn') === 'y') {
script =`${location.protocol == 'http:' ? 'http:' : 'https:'}`+'//wsdk-files.webengage.com/webengage/' + lc + '/v4.js';
} else {
script = `${location.protocol == 'http:' ? 'http:' : 'https:'}`+'//s3.amazonaws.com/'
+ (isGzip ? 'webengage-zfiles' : 'webengage-files')
+ '/webengage/' + lc + '/v4.js?r=' + Math.floor((new Date()).getTime() / 60000);
}
if (getParamValue("proxyUrl")!==''){
vscript.src = `${getParamValue("proxyUrl")}?url=${encodeURIComponent(script)}`
}else{
vscript.src = script
}
vscript.onload = function(event) {
vscript.onreadystatechange = vscript.onload = null;
init(webengage_fs_configurationMap);
};
vscript.onerror = function (event) {
if (!windowUnloading) {
var im = new Image();
im.src = '//c.webengage.com/e.jpg?type=error'
+ '&event=' + encodeURIComponent('[sf] v4 loading failed')
+ '&category=' + lc
+ '&data=' + encodeURIComponent('{"version" : "4.0", "text" : "Failed to load config ' + vscript.src + '" }')
+ '&ts=' + (new Date()).getTime();
}
init();
};
vscript.onreadystatechange = function () {
if (vscript.readyState === 'loaded') {
vscript.onload && vscript.onload();
} else if (vscript.readyState === 'complete') {
setTimeout(function () {
vscript.onload && vscript.onload();
}, 2000);
}
};
document.body.appendChild(vscript);
});
})(window, document);</script></head><body marginwidth="0" marginheight="0"><script type="text/javascript" charset="UTF-8" src="./v4.js.download"></script></body></html>