-
Notifications
You must be signed in to change notification settings - Fork 33
/
bbo.js
3175 lines (2596 loc) · 76.2 KB
/
bbo.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
/*
* bbo
* bbo is a utility library of zero dependencies for javascript.
* (c) 2011 - 2021
* https://github.com/tnfe/bbo.git
* version 1.1.26
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.bbo = factory());
}(this, (function () { 'use strict';
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toArray(arr) {
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
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 _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 getTag(src) {
return Object.prototype.toString.call(src);
}
function isString(str) {
return getTag(str) === '[object String]';
}
function isFunction(func) {
return getTag(func) === '[object Function]';
}
var version = '1.1.26';
var globalObject = null;
function getGlobalObject() {
if (globalObject !== null) {
return globalObject;
}
/* istanbul ignore next */
// It's hard to mock the global variables. This code surely works fine. I hope :)
if (typeof global === 'object' && global.Object === Object) {
// NodeJS global object
globalObject = global;
} else if (typeof self === 'object' && self.Object === Object) {
// self property from Window object
globalObject = self;
} else {
// Other cases. Function constructor always has the context as global object
// eslint-disable-next-line no-new-func
globalObject = new Function('return this')();
}
return globalObject;
}
/* eslint-disable no-invalid-this */
var globalObject$1 = getGlobalObject();
var previous = globalObject$1.bbo;
function noConflict() {
if (this === globalObject$1.bbo) {
globalObject$1.bbo = previous;
}
return this;
}
function ua(lower) {
return lower ? window.navigator.userAgent.toLowerCase() : window.navigator.userAgent;
}
/**
* detect IOS
* From https://stackoverflow.com/questions/9038625/detect-if-device-is-ios
* more see:
* https://github.com/madrobby/zepto/blob/master/src/detect.js#files
*/
function isIOS() {
return /iPad|iPhone|iPod/.test(ua());
}
function iPhone() {
return /iPhone/.test(ua());
}
function isIPad() {
return /iPad/.test(ua());
}
/**
* detect Android
* From https://stackoverflow.com/questions/6031412/detect-android-phone-via-javascript-jquery
*/
function isAndroid() {
return ua('l').indexOf('android') > -1;
}
/**
* detect PC / Mobile
* From https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery
*/
function isMobile() {
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(ua('l'));
}
/**
* detect PC / Mobile
* From https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery
*/
function isPC() {
return !isMobile();
}
function isWeixin() {
return /MicroMessenger/i.test(ua('l')); // 微信
}
function isNewsApp() {
return /qqnews/.test(ua()); // 腾讯新闻app
}
function isQQ() {
return /qq\//.test(ua('l')); // 手机QQ
}
function isQQbrowser() {
return /mqqbrowser\//.test(ua('l')); // QQ浏览器
}
function isTenvideo() {
return /qqlivebrowser/.test(ua('l')); // 腾讯视频
}
function isWeiShi() {
return /weishi/.test(ua('l')); // 腾讯微视
}
function isIphoneXmodel() {
// X XS, XS Max, XR
var xSeriesConfig = [{
devicePixelRatio: 3,
width: 375,
height: 812
}, {
devicePixelRatio: 3,
width: 414,
height: 896
}, {
devicePixelRatio: 2,
width: 414,
height: 896
}];
if (typeof window !== 'undefined' && window) {
var _window = window,
devicePixelRatio = _window.devicePixelRatio,
screen = _window.screen;
var width = screen.width,
height = screen.height;
return xSeriesConfig.some(item => item.devicePixelRatio === devicePixelRatio && item.width === width && item.height === height);
}
return false;
}
/**
* ie version
* From https://codepen.io/gapcode/pen/vEJNZN
* IE 10 ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
* IE 11 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
* Edge 12 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
* Edge 13 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586';
*/
function ieVersion() {
var uakit = ua();
var msie = uakit.indexOf('MSIE ');
if (msie > 0) {
return parseInt(uakit.substring(msie + 5, uakit.indexOf('.', msie)), 10);
}
var trident = uakit.indexOf('Trident/');
if (trident > 0) {
var rv = uakit.indexOf('rv:');
return parseInt(uakit.substring(rv + 3, uakit.indexOf('.', rv)), 10);
}
var edge = uakit.indexOf('Edge/');
if (edge > 0) {
return parseInt(ua.substring(edge + 5, uakit.indexOf('.', edge)), 10);
}
return '';
}
function isIE() {
return ieVersion() > 0;
}
/**
* arguments to array
*/
/**
* Converts the arguments object to an array object and slice it.
* first defalult is 0.
* @export
* @param {*} $arguments
* @param {*} first
* @returns
*/
function args($arguments, first) {
return Array.prototype.slice.call($arguments, first || 0);
}
var noop = () => {};
var merge = function () {
for (var _len = arguments.length, objs = new Array(_len), _key = 0; _key < _len; _key++) {
objs[_key] = arguments[_key];
}
return [].concat(objs).reduce((acc, obj) => Object.keys(obj).reduce((a, k) => {
acc[k] = acc.hasOwnProperty(k) ? [].concat(acc[k]).concat(obj[k]) : obj[k];
return acc;
}, {}), {});
};
var over = function () {
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
fns[_key] = arguments[_key];
}
return function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return fns.map(fn => fn.apply(null, args));
};
};
var call = function (key) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return context => context[key].apply(context, args);
};
function hasOwnProperty(obj, keyName) {
return Object.prototype.hasOwnProperty.call(obj, keyName);
}
function setStyle(el, ruleName, val) {
el.style[ruleName] = val;
}
function attr(el, ruleName, val) {
el.setAttribute(ruleName, val);
}
/**
* trigger event
* https://stackoverflow.com/questions/2490825/how-to-trigger-event-in-javascript
*/
var trigger = (element, event, eventType) => {
// delete document.createEventObject of ie
var e = document.createEvent(eventType || 'HTMLEvents');
e.initEvent(event, true, true);
element.dispatchEvent(e);
};
function g(i) {
return document.getElementById(i);
}
function c(t, cn, i, id) {
var el = document.createElement(t);
if (cn) {
attr(el, 'class', cn);
}
if (i) {
el.innerHTML = i;
}
if (id) {
attr(el, 'id', id);
}
return el;
}
/**
* open new url dont not blocked by browser
*/
var open = href => {
var id = '_bbo_open_proxy';
var a = g(id) || c('a', id, '', id);
setStyle(a, 'display', 'none');
attr(a, 'href', href);
attr(a, 'target', '_blank');
if (!a.parentNode) document.body.appendChild(a);
trigger(a, 'click', 'MouseEvents');
};
var stopPropagation = event => {
var e = event || window.event;
var stop = e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
return stop;
};
function gc(cn) {
return document.getElementsByClassName(cn);
}
function query(i) {
return document.querySelector(i);
}
var show = function () {
for (var _len = arguments.length, el = new Array(_len), _key = 0; _key < _len; _key++) {
el[_key] = arguments[_key];
}
return [].concat(el).forEach(e => {
e.style.display = '';
});
};
var hide = function () {
for (var _len = arguments.length, el = new Array(_len), _key = 0; _key < _len; _key++) {
el[_key] = arguments[_key];
}
return [].concat(el).forEach(e => {
e.style.display = 'none';
});
};
var elementContains = (parent, child) => parent !== child && parent.contains(child);
var getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
/**
* generate uuid
* From https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
*/
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
var v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
}
function isArray(arr) {
return getTag(arr) === '[object Array]';
}
function isMap(map) {
return getTag(map) === '[object Map]';
}
function isSet(set) {
return getTag(set) === '[object Set]';
}
/**
* Gets the size of `collection` by returning its length for array-like
* values or the number of own enumerable string keyed properties for objects.
*
* @category Collection
* @param {Array|Object|string} collection The collection to inspect.
* @returns {number} Returns the collection size.
*/
function size(collection) {
if (collection === null || collection === undefined) {
return 0;
}
if (isArray(collection) || isString(collection)) {
return collection.length;
}
if (isMap(collection) || isSet(collection)) {
return collection.size;
}
return Object.keys(collection).length;
}
/**
* string hash map
* From https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
*/
function hash(str) {
var _str = String(str);
var hash = 0;
var i;
var chr;
if (size(_str) === 0) return hash;
for (i = 0; i < _str.length; i++) {
chr = _str.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
/**
* is typeof type
*/
var isTypeof = (val, type) => {
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase() === type;
};
/**
* map condition judge
* bbo.judge = bbo.judgment
*/
function judge(v, vals, strict) {
if (!isTypeof(vals, 'array')) return false;
for (var key in vals) {
if (strict) {
if (v === vals[key]) return true;
} else {
// eslint-disable-next-line eqeqeq
if (v == vals[key]) return true;
}
}
return false;
}
var getType = v => v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
function construct() {
var classs = arguments[0];
return new (Function.prototype.bind.apply(classs, arguments))();
}
/**
* Gets all the formal parameter names of a function
* https://www.zhihu.com/question/28912825
*/
function paramsName(fn) {
return /\(\s*([\s\S]*?)\s*\)/.exec(fn.toString())[1].split(/\s*,\s*/);
}
/************************************************************************
* LOGS
*************************************************************************/
function log(msg, styles) {
var ele = g('_bbo_log');
if (ele === null) {
ele = c('div');
attr(ele, 'id', '_bbo_log');
attr(ele, 'style', 'position:fixed;left:0;top:0;z-index:9999;padding:4px;');
document.body.appendChild(ele);
}
if (styles) {
for (var style in styles) {
if (Object.prototype.hasOwnProperty.call(styles, style)) {
ele.style[style] = styles[style];
}
}
}
ele.innerHTML = msg;
}
function isObject(value) {
var type = typeof value;
return value !== null && (type === 'object' || type === 'function');
}
var properObject = o => isObject(o) && !o.hasOwnProperty ? { ...o
} : o;
var isDate = d => d instanceof Date;
function isEmpty(obj) {
if (obj === null) {
return true;
}
if (isArray(obj)) {
return !obj.length;
}
if (isString(obj)) {
return !obj.length;
}
if (isObject(obj)) {
return !Object.keys(obj).length;
}
if (isMap(obj) || isSet(obj)) {
return !obj.size;
} // other primitive || unidentifed object type
return Object(obj) !== obj || !Object.keys(obj).length;
}
var objectDiff = (lhs, rhs) => {
if (lhs === rhs) return {}; // equal return no diff
if (!isObject(lhs) || !isObject(rhs)) return rhs; // return updated rhs
var l = properObject(lhs);
var r = properObject(rhs);
var deletedValues = Object.keys(l).reduce((acc, key) => {
return r.hasOwnProperty(key) ? acc : { ...acc,
[key]: undefined
};
}, {});
if (isDate(l) || isDate(r)) {
// eslint-disable-next-line eqeqeq
if (l.valueOf() == r.valueOf()) return {};
return r;
}
return Object.keys(r).reduce((acc, key) => {
if (!l.hasOwnProperty(key)) return { ...acc,
[key]: r[key]
}; // return added r key
var difference = objectDiff(l[key], r[key]);
if (isObject(difference) && isEmpty(difference) && !isDate(difference)) return acc; // return no diff
return { ...acc,
[key]: difference
}; // return updated key
}, deletedValues);
};
var addedDiff = (lhs, rhs) => {
if (lhs === rhs || !isObject(lhs) || !isObject(rhs)) return {};
var l = properObject(lhs);
var r = properObject(rhs);
return Object.keys(r).reduce((acc, key) => {
if (l.hasOwnProperty(key)) {
var difference = addedDiff(l[key], r[key]);
if (isObject(difference) && isEmpty(difference)) return acc;
return { ...acc,
[key]: difference
};
}
return { ...acc,
[key]: r[key]
};
}, {});
};
var deletedDiff = (lhs, rhs) => {
if (lhs === rhs || !isObject(lhs) || !isObject(rhs)) return {};
var l = properObject(lhs);
var r = properObject(rhs);
return Object.keys(l).reduce((acc, key) => {
if (r.hasOwnProperty(key)) {
var difference = deletedDiff(l[key], r[key]);
if (isObject(difference) && isEmpty(difference)) return acc;
return { ...acc,
[key]: difference
};
}
return { ...acc,
[key]: undefined
};
}, {});
};
var updatedDiff = (lhs, rhs) => {
if (lhs === rhs) return {};
if (!isObject(lhs) || !isObject(rhs)) return rhs;
var l = properObject(lhs);
var r = properObject(rhs);
if (isDate(l) || isDate(r)) {
// eslint-disable-next-line eqeqeq
if (l.valueOf() == r.valueOf()) return {};
return r;
}
return Object.keys(r).reduce((acc, key) => {
if (l.hasOwnProperty(key)) {
var difference = updatedDiff(l[key], r[key]);
if (isObject(difference) && isEmpty(difference) && !isDate(difference)) return acc;
return { ...acc,
[key]: difference
};
}
return acc;
}, {});
};
var detailedDiff = (lhs, rhs) => ({
added: addedDiff(lhs, rhs),
deleted: deletedDiff(lhs, rhs),
updated: updatedDiff(lhs, rhs)
});
/**
* to json
*/
// eval hack
var evil = fn => {
// A variable points to Function, preventing reporting errors
var Fn = Function;
return new Fn('return ' + fn)();
}; // bbo.toJSON = bbo.tojson = bbo.toJson
var toJson = res => {
if (!res) return null;
if (typeof res === 'string') {
try {
return JSON.parse(res);
} catch (e) {
return evil('(' + res + ')');
}
} else {
return res;
}
};
var randomKey = function () {
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 32;
/** Removed confusing characters 'oOLl,9gq,Vv,Uu,I1' **/
var possible = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
var key = '';
for (var i = 0; i < len; i++) {
key += possible.charAt(Math.floor(Math.random() * possible.length));
}
return key;
};
/* eslint-disable */
/**
* Options:
* - param {String} qs parameter (`callback`)
* - prefix {String} qs parameter (`bbo`)
* - name {String} qs parameter (`prefix` + incr)
* - timeout {Number} how long after a timeout error is emitted (`60000`)
* @param {String} url
* @param {Object|Function} optional options / callback
* @param {Function} optional callback
*/
function jsonp(url, opts, fn) {
if (isFunction(opts)) {
fn = opts;
opts = {};
}
if (!opts) opts = {};
var prefix = opts.prefix || 'bbo';
var id = opts.name || prefix + randomKey(10);
var param = opts.param || 'callback';
var timeout = null != opts.timeout ? opts.timeout : 60000;
var enc = encodeURIComponent;
var target = document.getElementsByTagName('script')[0] || document.head;
var script;
var timer;
if (timeout) {
timer = setTimeout(function () {
cleanup();
if (fn) fn(new Error('Timeout'));
}, timeout);
}
function cleanup() {
if (script.parentNode) script.parentNode.removeChild(script);
window[id] = noop();
if (timer) clearTimeout(timer);
}
function cancel() {
if (window[id]) {
cleanup();
}
}
window[id] = function (data) {
cleanup();
if (fn) fn(data, null);
};
console.log(url);
url += (~url.indexOf('?') ? '&' : '?') + param + '=' + enc(id);
url = url.replace('?&', '?');
script = document.createElement('script');
script.src = url;
target.parentNode.insertBefore(script, target);
return cancel;
}
function isNumber(number) {
return getTag(number) === '[object Number]';
}
/* eslint-disable guard-for-in */
var cookie = () => {
function cookieAttrExtend() {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[i];
for (var key in attributes) {
if (hasOwnProperty(attributes, key)) {
result[key] = attributes[key];
}
}
}
return result;
}
function init(converter) {
function api(key, value, attributes) {
var result;
if (size(arguments) > 1) {
attributes = cookieAttrExtend({
path: '/'
}, api.defaults, attributes);
if (isNumber(attributes.expires)) {
var expires = new Date();
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e5);
attributes.expires = expires;
}
try {
result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}
if (!converter.write) {
value = encodeURIComponent(String(value)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
} else {
value = converter.write(value, key);
}
key = encodeURIComponent(String(key));
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape); // eslint-disable-next-line no-return-assign
return document.cookie = [key, '=', value, attributes.expires ? '; expires=' + attributes.expires.toUTCString() : '', attributes.path ? '; path=' + attributes.path : '', attributes.domain ? '; domain=' + attributes.domain : '', attributes.secure ? '; secure' : ''].join('');
}
if (!key) {
result = {};
}
var cookies = document.cookie ? document.cookie.split('; ') : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var _cookie = parts.slice(1).join('=');
if (_cookie.charAt(0) === '"') {
_cookie = _cookie.slice(1, -1);
}
try {
var name = parts[0].replace(rdecode, decodeURIComponent);
_cookie = converter.read ? converter.read(_cookie, name) : converter(_cookie, name) || _cookie.replace(rdecode, decodeURIComponent); // eslint-disable-next-line no-invalid-this
if (this.json) {
try {
_cookie = JSON.parse(_cookie);
} catch (e) {}
}
if (key === name) {
result = _cookie;
break;
}
if (!key) {
result[name] = _cookie;
}
} catch (e) {}
}
return result;
}
api.set = api;
api.get = function (key) {
return api.call(api, key);
};
api.getJson = api.getJSON = function () {
return api.apply({
json: true
}, [].slice.call(arguments));
};
api.defaults = {};
api.remove = function (key, attributes) {
api(key, '', cookieAttrExtend(attributes, {
expires: -1
}));
};
api.withConverter = init;
return api;
}
return init(function () {});
};
/**
* setCookie / getCookie / deleteCookie
* From https://stackoverflow.com/questions/1458724/how-do-i-set-unset-cookie-with-jquery/1458728#1458728
*/
var setCookie = (name, value, option) => {
var longTime = 10; // let path = '; path=/';
var val = option && option.raw ? value : encodeURIComponent(value);
var cookie = encodeURIComponent(name) + '=' + val;
if (option) {
if (option.days) {
var date = new Date();
var ms = option.days * 24 * 3600 * 1000;
date.setTime(date.getTime() + ms);
cookie += '; expires=' + date.toGMTString();
} else if (option.hour) {
var _date = new Date();
var _ms = option.hour * 3600 * 1000;
_date.setTime(_date.getTime() + _ms);
cookie += '; expires=' + _date.toGMTString();
} else {
var _date2 = new Date();
var _ms2 = longTime * 365 * 24 * 3600 * 1000;
_date2.setTime(_date2.getTime() + _ms2);
cookie += '; expires=' + _date2.toGMTString();
}
if (option.path) cookie += '; path=' + option.path;
if (option.domain) cookie += '; domain=' + option.domain;
if (option.secure) cookie += '; true';
}
document.cookie = cookie;
};
var getCookie = name => {
var nameEQ = encodeURIComponent(name) + '=';
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));