-
Notifications
You must be signed in to change notification settings - Fork 45
/
onelink-smart-script-latest.js
2374 lines (2310 loc) · 94.8 KB
/
onelink-smart-script-latest.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* AF Smart Script (Build 2.9.2)
*/
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return _arrayLikeToArray(r);
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
var AF_URL_SCHEME = '(https:\\/\\/)(([^\\.]+).)(.*\\/)(.*)';
var VALID_AF_URL_PARTS_LENGTH = 5;
var GOOGLE_CLICK_ID = 'gclid';
var FACEBOOK_CLICK_ID = 'fbclid';
var GBRAID = 'gbraid';
var WBRAID = 'wbraid';
var ASSOCIATED_AD_KEYWORD = 'keyword';
var AF_KEYWORDS = 'af_keywords';
var AF_CUSTOM_EXCLUDE_PARAMS_KEYS = ['pid', 'c', 'af_channel', 'af_ad', 'af_adset', 'deep_link_value', 'af_sub1', 'af_sub2', 'af_sub3', 'af_sub4', 'af_sub5'];
var GCLID_EXCLUDE_PARAMS_KEYS = ['pid', 'c', 'af_channel', 'af_ad', 'af_adset', 'deep_link_value'];
var LOCAL_STORAGE_VALUES = {
SS_WEB_REFERRER: 'ss_webReferrer'
};
var isSkippedURL = function isSkippedURL(_ref) {
var url = _ref.url,
skipKeys = _ref.skipKeys,
errorMsg = _ref.errorMsg;
// search if this page referred and contains one of the given keys
if (url) {
var lowerURL = url.toLowerCase();
if (lowerURL) {
var skipKey = skipKeys.find(function (key) {
return lowerURL.includes(key.toLowerCase());
});
!!skipKey && console.debug(errorMsg, skipKey);
return !!skipKey;
}
}
return false;
};
var getGoogleClickIdParameters = function getGoogleClickIdParameters(gciKey, currentURLParams) {
var gciParam = currentURLParams[GOOGLE_CLICK_ID];
var result = {};
if (gciParam) {
console.debug('This user comes from Google AdWords');
result[gciKey] = gciParam;
var keywordParam = currentURLParams[ASSOCIATED_AD_KEYWORD];
if (keywordParam) {
console.debug('There is a keyword associated with the ad');
result[AF_KEYWORDS] = keywordParam;
}
} else {
console.debug('This user comes from SRN or custom network');
}
return result;
};
var stringifyParameters = function stringifyParameters() {
var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var paramStr = Object.keys(parameters).reduce(function (curr, key) {
if (parameters[key]) {
curr += "&".concat(key, "=").concat(parameters[key]);
}
return curr;
}, '');
console.debug('Generated OneLink parameters', paramStr);
return paramStr;
};
var getParameterValue = function getParameterValue(currentURLParams) {
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
keys: [],
overrideValues: {},
defaultValue: ''
};
//exit when config object structure is not valid
if (!(config !== null && config !== void 0 && config.keys && Array.isArray(config.keys) || config !== null && config !== void 0 && config.defaultValue)) {
console.error('Parameter config structure is wrong', config);
return null;
}
var _config$keys = config.keys,
keys = _config$keys === void 0 ? [] : _config$keys,
_config$overrideValue = config.overrideValues,
overrideValues = _config$overrideValue === void 0 ? {} : _config$overrideValue,
_config$defaultValue = config.defaultValue,
defaultValue = _config$defaultValue === void 0 ? '' : _config$defaultValue;
var firstMatchedKey = keys.find(function (key) {
//set the first match of key which contains also a value
return !!currentURLParams[key];
});
if (firstMatchedKey) {
var value = currentURLParams[firstMatchedKey];
//in case the value exists:
//check if it exists in the overrideValues object, when exists - replace it
//otherwise return default value
return overrideValues[value] || value || defaultValue;
}
return defaultValue;
};
var isIOS = function isIOS(useragent) {
return /iphone|ipad|ipod/i.test(useragent && useragent.toLowerCase());
};
var isUACHSupported = function isUACHSupported() {
return (typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === 'object' && 'userAgentData' in navigator && 'getHighEntropyValues' in navigator.userAgentData && !isIOS(navigator && navigator.userAgent);
};
var getQueryParamsAndSaveToLocalStorage = function getQueryParamsAndSaveToLocalStorage(websiteUrl) {
if (!websiteUrl) {
console.debug("website doesnt exist + ".concat(websiteUrl));
}
try {
var url = new URL(websiteUrl);
var urlParams = new URLSearchParams(url.search);
var queryParams = Array.from(urlParams).reduce(function (acc, _ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
key = _ref3[0],
value = _ref3[1];
return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, encodeURIComponent(value)));
}, {});
var savedQueryParams = JSON.parse(localStorage.getItem('ss_incoming_params') || '[]');
var now = new Date().getTime();
var twoHoursLater = now + 2 * 60 * 60 * 1000; // Add 2 hours in milliseconds(product request)
var dataToSave = _objectSpread2(_objectSpread2({}, queryParams), {}, {
af_ss_exp_at: twoHoursLater
});
savedQueryParams.unshift(dataToSave); // we used unshift becuse the order matter
localStorage.setItem('ss_incoming_params', JSON.stringify(savedQueryParams));
} catch (error) {
console.debug("url isnt valid + ".concat(error));
}
};
var isValidUrl = function isValidUrl(urlString) {
try {
return Boolean(new URL(urlString));
} catch (e) {
return false;
}
};
var getCurrentUrl = function getCurrentUrl() {
return new URL(window.location.href);
};
var getReferrerUrl = function getReferrerUrl() {
var referrer = document.referrer;
return referrer ? new URL(referrer) : null;
};
var isSameOrigin = function isSameOrigin(currentUrl, refUrl) {
return currentUrl.origin === refUrl.origin;
};
var saveWebReferrer = function saveWebReferrer() {
var currentUrl = getCurrentUrl();
var refUrl = getReferrerUrl();
if (refUrl && isSameOrigin(currentUrl, refUrl)) {
console.warn('You navigate from the same website');
return;
}
localStorage.setItem(LOCAL_STORAGE_VALUES.SS_WEB_REFERRER, JSON.stringify(document.referrer));
};
var removeExpiredLocalStorageItems = function removeExpiredLocalStorageItems() {
var currentTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Date.now();
var incomingParams = JSON.parse(localStorage.getItem('ss_incoming_params') || '[]');
localStorage.setItem('ss_incoming_params', JSON.stringify(incomingParams.filter(function (_ref4) {
var af_ss_exp_at = _ref4.af_ss_exp_at;
return af_ss_exp_at > currentTime;
})));
};
function aggregateValuesFromParameters() {
var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var aggregateValues = [];
Object.values(parameters).forEach(function (value) {
if (value && value.keys && Array.isArray(value.keys)) {
value.keys.forEach(function (key) {
return aggregateValues.push(key);
});
}
if (Array.isArray(value)) {
value.forEach(function (item) {
if (Array.isArray(item === null || item === void 0 ? void 0 : item.keys)) {
aggregateValues.push.apply(aggregateValues, _toConsumableArray(item.keys));
}
});
}
});
if (
// eslint-disable-next-line no-prototype-builtins
parameters.hasOwnProperty('googleClickIdKey') && typeof parameters.googleClickIdKey === 'string') {
aggregateValues.push(GOOGLE_CLICK_ID);
}
return aggregateValues;
}
function getCurrentURLParams(aggregateValues) {
var currentURLParams = {};
if (Object.keys(localStorage).includes('ss_incoming_params')) {
var incomingParamsFromSS = JSON.parse(localStorage['ss_incoming_params']);
currentURLParams = incomingParamsFromSS.find(function (obj) {
return aggregateValues.some(function (key) {
return key in obj;
});
}) || {};
} else {
console.log("Key 'ss_incoming_params' not found in localStorage.");
}
return currentURLParams;
}
var isOneLinkURLValid = function isOneLinkURLValid(oneLinkURL) {
var _ref5;
var oneLinkURLParts = (_ref5 = oneLinkURL || '') === null || _ref5 === void 0 ? void 0 : _ref5.toString().match(AF_URL_SCHEME);
if (!oneLinkURLParts || (oneLinkURLParts === null || oneLinkURLParts === void 0 ? void 0 : oneLinkURLParts.length) < VALID_AF_URL_PARTS_LENGTH) {
console.error("oneLinkURL is missing or not in the correct format, can't generate URL", oneLinkURL);
return false;
}
return true;
};
var isMSValid = function isMSValid() {
var mediaSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (!(mediaSource !== null && mediaSource !== void 0 && mediaSource.defaultValue)) {
console.error("mediaSource is missing (default value was not supplied), can't generate URL", mediaSource);
return false;
}
return true;
};
var isSkipListsValid = function isSkipListsValid(_ref6) {
var _ref6$referrerSkipLis = _ref6.referrerSkipList,
referrerSkipList = _ref6$referrerSkipLis === void 0 ? [] : _ref6$referrerSkipLis,
_ref6$urlSkipList = _ref6.urlSkipList,
urlSkipList = _ref6$urlSkipList === void 0 ? [] : _ref6$urlSkipList;
if (isSkippedURL({
url: document.referrer,
skipKeys: referrerSkipList,
errorMsg: 'Generate url is skipped. HTTP referrer contains key:'
})) {
return false;
}
if (isSkippedURL({
url: document.URL,
skipKeys: urlSkipList,
errorMsg: 'Generate url is skipped. URL contains string:'
})) {
return false;
}
return true;
};
var extractCustomParams = function extractCustomParams(_ref7) {
var _ref7$afCustom = _ref7.afCustom,
afCustom = _ref7$afCustom === void 0 ? [] : _ref7$afCustom,
_ref7$currentURLParam = _ref7.currentURLParams,
currentURLParams = _ref7$currentURLParam === void 0 ? {} : _ref7$currentURLParam,
googleClickIdKey = _ref7.googleClickIdKey;
var afParams = {};
if (Array.isArray(afCustom)) {
afCustom.forEach(function (customParam) {
if (customParam !== null && customParam !== void 0 && customParam.paramKey) {
var isOverrideExistingKey = AF_CUSTOM_EXCLUDE_PARAMS_KEYS.find(function (k) {
return k === (customParam === null || customParam === void 0 ? void 0 : customParam.paramKey);
});
if ((customParam === null || customParam === void 0 ? void 0 : customParam.paramKey) === googleClickIdKey || isOverrideExistingKey) {
console.debug("Custom parameter ParamKey can't override Google-Click-Id or AF Parameters keys", customParam);
} else {
afParams[customParam.paramKey] = getParameterValue(currentURLParams, customParam);
}
}
});
}
return afParams;
};
var validateAndMappedParams = function validateAndMappedParams() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var currentURLParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var isDirectClick = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var mediaSource = params.mediaSource,
campaign = params.campaign,
channel = params.channel,
ad = params.ad,
adSet = params.adSet,
deepLinkValue = params.deepLinkValue,
afSub1 = params.afSub1,
afSub2 = params.afSub2,
afSub3 = params.afSub3,
afSub4 = params.afSub4,
afSub5 = params.afSub5,
afCustom = params.afCustom,
googleClickIdKey = params.googleClickIdKey;
var afParams = {};
// Validates the URL and returns `true` if it should be skipped, `false` otherwise.
if (mediaSource) {
var pidValue = getParameterValue(currentURLParams, mediaSource);
if (!pidValue) {
console.error("mediaSource was not found in the URL and default value was not supplied, can't generate URL", mediaSource);
return null;
}
var pidParamKey = isDirectClick ? 'af_media_source' : 'pid';
afParams[pidParamKey] = pidValue;
}
if (campaign) {
var campaignValue = getParameterValue(currentURLParams, campaign);
if (!campaignValue && isDirectClick) {
console.error("campaign was not found in the URL and default value was not supplied, can't generate URL", campaign);
return null;
}
if (isDirectClick) {
afParams['af_campaign'] = campaignValue;
afParams['af_campaign_id'] = campaignValue;
} else {
afParams['c'] = campaignValue;
}
}
if (channel) {
afParams['af_channel'] = getParameterValue(currentURLParams, channel);
}
if (ad) {
afParams['af_ad'] = getParameterValue(currentURLParams, ad);
}
if (adSet) {
afParams['af_adset'] = getParameterValue(currentURLParams, adSet);
}
if (deepLinkValue) {
afParams['deep_link_value'] = getParameterValue(currentURLParams, deepLinkValue);
}
var afSubs = [afSub1, afSub2, afSub3, afSub4, afSub5];
afSubs.forEach(function (afSub, index) {
if (afSub) {
afParams["af_sub".concat(index + 1)] = getParameterValue(currentURLParams, afSub);
}
});
if (googleClickIdKey) {
if (GCLID_EXCLUDE_PARAMS_KEYS.find(function (k) {
return k === googleClickIdKey;
})) {
console.debug("Google Click Id ParamKey can't override AF Parameters keys", googleClickIdKey);
} else {
var googleParameters = getGoogleClickIdParameters(googleClickIdKey, currentURLParams);
Object.keys(googleParameters).forEach(function (gpk) {
afParams[gpk] = googleParameters[gpk];
});
}
}
var customParams = extractCustomParams({
afCustom: afCustom,
currentURLParams: currentURLParams,
googleClickIdKey: googleClickIdKey
});
return _objectSpread2(_objectSpread2({}, afParams), customParams);
};
var isPlatformValid = function isPlatformValid(platform) {
if (!platform) {
console.error("platform is missing , can't generate URL", platform);
return false;
}
var platforms = ['smartcast', 'tizen', 'roku', 'webos', 'vidaa', 'playstation', 'android', 'ios', 'steam', 'quest', 'battlenet', 'epic', 'switch', 'xbox', 'nativepc'];
if (!platforms.includes(platform.toLowerCase())) {
console.error('platform need to be part of the known platforms supoorted');
return false;
}
return true;
};
function getUserAgentData() {
return new Promise(function (resolve) {
if (isUACHSupported()) {
navigator.userAgentData.getHighEntropyValues(['model', 'platformVersion']).then(function (clientHints) {
resolve({
model: clientHints.model,
platformVersion: clientHints.platformVersion
});
})["catch"](function () {
resolve();
});
} else {
resolve();
}
});
}
var createImpressionsLink = function createImpressionsLink(finalURL) {
if (!finalURL) {
console.debug('ClickURL is not valid');
return null;
}
return new Promise(function (resolve) {
getUserAgentData().then(function (userAgentData) {
var url = new URL(finalURL);
url.hostname = 'impressions.onelink.me';
if (userAgentData) {
url.pathname = "/ch".concat(url.pathname);
url.searchParams.append('af_ch_model', encodeURIComponent(userAgentData.model));
url.searchParams.append('af_ch_os_version', encodeURIComponent(userAgentData.platformVersion));
}
resolve(url.href);
})["catch"](function () {
resolve();
});
});
};
function getHexColorAfterValidation(color) {
var colorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
return colorRegex.test(color) ? color : '#000';
}
function getParameterValueFromURL(url, parameter) {
var params = new URLSearchParams(url);
return params.get(parameter);
}
function updateFinalUrlWithForwardParameters(url, forwardParametersList, URLSearchParams) {
return forwardParametersList.reduce(function (updatedUrl, parameterName) {
var parameterValue = getParameterValueFromURL(URLSearchParams, parameterName);
if (parameterValue) {
console.debug("The URL contains forwarding parameter ".concat(parameterName, "."));
return "".concat(updatedUrl, "&").concat(parameterName, "=").concat(encodeURIComponent(parameterValue));
}
return updatedUrl;
}, url);
}
var processTrackingParameters = function processTrackingParameters(destinationURL) {
var forwardParametersList = [GOOGLE_CLICK_ID, FACEBOOK_CLICK_ID, GBRAID, WBRAID];
//DELINIT-1888 - for supporting postbacks for GCLID and FBCLID we need to fdorward them to the final URL
destinationURL = updateFinalUrlWithForwardParameters(destinationURL, forwardParametersList, window.location.search);
// DELINIT-1888 - specific handling for GCLID - passing the keyword to the final URL and make sure it does not already on the link
var hasGclidOnURL = getParameterValueFromURL(window.location.search, GOOGLE_CLICK_ID);
var gbraid = getParameterValueFromURL(window.location.search, GBRAID);
var wbraid = getParameterValueFromURL(window.location.search, WBRAID);
if (hasGclidOnURL || gbraid || wbraid) {
var keywordParam = getParameterValueFromURL(window.location.search, ASSOCIATED_AD_KEYWORD);
var hasAfKeywordOnFinalURL = getParameterValueFromURL(destinationURL, AF_KEYWORDS);
if (keywordParam && !hasAfKeywordOnFinalURL) {
destinationURL = "".concat(destinationURL, "&").concat(AF_KEYWORDS, "=").concat(keywordParam);
}
}
return destinationURL;
};
/**
* EasyQRCodeJS
*
* Cross-browser QRCode generator for pure javascript. Support Canvas, SVG and Table drawing methods. Support Dot style, Logo, Background image, Colorful, Title etc. settings. Support Angular, Vue.js, React, Next.js, Svelte framework. Support binary(hex) data mode.(Running with DOM on client side)
*
* Version 4.4.10
*
* @author [ [email protected] ]
*
* @see https://github.com/ushelp/EasyQRCodeJS
* @see http://www.easyproject.cn/easyqrcodejs/tryit.html
* @see https://github.com/ushelp/EasyQRCodeJS-NodeJS
*
* Copyright 2017 Ray, EasyProject
* Released under the MIT license
*
* [Support AMD, CMD, CommonJS/Node.js]
*
*/
function QRCode() {
// 自定义局部 undefined 变量
var undefined$1;
/** Node.js global 检测. */
var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
/** `self` 变量检测. */
var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
/** 全局对象检测. */
var root = freeGlobal || freeSelf || Function('return this')();
/** `exports` 变量检测. */
var freeExports = (typeof exports === "undefined" ? "undefined" : _typeof(exports)) == 'object' && exports && !exports.nodeType && exports;
/** `module` 变量检测. */
var freeModule = freeExports && (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module && !module.nodeType && module;
var _QRCode = root.QRCode;
var QRCode;
function QR8bitByte(data, binary, utf8WithoutBOM) {
this.mode = QRMode.MODE_8BIT_BYTE;
this.data = data;
this.parsedData = [];
// Added to support UTF-8 Characters
for (var i = 0, l = this.data.length; i < l; i++) {
var byteArray = [];
var code = this.data.charCodeAt(i);
if (binary) {
byteArray[0] = code;
} else {
if (code > 0x10000) {
byteArray[0] = 0xf0 | (code & 0x1c0000) >>> 18;
byteArray[1] = 0x80 | (code & 0x3f000) >>> 12;
byteArray[2] = 0x80 | (code & 0xfc0) >>> 6;
byteArray[3] = 0x80 | code & 0x3f;
} else if (code > 0x800) {
byteArray[0] = 0xe0 | (code & 0xf000) >>> 12;
byteArray[1] = 0x80 | (code & 0xfc0) >>> 6;
byteArray[2] = 0x80 | code & 0x3f;
} else if (code > 0x80) {
byteArray[0] = 0xc0 | (code & 0x7c0) >>> 6;
byteArray[1] = 0x80 | code & 0x3f;
} else {
byteArray[0] = code;
}
}
this.parsedData.push(byteArray);
}
this.parsedData = Array.prototype.concat.apply([], this.parsedData);
if (!utf8WithoutBOM && this.parsedData.length != this.data.length) {
this.parsedData.unshift(191);
this.parsedData.unshift(187);
this.parsedData.unshift(239);
}
}
QR8bitByte.prototype = {
getLength: function getLength(buffer) {
return this.parsedData.length;
},
write: function write(buffer) {
for (var i = 0, l = this.parsedData.length; i < l; i++) {
buffer.put(this.parsedData[i], 8);
}
}
};
function QRCodeModel(typeNumber, errorCorrectLevel) {
this.typeNumber = typeNumber;
this.errorCorrectLevel = errorCorrectLevel;
this.modules = null;
this.moduleCount = 0;
this.dataCache = null;
this.dataList = [];
}
QRCodeModel.prototype = {
addData: function addData(data, binary, utf8WithoutBOM) {
var newData = new QR8bitByte(data, binary, utf8WithoutBOM);
this.dataList.push(newData);
this.dataCache = null;
},
isDark: function isDark(row, col) {
if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
throw new Error(row + ',' + col);
}
return this.modules[row][col][0];
},
getEye: function getEye(row, col) {
if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
throw new Error(row + ',' + col);
}
var block = this.modules[row][col]; // [isDark(ture/false), EyeOuterOrInner(O/I), Position(TL/TR/BL/A) ]
if (block[1]) {
var type = 'P' + block[1] + '_' + block[2]; //PO_TL, PI_TL, PO_TR, PI_TR, PO_BL, PI_BL
if (block[2] == 'A') {
type = 'A' + block[1]; // AI, AO
}
return {
isDark: block[0],
type: type
};
} else {
return null;
}
},
getModuleCount: function getModuleCount() {
return this.moduleCount;
},
make: function make() {
this.makeImpl(false, this.getBestMaskPattern());
},
makeImpl: function makeImpl(test, maskPattern) {
this.moduleCount = this.typeNumber * 4 + 17;
this.modules = new Array(this.moduleCount);
for (var row = 0; row < this.moduleCount; row++) {
this.modules[row] = new Array(this.moduleCount);
for (var col = 0; col < this.moduleCount; col++) {
this.modules[row][col] = []; // [isDark(ture/false), EyeOuterOrInner(O/I), Position(TL/TR/BL) ]
}
}
this.setupPositionProbePattern(0, 0, 'TL'); // TopLeft, TL
this.setupPositionProbePattern(this.moduleCount - 7, 0, 'BL'); // BotoomLeft, BL
this.setupPositionProbePattern(0, this.moduleCount - 7, 'TR'); // TopRight, TR
this.setupPositionAdjustPattern('A'); // Alignment, A
this.setupTimingPattern();
this.setupTypeInfo(test, maskPattern);
if (this.typeNumber >= 7) {
this.setupTypeNumber(test);
}
if (this.dataCache == null) {
this.dataCache = QRCodeModel.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
}
this.mapData(this.dataCache, maskPattern);
},
setupPositionProbePattern: function setupPositionProbePattern(row, col, posName) {
for (var r = -1; r <= 7; r++) {
if (row + r <= -1 || this.moduleCount <= row + r) continue;
for (var c = -1; c <= 7; c++) {
if (col + c <= -1 || this.moduleCount <= col + c) continue;
if (0 <= r && r <= 6 && (c == 0 || c == 6) || 0 <= c && c <= 6 && (r == 0 || r == 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {
this.modules[row + r][col + c][0] = true;
this.modules[row + r][col + c][2] = posName; // Position
if (r == -0 || c == -0 || r == 6 || c == 6) {
this.modules[row + r][col + c][1] = 'O'; // Position Outer
} else {
this.modules[row + r][col + c][1] = 'I'; // Position Inner
}
} else {
this.modules[row + r][col + c][0] = false;
}
}
}
},
getBestMaskPattern: function getBestMaskPattern() {
var minLostPoint = 0;
var pattern = 0;
for (var i = 0; i < 8; i++) {
this.makeImpl(true, i);
var lostPoint = QRUtil.getLostPoint(this);
if (i == 0 || minLostPoint > lostPoint) {
minLostPoint = lostPoint;
pattern = i;
}
}
return pattern;
},
createMovieClip: function createMovieClip(target_mc, instance_name, depth) {
var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
var cs = 1;
this.make();
for (var row = 0; row < this.modules.length; row++) {
var y = row * cs;
for (var col = 0; col < this.modules[row].length; col++) {
var x = col * cs;
var dark = this.modules[row][col][0];
if (dark) {
qr_mc.beginFill(0, 100);
qr_mc.moveTo(x, y);
qr_mc.lineTo(x + cs, y);
qr_mc.lineTo(x + cs, y + cs);
qr_mc.lineTo(x, y + cs);
qr_mc.endFill();
}
}
}
return qr_mc;
},
setupTimingPattern: function setupTimingPattern() {
for (var r = 8; r < this.moduleCount - 8; r++) {
if (this.modules[r][6][0] != null) {
continue;
}
this.modules[r][6][0] = r % 2 == 0;
}
for (var c = 8; c < this.moduleCount - 8; c++) {
if (this.modules[6][c][0] != null) {
continue;
}
this.modules[6][c][0] = c % 2 == 0;
}
},
setupPositionAdjustPattern: function setupPositionAdjustPattern(posName) {
var pos = QRUtil.getPatternPosition(this.typeNumber);
for (var i = 0; i < pos.length; i++) {
for (var j = 0; j < pos.length; j++) {
var row = pos[i];
var col = pos[j];
if (this.modules[row][col][0] != null) {
continue;
}
for (var r = -2; r <= 2; r++) {
for (var c = -2; c <= 2; c++) {
if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
this.modules[row + r][col + c][0] = true;
this.modules[row + r][col + c][2] = posName; // Position
if (r == -2 || c == -2 || r == 2 || c == 2) {
this.modules[row + r][col + c][1] = 'O'; // Position Outer
} else {
this.modules[row + r][col + c][1] = 'I'; // Position Inner
}
} else {
this.modules[row + r][col + c][0] = false;
}
}
}
}
}
},
setupTypeNumber: function setupTypeNumber(test) {
var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
for (var i = 0; i < 18; i++) {
var mod = !test && (bits >> i & 1) == 1;
this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3][0] = mod;
}
for (var i = 0; i < 18; i++) {
var mod = !test && (bits >> i & 1) == 1;
this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)][0] = mod;
}
},
setupTypeInfo: function setupTypeInfo(test, maskPattern) {
var data = this.errorCorrectLevel << 3 | maskPattern;
var bits = QRUtil.getBCHTypeInfo(data);
for (var i = 0; i < 15; i++) {
var mod = !test && (bits >> i & 1) == 1;
if (i < 6) {
this.modules[i][8][0] = mod;
} else if (i < 8) {
this.modules[i + 1][8][0] = mod;
} else {
this.modules[this.moduleCount - 15 + i][8][0] = mod;
}
}
for (var i = 0; i < 15; i++) {
var mod = !test && (bits >> i & 1) == 1;
if (i < 8) {
this.modules[8][this.moduleCount - i - 1][0] = mod;
} else if (i < 9) {
this.modules[8][15 - i - 1 + 1][0] = mod;
} else {
this.modules[8][15 - i - 1][0] = mod;
}
}
this.modules[this.moduleCount - 8][8][0] = !test;
},
mapData: function mapData(data, maskPattern) {
var inc = -1;
var row = this.moduleCount - 1;
var bitIndex = 7;
var byteIndex = 0;
for (var col = this.moduleCount - 1; col > 0; col -= 2) {
if (col == 6) col--;
while (true) {
for (var c = 0; c < 2; c++) {
if (this.modules[row][col - c][0] == null) {
var dark = false;
if (byteIndex < data.length) {
dark = (data[byteIndex] >>> bitIndex & 1) == 1;
}
var mask = QRUtil.getMask(maskPattern, row, col - c);
if (mask) {
dark = !dark;
}
this.modules[row][col - c][0] = dark;
bitIndex--;
if (bitIndex == -1) {
byteIndex++;
bitIndex = 7;
}
}
}
row += inc;
if (row < 0 || this.moduleCount <= row) {
row -= inc;
inc = -inc;
break;
}
}
}
}
};
QRCodeModel.PAD0 = 0xec;
QRCodeModel.PAD1 = 0x11;
QRCodeModel.createData = function (typeNumber, errorCorrectLevel, dataList) {
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
var buffer = new QRBitBuffer();
for (var i = 0; i < dataList.length; i++) {
var data = dataList[i];
buffer.put(data.mode, 4);
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
data.write(buffer);
}
var totalDataCount = 0;
for (var i = 0; i < rsBlocks.length; i++) {
totalDataCount += rsBlocks[i].dataCount;
}
if (buffer.getLengthInBits() > totalDataCount * 8) {
throw new Error('code length overflow. (' + buffer.getLengthInBits() + '>' + totalDataCount * 8 + ')');
}
if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
buffer.put(0, 4);
}
while (buffer.getLengthInBits() % 8 != 0) {
buffer.putBit(false);
}
while (true) {
if (buffer.getLengthInBits() >= totalDataCount * 8) {
break;
}
buffer.put(QRCodeModel.PAD0, 8);
if (buffer.getLengthInBits() >= totalDataCount * 8) {
break;
}
buffer.put(QRCodeModel.PAD1, 8);
}
return QRCodeModel.createBytes(buffer, rsBlocks);
};
QRCodeModel.createBytes = function (buffer, rsBlocks) {
var offset = 0;
var maxDcCount = 0;
var maxEcCount = 0;
var dcdata = new Array(rsBlocks.length);
var ecdata = new Array(rsBlocks.length);
for (var r = 0; r < rsBlocks.length; r++) {
var dcCount = rsBlocks[r].dataCount;
var ecCount = rsBlocks[r].totalCount - dcCount;
maxDcCount = Math.max(maxDcCount, dcCount);
maxEcCount = Math.max(maxEcCount, ecCount);
dcdata[r] = new Array(dcCount);
for (var i = 0; i < dcdata[r].length; i++) {
dcdata[r][i] = 0xff & buffer.buffer[i + offset];
}
offset += dcCount;
var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
var modPoly = rawPoly.mod(rsPoly);
ecdata[r] = new Array(rsPoly.getLength() - 1);
for (var i = 0; i < ecdata[r].length; i++) {
var modIndex = i + modPoly.getLength() - ecdata[r].length;
ecdata[r][i] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
}
}
var totalCodeCount = 0;
for (var i = 0; i < rsBlocks.length; i++) {
totalCodeCount += rsBlocks[i].totalCount;
}
var data = new Array(totalCodeCount);
var index = 0;
for (var i = 0; i < maxDcCount; i++) {
for (var r = 0; r < rsBlocks.length; r++) {
if (i < dcdata[r].length) {
data[index++] = dcdata[r][i];
}
}
}
for (var i = 0; i < maxEcCount; i++) {
for (var r = 0; r < rsBlocks.length; r++) {
if (i < ecdata[r].length) {
data[index++] = ecdata[r][i];
}
}
}
return data;
};
var QRMode = {
MODE_NUMBER: 1 << 0,
MODE_ALPHA_NUM: 1 << 1,
MODE_8BIT_BYTE: 1 << 2,
MODE_KANJI: 1 << 3
};
var QRErrorCorrectLevel = {
L: 1,
M: 0,
Q: 3,
H: 2
};
var QRMaskPattern = {
PATTERN000: 0,
PATTERN001: 1,
PATTERN010: 2,
PATTERN011: 3,
PATTERN100: 4,
PATTERN101: 5,
PATTERN110: 6,
PATTERN111: 7
};
var QRUtil = {
PATTERN_POSITION_TABLE: [[], [6, 18], [6, 22], [6, 26], [6, 30], [6, 34], [6, 22, 38], [6, 24, 42], [6, 26, 46], [6, 28, 50], [6, 30, 54], [6, 32, 58], [6, 34, 62], [6, 26, 46, 66], [6, 26, 48, 70], [6, 26, 50, 74], [6, 30, 54, 78], [6, 30, 56, 82], [6, 30, 58, 86], [6, 34, 62, 90], [6, 28, 50, 72, 94], [6, 26, 50, 74, 98], [6, 30, 54, 78, 102], [6, 28, 54, 80, 106], [6, 32, 58, 84, 110], [6, 30, 58, 86, 114], [6, 34, 62, 90, 118], [6, 26, 50, 74, 98, 122], [6, 30, 54, 78, 102, 126], [6, 26, 52, 78, 104, 130], [6, 30, 56, 82, 108, 134], [6, 34, 60, 86, 112, 138], [6, 30, 58, 86, 114, 142], [6, 34, 62, 90, 118, 146], [6, 30, 54, 78, 102, 126, 150], [6, 24, 50, 76, 102, 128, 154], [6, 28, 54, 80, 106, 132, 158], [6, 32, 58, 84, 110, 136, 162], [6, 26, 54, 82, 110, 138, 166], [6, 30, 58, 86, 114, 142, 170]],
G15: 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0,
G18: 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0,
G15_MASK: 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1,
getBCHTypeInfo: function getBCHTypeInfo(data) {
var d = data << 10;
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15);
}
return (data << 10 | d) ^ QRUtil.G15_MASK;
},
getBCHTypeNumber: function getBCHTypeNumber(data) {
var d = data << 12;
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18);
}
return data << 12 | d;
},
getBCHDigit: function getBCHDigit(data) {
var digit = 0;
while (data != 0) {
digit++;
data >>>= 1;
}
return digit;
},
getPatternPosition: function getPatternPosition(typeNumber) {
return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
},
getMask: function getMask(maskPattern, i, j) {
switch (maskPattern) {
case QRMaskPattern.PATTERN000:
return (i + j) % 2 == 0;
case QRMaskPattern.PATTERN001:
return i % 2 == 0;
case QRMaskPattern.PATTERN010:
return j % 3 == 0;
case QRMaskPattern.PATTERN011:
return (i + j) % 3 == 0;
case QRMaskPattern.PATTERN100:
return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
case QRMaskPattern.PATTERN101:
return i * j % 2 + i * j % 3 == 0;