-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
3056 lines (2821 loc) · 80.2 KB
/
functions.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
// Global variables
var alertData = "";
var alertOriginal = "";
var alertTable = alertData.split("\n");
var version = "xxx";
srcRelnotes = "https://docs.google.com/document/d/e/2PACX-1vQ_8Iv9HbBj4nWDXSY_kHsW1ZP_4c4dbOVO0GLuObJc1vFu_TBg9oV6ZJXMWd_tLITOj7i6WaJBeZJI/pub";
const CHECKED_CHAR = "✔";
function getBBOalertHeaderMsg() {
try {
var r = alertTable[0].split(',')[1];
if (r == undefined) return '';
if (alertTable[0].toUpperCase().indexOf('BBOALERT') == -1) return '';
return ' ' + r.trim() + ' ';
} catch {
return '';
}
}
/**
* @ignore
*/
function stringToCC(s) {
ref = shiftChars(s, 256);
var t = '';
for (i = 0; i < ref.length; i = i + 30) {
t = t + '\n' + ref.substr(i, 30);
}
return t;
}
/**
* @ignore
*/
function CCtoString(s) {
if (s == undefined) return '';
if (s == null) return '';
if (s == '') return '';
var ref = s.replace(/ /g, '');
if (getDataType(s) == 'BBOalert') {
ref = ref.replace(/←/g, '\n');
ref = ref.replace(/→/g, '\t');
ref = ref.replace(/↓/g, '!');
ref = ref.replace(/…/g, ' ');
} else {
return shiftChars(ref.replace(/\n/g, ""), -256);
}
return ref;
}
/**
* execute script
* @param {string} S Javascript code
* @param {string} S Javascript code
* @param {string} CR context field (optional)
* @param {string} C current bidding context (optional)
* @param {string} BR call field (optional)
* @param {string} B current call (optional)
* @returns R = value of reserved variable
*/
function userScript(SN="", S="", CR="", C="", BR="", B="") {
R = '';
var i = S.indexOf("\(");
try {
if (i != -1) {
R = getUserScript(S.slice(0,i))(SN, scriptArg(S), CR, C, BR, B);
if (R == "not_found") eval(S);
} else {
eval(S);
}
return R;
} catch (error) {
addLog('Error in script ' + SN);
addLog(error);
addLog(S);
return 'ERROR';
}
}
/**
* tranform string s into RegExp object
* @param {string} s
* @returns {RegExp}
*/
function makeRegExp(s) {
var re;
if (s.startsWith('/') && s.endsWith('/')) {
re = new RegExp(s.slice(1, s.length - 1));
} else {
var ref = s.replace(/\*/g, '.');
ref = ref.replace(/_/g, '.');
re = new RegExp(ref);
}
return re;
}
/**
* @ignore
*/
function setPageReload() {
var nb = document.querySelector('.navBarClass');
if (nb == null) return;
var nadc = nb.querySelector('.nonAnonDivClass');
if (nadc == null) return;
var lob = nadc.querySelector('button');
if (lob == null) return;
if (lob.onclick == null) lob.onclick = preparePageReload;
}
/**
* @ignoreµ
*/
function preparePageReload() {
var db = document.querySelector('mat-dialog-container');
if (db == null) return;
var bt = db.querySelector('button');
if (bt == null) return;
bt.onclick = pageReload;
}
/**
* @ignore
*/
function pageReload() {
setOptions(false);
}
/**
* click OK button programatically
*/
function clickOK() {
var elBiddingBox = document.querySelector(".biddingBoxClass");
if (elBiddingBox == null) return false;
elBiddingButtons = elBiddingBox.querySelectorAll(".biddingBoxButtonClass");
if (elBiddingButtons == null) return false;
if (elBiddingButtons.lebgth < 17) return false;
setTimeout(function () {
elBiddingButtons[16].click();
}, 300);
}
/**
* when OK button appears, click it promatically
*/
function confirmBid() {
var n = 0;
var t = setInterval(function () {
n++;
if (n > 100) clearInterval(t);
if (buttonOKvisible()) {
clearInterval(t);
if (trustedBid) {
clickOK();
}
}
}, 10);
}
/**
* @ignore
*/
function normalize(s) {
return elimine2Spaces(s.replace(/,+/g, ';')).trim();
}
// var version = chrome.runtime.getManifest().name + ' ' + chrome.runtime.getManifest().version;
var logText = version + '\n';
logText = logText + navigator.userAgent + '\n';
/**
* get main BBO panel div element
* @returns div element
*/
function getNavDiv() {
return document.getElementById('navDiv');
}
/**
* returns div element containing chat dialog
*/
function getChatDiv() {
return document.getElementById('chatDiv');
}
/**
* returns current BBO user-id
*/
function whoAmI() {
var nb = document.querySelector('.navBarClass');
if (nb == null) {
addLog('whoAmI .navBarClass not found');
return '';
}
var nt = document.querySelector('.nameTagClass');
if (nt == null) {
addLog('whoAmI .nameTagClass not found');
return '';
}
return (nt.textContent.trim().toLowerCase());
}
/**
* @ignore
*/
function myDirection() {
if ((nd = getNavDiv()) == null) return '';
var cs = nd.querySelector('.coverClass');
if (cs == null) return '';
var nd = cs.querySelectorAll('.nameDisplayClass');
if (nd == null) return '';
if (nd.length != 4) return '';
var dc = cs.querySelectorAll('.directionClass');
if (dc == null) return '';
if (dc.length != 4) return '';
var me = whoAmI();
if (me == '') return '';
for (var i = 0; i < 4; i++) {
if (nd[i].textContent.trim().toLowerCase() == me) {
return dc[i].textContent.trim();
}
} {
addLog(me + ' seat not found');
return '';
}
}
/**
* @ignore
*/
function addLog(txt) {
logText = logText + getNow(true) + ',' + txt + '\n';
}
/**
* @ignore
*/
function exportLogData() {
bboalertLog(version + "<br>" + (logText.split('\n').length - 1) + ' records exported');
writeToClipboard(logText);
}
/**
* @ignore
*/
var triggerDragAndDrop = function (selectorDrag, selectorDrop, dist) {
// function for triggering mouse events
var fireMouseEvent = function (type, elem, centerX, centerY) {
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent(type, true, true, window, 1, 1, 1, centerX, centerY, false, false, false, false, 0, elem);
elem.dispatchEvent(evt);
};
// fetch target elements
var elemDrag = document.querySelector(selectorDrag);
var elemDrop = document.querySelector(selectorDrop);
if (!elemDrag || !elemDrop) return false;
// calculate positions
var pos = elemDrag.getBoundingClientRect();
var center1X = Math.floor((pos.left + pos.right) / 2);
var center1Y = Math.floor((pos.top + pos.bottom) / 2);
pos = elemDrop.getBoundingClientRect();
var center2X = Math.floor((pos.left + pos.right) / 2) + dist;
var center2Y = Math.floor((pos.top + pos.bottom) / 2);
// mouse over dragged element and mousedown
fireMouseEvent('mousemove', elemDrag, center1X, center1Y);
fireMouseEvent('mouseenter', elemDrag, center1X, center1Y);
fireMouseEvent('mouseover', elemDrag, center1X, center1Y);
fireMouseEvent('mousedown', elemDrag, center1X, center1Y);
// start dragging process over to drop target
fireMouseEvent('dragstart', elemDrag, center1X, center1Y);
fireMouseEvent('drag', elemDrag, center1X, center1Y);
fireMouseEvent('mousemove', elemDrag, center1X, center1Y);
fireMouseEvent('drag', elemDrag, center2X, center2Y);
fireMouseEvent('mousemove', elemDrop, center2X, center2Y);
// trigger dragging process on top of drop target
fireMouseEvent('mouseenter', elemDrop, center2X, center2Y);
fireMouseEvent('dragenter', elemDrop, center2X, center2Y);
fireMouseEvent('mouseover', elemDrop, center2X, center2Y);
fireMouseEvent('dragover', elemDrop, center2X, center2Y);
// release dragged element on top of drop target
fireMouseEvent('drop', elemDrop, center2X, center2Y);
fireMouseEvent('dragend', elemDrag, center2X, center2Y);
fireMouseEvent('mouseup', elemDrag, center2X, center2Y);
return true;
};
/**
* @ignore
*/
function isUndoCommand(t) {
if (t.search('Undo') != -1) return true;
if (t.search('悔牌') != -1) return true;
if (t.search('Fortryd') != -1) return true;
if (t.search('Ακύρωση') != -1) return true;
if (t.search('Deshacer') != -1) return true;
if (t.search('בטל') != -1) return true;
if (t.search('Visszavonás') != -1) return true;
if (t.search('やり直す') != -1) return true;
if (t.search('Ongedaan maken') != -1) return true;
if (t.search('Angre') != -1) return true;
if (t.search('Cofnij') != -1) return true;
if (t.search('Desfazer') != -1) return true;
if (t.search('Cere înapoi') != -1) return true;
if (t.search('Geri al') != -1) return true;
if (t.search('Merusak') != -1) return true;
if (t.search('Zpět') != -1) return true;
if (t.search('Откат') != -1) return true;
if (t.search('Vraćanje') != -1) return true;
if (t.search('Pöydän asetukset') != -1) return true;
if (t.search('重來') != -1) return true;
if (t.search('Ångra') != -1) return true;
return false;
}
/**
* @ignore
*/
function isTable(t) {
if (t.search('→Table') != -1) return true;
if (t.search('→Маса') != -1) return true;
if (t.search('→牌 桌') != -1) return true;
if (t.search('→Bord') != -1) return true;
if (t.search('→Tisch') != -1) return true;
if (t.search('→Τραπέζι') != -1) return true;
if (t.search('→Table') != -1) return true;
if (t.search('→Asztal') != -1) return true;
if (t.search('→Tavolo') != -1) return true;
if (t.search('→テーブル') != -1) return true;
if (t.search('→Tafel') != -1) return true;
if (t.search('→Stół') != -1) return true;
if (t.search('→Mesa') != -1) return true;
if (t.search('→Masa') != -1) return true;
if (t.search('→Tabel') != -1) return true;
if (t.search('→Stůl') != -1) return true;
if (t.search('→Стол') != -1) return true;
if (t.search('→Stol') != -1) return true;
if (t.search('→Pöytä') != -1) return true;
if (t.search('→牌桌') != -1) return true;
return false;
}
/**
* @ignore
*/
function isOpponents(t) {
if (t.search('→Opponents') != -1) return true;
if (t.search('→Противници') != -1) return true;
if (t.search('→对手') != -1) return true;
if (t.search('→Modstandere') != -1) return true;
if (t.search('→Gegner') != -1) return true;
if (t.search('→Αντίπαλοι') != -1) return true;
if (t.search('→Oponentes') != -1) return true;
if (t.search('→Adversaires') != -1) return true;
if (t.search('→Ellenfelek') != -1) return true;
if (t.search('→Avversari') != -1) return true;
if (t.search('→対戦相手') != -1) return true;
if (t.search('→Tegenstanders') != -1) return true;
if (t.search('→Motstandere') != -1) return true;
if (t.search('→Przeciwnicy') != -1) return true;
if (t.search('→Adversários') != -1) return true;
if (t.search('→Adversari') != -1) return true;
if (t.search('→Rakipler') != -1) return true;
if (t.search('→Penentang') != -1) return true;
if (t.search('→Soupeři') != -1) return true;
if (t.search('→Оппоненты') != -1) return true;
if (t.search('→Protivnici') != -1) return true;
if (t.search('→Vastustajille') != -1) return true;
if (t.search('→Motståndare') != -1) return true;
return false;
}
/**
* generate UNDO menu command programmatically
*/
function undoCommand() {
if ((nd = getNavDiv()) == null) return;
var menu = nd.querySelector('.moreClass');
if (menu == null) return;
if (getContext() == '') return;
menu.click();
var n = 0;
var t = setInterval(function () {
var mc = document.querySelectorAll('.menuClass');
if (mc != null) {
for (var i = 0; i < mc.length; i++) {
for (var j = 0; j < mc[i].children.length; j++) {
if (isUndoCommand(mc[i].children[j].textContent)) {
clearInterval(t);
mc[i].children[j].firstChild.click();
return;
}
}
}
}
n++;
if (n == 10) clearInterval(t);
}, 100);
}
/**
* @ignore
*/
function setUndo() {
if ((nd = getNavDiv()) == null) return;
var cells = nd.querySelectorAll('.auctionBoxHeaderCellClass');
if (cells == null) return;
if (cells.length != 4) return;
if (cells[0].onclick == null) cells[0].onclick = undoCommand;
if (cells[1].onclick == null) cells[1].onclick = undoCommand;
if (cells[2].onclick == null) cells[2].onclick = undoCommand;
if (cells[3].onclick == null) cells[3].onclick = undoCommand;
}
/**
* @ignore
*/
function addBBOalertButton() {
if (document.getElementById('myButton') != null) return;
var b = document.createElement("button");
b.style.width = '100%';
b.style.height = '100%';
b.style.backgroundColor = 'blue';
b.textContent = 'Ale\nrt';
b.style.color = 'white';
b.style.display = 'block';
b.id = 'myButton';
b.style.zIndex = "1";
b.onclick = toggleOptions;
var cc = document.querySelector('.connectionClass');
for (var i = 0; i < cc.children.length; i++) cc.children[i].style.display = 'none';
cc.appendChild(b);
}
/**
* retrieve my direction from the auction box 'S' 'W' 'N' 'E' or '' if not found
*/
function mySeat() {
if ((nd = getNavDiv()) == null) return '';
var cells = nd.querySelectorAll('.auctionBoxHeaderCellClass');
if (cells == null) return '';
if (cells.length != 4) return '';
return cells[3].innerText.slice(0, 1);
}
/**
* retrieve our vulnerability tag
*/
function ourVulnerability() {
var vultab = ["", "NS", "EW", "NSEW", "NS", "EW", "NSEW", "", "EW", "NSEW", "", "NS", "NSEW", "", "NS", "EW"];
var sd = getDealNumber();
if (sd == '') return '';
var nd = parseInt(sd);
if (isNaN(nd)) return '';
if (nd < 1) return '';
nd = (nd - 1) % 16;
if (vultab[nd].includes(mySeat())) return '@v';
return '@n';
}
/**
* @ignore
*/
function openAccountTab() {
var vc = document.querySelectorAll('.verticalClass');
if (vc.length < 4) return false;
vc[3].click();
return true;
}
/**
* check if confirm bids switch is ON
* returns 'Y' 'N' or '' if not found
*/
function confirmBidsSet() {
var rd = document.getElementById('rightDiv');
if (rd == null) return '';
var sc = rd.querySelectorAll('.settingClass');
if (sc.length < 6) {
if (sc.length == 0) return '';
}
if (document.querySelectorAll('.settingClass')[4].querySelector('mat-slide-toggle').classList[2] == "mat-checked") return 'Y';
else return 'N';
}
/**
* return true if OK button is visible
*/
function buttonOKvisible() {
if ((nd = getNavDiv()) == null) return false;
var elBiddingBox = nd.querySelector(".biddingBoxClass");
if (elBiddingBox == null) return false;
elBiddingButtons = elBiddingBox.querySelectorAll(".biddingBoxButtonClass");
if (elBiddingButtons == null) return false;
if (elBiddingButtons.length < 17) return false;
return (elBiddingButtons[16].style.display != 'none');
}
/**
* toggle BBOalert panel display
*/
function toggleOptions() {
var adPanel0 = document.getElementById("adpanel0");
if (adPanel0 == null) return;
if (adPanel0.style.display == 'none') {
setOptions(true);
} else {
setOptions(false);
}
}
/**
* @ignore
*/
function toggleButtons(inp) {
if (!isSettingON(1)) return;
var ap2 = document.getElementById('adpanel2');
var btt = document.getElementById('bttab-buttons');
if (ap2 == null) return;
if (inp == null) return;
ap2.inputObject = inp;
ap2.display = !ap2.display;
if (ap2.display) {
var clr = "rgb(211,211,211";
ap2.children[0].style.backgroundColor = clr;
ap2.children[1].style.backgroundColor = clr;
ap2.children[2].style.backgroundColor = clr;
ap2.style.backgroundColor = clr;
btt.style.backgroundColor = clr;
btt.click();
return;
}
if (btt.openTab == "none") {
setTimeout(() => {
setOptionsOff();
}, 100);
return;
}
if (btt.openTab == "data") {
setTimeout(() => {
$("#bttab-bboalert")[0].click();
}, 100);
return;
}
if (btt.openTab == "options") {
setTimeout(() => {
$("#bttab-options")[0].click();
}, 100);
return;
}
if (btt.openTab == "buttons") {
setTimeout(() => {
$("#bttab-buttons")[0].click();
}, 100);
return;
}
if (btt.openTab == "info") {
setTimeout(() => {
$("#bttab-info")[0].click();
}, 100);
return;
}
}
/**
* @ignore
*/
function setExplainInputClickEvents() {
var ap2 = document.getElementById('"adpanel2"');
if (ap2.inputObject == null) return;
if (!isVisible(ap2.inputObject)) setButtonPanel(false);
}
/**
* @ignore
*/
function setChatInputClickEvents() {
var ap2 = document.getElementById('"adpanel2"');
if (ap2.inputObject == null) return;
if (!isVisible(ap2.inputObject)) setButtonPanel(false);
}
/**
* @ignore
*/
function setInputClickEvents() {
var ap2 = document.getElementById('adpanel2');
if (ap2.inputObject == null) return;
if (!isVisible(ap2.inputObject)) setButtonPanel(false);
}
/**
* @ignore
*/
function toggleOptions1() {
var adPanel0 = document.getElementById("adpanel0");
if (adPanel0 == null) return;
var ap2 = document.getElementById('adpanel2');
if (adPanel0.style.display != 'none') {
if (ap2 != null) {
if (ap2.style.display == 'none') {
ap2.style.display = 'block';
return;
} else {
ap2.style.display = 'none';
}
}
setOptions(false);
} else {
if (ap2 != null) {
ap2.style.display = 'none';
}
setOptions(true);
}
}
/**
* display BBOalert panel if on=true. Otherwise hide it
*/
function setOptions(on) {
var adPanel0 = document.getElementById("adpanel0");
if (adPanel0 == null) return;
if (on) {
adPanel0.style.display = 'block';
if (adPanel0.getBoundingClientRect().width < 250) {
triggerDragAndDrop('.hDividerClass', '.hDividerClass', (adPanel0.getBoundingClientRect().width) - 300);
}
} else {
adPanel0.style.display = 'none';
}
var b = document.getElementById('bboalert-tab');
if (b == null) return;
var t = b.querySelector('.verticalClass');
if (t == null) return;
if (on) {
t.style.backgroundColor = "green";
t.style.color = 'white';
} else {
t.style.backgroundColor = "rgb(209, 214, 221)";
t.style.color = 'black';
}
}
/**
* display button panel if on=true. Otherwise hide it
*/
function setButtonPanel(on) {
var adPanel2 = document.getElementById("adpanel2");
var adPanel0 = document.getElementById("adpanel0");
if (adPanel0 == null) return;
if (on) {
var b = document.querySelector('#bboalert-sc');
if (b != null) {
if (b.style.backgroundColor == "red") return;
}
// adPanel2.style.display = 'block';
// if (adPanel0.getBoundingClientRect().width < 250) {
// triggerDragAndDrop('.hDividerClass', '.hDividerClass', (adPanel0.getBoundingClientRect().width) - 300);
// }
setOptionsOn();
document.getElementById("bttab-buttons").click();
} else {
setOptionsOff();
// adPanel2.style.display = 'none';
// adPanel2.inputObject = null;
}
}
/**
* @ignore
*/
function addBBOalertTab() {
if (document.getElementById('bboalert-tab') != null) return;
var rd = document.getElementById('rightDiv');
if (rd == null) return;
var vt = rd.querySelector('.verticalTabBarClass');
if (vt == null) return;
tabs = vt.children;
if (tabs == null) return;
if (tabs.length < 2) return;
t = tabs[1].cloneNode(true);
t.querySelector('.verticalClass').textContent = 'BBOalert';
t.id = 'bboalert-tab';
t.onclick = toggleOptions;
t.style.color = 'white';
t.backgroundColor = 'red';
vt.appendChild(t);
t = document.getElementById('bboalert-tab');
t.onclick = toggleOptions;
}
/**
* @ignore
* match vulnerability and seat conditions in text
* @param {*} v
* @param {*} V
* @param {*} s
* @param {*} t
*/
function matchVulSeat(v, V, s, t) {
// set option only during the first round of bidding
if (s == '') return '';
// Check if seat dependence specified
if ((t.indexOf('@1') > 0) || (t.indexOf('@2') > 0) || (t.indexOf('@3') > 0) || (t.indexOf('@4') > 0)) {
if (t.indexOf(s) == -1) return 'N';
}
// Check if our vulnerability dependence specified
if ((t.indexOf('@n') > 0) || (t.indexOf('@v') > 0)) {
if (t.indexOf(v) == -1) return 'N';
}
// Check if their vulnerability dependence specified
if ((t.indexOf('@N') > 0) || (t.indexOf('@V') > 0)) {
if (t.indexOf(V) == -1) return 'N';
}
return 'Y';
}
/**
* Check if element e is visible
*/
function isVisible(e) {
if (e == null) return false;
if (e == undefined) return false;
return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
}
/**
* get formatted actual date and time
* if secs=true resultion up to seconds
*/
function getNow(secs) {
var now = new Date();
var yyyy = now.getFullYear().toString();
var m = now.getMonth() + 1;
var mm = m.toString();
if (mm.length == 1) mm = '0' + mm;
var dd = now.getDate().toString();
if (dd.length == 1) dd = '0' + dd;
var hh = now.getHours().toString();
if (hh.length == 1) hh = '0' + hh;
var mn = now.getMinutes().toString();
if (mn.length == 1) mn = '0' + mn;
if (!secs) return yyyy + mm + dd + "_" + hh + ":" + mn;
var ss = now.getSeconds().toString();
if (ss.length == 1) ss = '0' + ss;
return yyyy + mm + dd + "_" + hh + ":" + mn + ":" + ss;
}
/**
* elimine spaces and tabs from string str
*/
function elimine2Spaces(str) {
var s = str.replace(/\t+/g, ' ');
s = s.replace(/\u0020\u0020+/g, ' ');
return s;
}
// Elimine spaces and tabs
function elimineSpaces(str) {
var s = str.replace(/\s+/g, '');
s = s.replace(/\t+/g, '');
return s;
}
/**
* @ignore
*/
function readFromClipboard(callback) {
navigator.clipboard.readText().then((cbData) => {
callback(cbData);
});
}
/**
* copy string txt to the clipboard
*/
function writeToClipboard(txt) {
navigator.clipboard.writeText(txt).then(function () {}, function () {});
}
/**
* Strip context ctx from leading passes
*/
function stripContext(ctx) {
if (ctx.startsWith('------')) return ctx.substr(6);
if (ctx.startsWith('----')) return ctx.substr(4);
if (ctx.startsWith('--')) return ctx.substr(2);
return ctx;
}
/**
* @ignore
*/
function decodeOption(opt) {
if (opt.length != 2) return opt;
optText = '';
if (opt.slice(0, 1) == '1') optText = optText + '@1';
if (opt.slice(0, 1) == '2') optText = optText + '@2';
if (opt.slice(0, 1) == '3') optText = optText + '@3';
if (opt.slice(0, 1) == '4') optText = optText + '@4';
if (opt.slice(0, 1) == '5') optText = optText + '@1@2';
if (opt.slice(0, 1) == '6') optText = optText + '@3@4';
if (opt.slice(1, 2) == '1') optText = optText + '@n@N';
if (opt.slice(1, 2) == '2') optText = optText + '@v@N';
if (opt.slice(1, 2) == '3') optText = optText + '@n@V';
if (opt.slice(1, 2) == '4') optText = optText + '@v@V';
if (opt.slice(1, 2) == '5') optText = optText + '@n';
if (opt.slice(1, 2) == '6') optText = optText + '@v';
if (opt.slice(1, 2) == '7') optText = optText + '@N';
if (opt.slice(1, 2) == '8') optText = optText + '@V';
return optText;
}
/**
* @ignore
*/
function translateCall(call) {
if (call == 'D') return 'Db';
if (call == 'Dbl') return 'Db';
if (call == 'Ktr.') return 'Db';
if (call == 'Ktr') return 'Db';
if (call == 'ктр') return 'Db';
if (call == 'X') return 'Db';
if (call == 'Rktr') return 'Rd';
if (call == 'рктр') return 'Rd';
if (call == 'Rdbl') return 'Rd';
if (call == 'RD') return 'Rd';
if (call == 'XX') return 'Rd';
if (call == 'p') return '--';
if (call == 'P') return '--';
if (call == 'Pass') return '--';
if (call == 'Pas') return '--';
if (call == 'Paso') return '--';
if (call == 'пас') return '--';
el = call;
if (el.length > 1) {
el = el.substr(0, 2);
if (el.charCodeAt(1) == 9827) {
return el[0] + 'C';
}
if (el.charCodeAt(1) == 9830) {
return el[0] + 'D';
}
if (el.charCodeAt(1) == 9829) {
return el[0] + 'H';
}
if (el.charCodeAt(1) == 9824) {
return el[0] + 'S';
}
return el[0] + 'N';
}
return el;
}
/**
* get seat number tag of the openeer
*/
function getSeatNr() {
var c = getContext();
if (c.startsWith('------')) return '@4';
if (c.startsWith('----')) return '@3';
if (c.startsWith('--')) return '@2';
return '@1';
}
/**
* Get actual bidding context
*/
function getContext() {
if ((nd = getNavDiv()) == null) return '??';
ctx = '';
bs = nd.querySelectorAll('bridge-screen');
if (bs.length == 0) {
return "??";
}
auction = bs[0].querySelectorAll('.auctionBoxCellClass');
if (auction.length == 0) {
return "??";
}
if (auction.length == 1) {
return "";
}
for (var i = 1; i < auction.length; i++) {
el = translateCall(auction[i].innerText);
ctx = ctx + el;
// Translate Double, Redouble and Pass from different language interfaces
}
return ctx;
}
/**
* retrieve our vulnerability tag from the auction box
*/
function areWeVulnerable() {
if ((nd = getNavDiv()) == null) return '';
var cells = nd.querySelectorAll('.auctionBoxHeaderCellClass');
if (cells == null) return '';
if (cells.length != 4) return '';
if (cells[3].style.backgroundColor == "rgb(255, 255, 255)") return '@n';
return '@v';
}
/**
* retrieve opponent's vulnerability tag from the auction box
*/
function areTheyVulnerable() {
if ((nd = getNavDiv()) == null) return '';
var cells = nd.querySelectorAll('.auctionBoxHeaderCellClass');
if (cells == null) return '';
if (cells.length != 4) return '';
if (cells[2].style.backgroundColor == "rgb(255, 255, 255)") return '@N';
return '@V';
}
/**
* retrieve current board number
*/
function getDealNumber() {
if ((nd = getNavDiv()) == null) return '';
vpi = nd.querySelector('.vulPanelInnerPanelClass');
if (vpi == null) return '';
if (!isVisible(vpi)) return '';
return vpi.textContent.trim();
}
/**
* @ignore
*/
function setTitle(txt) {
t = document.querySelectorAll('div.titleSpanClass');
if (t.length == 0) return;
for (var i = 0; i < t.length; i++) {
t[i].textContent = txt;
}
}
/**
* @ignore
*/
function setTitleText(txt) {
t = document.querySelector('.titleClass');
if (t == null) return;
if (isVisible(t)) {
t.innerText = '';
setTimeout(function () {
t.innerText = txt;
}, 500);
return;
}
t = document.querySelectorAll('div.titleSpanClass');
if (t.length == 0) return;
for (var i = 0; i < t.length; i++) {
t[i].textContent = '';
setTimeout(function () {
t[i].textContent = txt;
}, 500);
}
}
/**
* @ignore
*/
function matchContextOld(refContext, actContext) {
if (refContext == actContext) return true;
if (refContext.length != actContext.length) return false;
for (var j = 0; j < refContext.length; j++) {
if (refContext.substr(j, 1) == '_') continue;
if (refContext.substr(j, 1) == '*') continue;
if (refContext.substr(j, 1) != actContext.substr(j, 1)) return false;
}
return true;
}
/**
* Check if actual bidding context matches refeence context from the table
*/
function matchContext(refContext, actContext) {
var re;
try {
if (refContext.startsWith('/') && refContext.endsWith('/')) {
re = new RegExp(refContext.slice(1, refContext.length - 1));
return re.test(actContext);
}
if (matchContextOld(refContext, actContext)) return true;