-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1497 lines (1380 loc) · 45.6 KB
/
index.html
File metadata and controls
1497 lines (1380 loc) · 45.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
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
<head>
<style>
* {
font-family: "Whitney", "Arial";
color: #fff;
user-select: none;
}
button,
input,
select,
option {
color: black;
}
p,
h1,
h2,
h3,
h4,
h5,
h6,
ul {
margin: 0px;
}
body {
background-color: #333;
margin: 0px;
padding: 0px;
min-height: 100%;
overflow: hidden;
}
::-webkit-scrollbar {
width: 2px;
height: 2px;
}
::-webkit-scrollbar-track {
background: #888;
}
::-webkit-scrollbar-thumb {
background: #666;
}
.topbar {
top: 0px;
width: 100%;
height: 30px;
background-color: #444;
margin: 0px;
padding: 0px;
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
transition: top 0.5s;
overflow-y: hidden;
}
#topbar {
position: fixed;
z-index: 2;
}
.titlebutton {
height: 30px;
min-width: 35px;
-webkit-app-region: no-drag;
text-align: center;
color: #eee;
font-size: 22px;
padding-left: 4px;
padding-right: 4px;
flex: none;
cursor: pointer;
}
.titlebutton:hover {
background-color: #333 !important;
}
.titlebutton.active {
background-color: #333;
}
.spacer {
/*margin-left:auto;*/
height: 30px;
flex-grow: 100;
scroll-behavior: smooth;
}
#grabbar {
-webkit-app-region: drag;
box-sizing: border-box;
font-size: 25px;
padding-top: 2px;
border-bottom: 3px #777 solid;
background-color: #333
}
.fa {
font-family: "Font Awesome 5 Free";
font-weight: 900;
padding-top: 5px;
font-size: 20px;
}
.mainbody {
position: fixed;
top: 30px;
width: 100%;
height: calc(100% - 30px);
transition: height 0.5s, top 0.5s;
}
.tab {
display: none;
top: 30px;
width: 100%;
height: 100%;
}
.tab.active {
display: block;
}
.settings {
display: none;
position: fixed;
width: 100%;
height: 100%;
z-index: 1;
background-color: rgba(51, 51, 51, 0.2);
}
.settings.active {
display: block;
}
.settingsbody {
position: fixed;
background-color: #666;
width: 50vw;
height: 70vh;
left: 25vw;
top: 5vh;
padding: 16px;
border-radius: 8px;
overflow-y: auto;
}
.updatedialog {
display: none;
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(51, 51, 51, 0.7);
z-index: 99999;
}
.updatedialog.active {
display: block;
}
.updatedialogbody {
position: fixed;
background-color: #666;
width: 26vw;
left: 37vw;
top: 45vh;
padding: 16px;
border-radius: 8px;
}
.changelog {
display: none;
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(51, 51, 51, 0.7);
z-index: 99999;
}
.changelog.active {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
}
.changelogbody {
background-color: #666;
padding: 16px;
max-width: 50vw;
border-radius: 8px;
}
.rolldownbtn {
position: fixed;
display: none;
top: 4px;
right: 370px;
z-index: 9999;
font-size: 32px;
color: #eee;
}
#topbar:hover {
top: 0px !important;
}
.buttoncontainer {
display: flex;
flex-flow: row wrap;
justify-content: center;
}
.button {
flex: 1 1 25%;
display: flex;
border-radius: 8px;
height: 40px;
margin: 4px;
padding: 4px;
background-color: #888;
cursor: pointer;
justify-content: center;
align-items: center;
font-size: 20px;
transition: background-color 0.1s;
}
.button:hover {
background-color: #aaa;
}
.dialogtext {
font-size: 20px;
margin-top: 0px;
margin-bottom: 8px;
}
.important {
background-color: rgb(156, 156, 0);
}
.tokenchange {
display: none;
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(51, 51, 51, 0.7);
z-index: 2;
}
.tokenchange.active {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
}
.tokenchangebody {
display: none;
background-color: #666;
padding: 16px;
border-radius: 8px;
}
.tokenchangebody.active {
display: block;
}
.tchinput {
width: 100%;
height: 40px;
margin-bottom: 5px;
padding: 4px;
font-size: 20px;
border-radius: 5px;
border: none;
}
.tabbtn-ctx {
display: none;
position: fixed;
background-color: #333333b3;
z-index: 90;
padding: 5px;
border: 3px solid #444;
}
.tabbtn-ctx-item {
padding: 0.3em 1.2em;
}
.tabbtn-ctx-item:hover {
background-color: #2c8df733;
cursor: pointer;
}
.ctxwrap {
display: flex;
flex-flow: column nowrap;
}
</style>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.4.2/css/all.css" crossorigin="anonymous" />
</head>
<div id="tabbtn-ctx" class="tabbtn-ctx">
<div class="ctxwrap">
<div class="tabbtn-ctx-item" onclick="ctxreload()">Reload</div>
<div class="tabbtn-ctx-item" onclick="ctxrename()">Rename</div>
<div class="tabbtn-ctx-item" onclick="ctxdelete()">Delete</div>
<div class="tabbtn-ctx-item" onclick="ctxinspect()">Open DevTools</div>
</div>
</div>
<body>
<div class="topbar" id="topbar">
<div class="topbar spacer" id="tabbuttons"></div>
<div class="titlebutton fa" id="grabbar" title="Drag the window from here.">

</div>
<div class="titlebutton fa" id="addtab" title="Create a new tab." onclick="addtab(false)">

</div>
<div class="titlebutton rollupbtn" title="Collapse the tab bar unless hovered" onclick="rollup()">
▲
</div>
<div class="titlebutton fa settingsbtn" title="Configure DTabs settings." onclick="settings()">

</div>
<div class="titlebutton" onclick="remote.getCurrentWindow().minimize()">
_
</div>
<div class="titlebutton fa far"
onclick="remote.getCurrentWindow().isMaximized() ? remote.getCurrentWindow().unmaximize() : remote.getCurrentWindow().maximize()">

</div>
<div class="titlebutton" onclick="remote.getCurrentWindow().destroy()">X</div>
</div>
<div class="settings">
<div class="settingsbody">
<h1>Global settings</h1>
<input id="injecttoggle" type="checkbox"
onclick="localStorage.setItem('injectcss',$('#injecttoggle').checked);setCssState($('#injecttoggle').checked)" />Inject
CSS
<button id="injectpath" onclick="csspath()">Select file</button>
<button id="injectpath" onclick="csspath(true)">Reload CSS</button><br />
<input id="baseuriinput" type="text" placeholder="https://discord.com" />
<button id="changebaseuri" onclick="changeBaseUri()">
Change Base URI</button><br />
<h1>Tab settings</h1>
<select id="tabselect"></select>
<button id="inspecttab" onclick="inspecttab()">Open Devtools</button><br />
<input id="tabbaseuriinput" type="text" placeholder="https://discord.com" />
<button id="changetabbaseuri" onclick="changeTabBaseUri()">
Change Tab Base URI
</button>
<button id="deletetab" onclick="deletetab()">Delete tab</button>
<br />
<input id="locktabs" type="checkbox"
onclick="localStorage.setItem('tablock',$('#locktabs').checked);lockTabs($('#locktabs').checked)" />Lock
tabs
<h1>Analytics</h1>
Analytics shares some usage data about your usage of DTabs.<br />
If disabled, NO data will be sent (none).<br />
If enabled, you may configure the amount of data you wish to share with
the analytics server.<br />
By default, no identifying data will be reported, however, you may choose
to share this data if you wish.<br />
<br />
For any questions or concerns, please contact me
<u><a href="javascript:void(0);"
onclick="require('electron').shell.openExternal('https:\/\/craftxbox.com/contact')">HERE</a></u><br />
<input type="checkbox" id="analytics.enableTotally" onclick="toggleAnalytics('totally')" />Enable
Analytics<br />
<h3>Forced On (only when Analytics ON):</h3>
<input type="checkbox" disabled checked value="meta.system.unique" />Share
Unique ID (unidentifiable)<br />
<input type="checkbox" disabled checked value="dtabs.version" />Share
DTabs Version
<h3>
On by default:<button onclick="analyticsToggleAll('dfon',false)">
All Off</button><button onclick="analyticsToggleAll('dfon',true)">All On</button>
</h3>
<div id="dfon">
<input type="checkbox" id="meta.system.os" checked onclick="toggleAnalytics('meta.system.os')" />Share
System OS<br />
<input type="checkbox" id="dtabs.css.enabled" checked
onclick="toggleAnalytics('dtabs.css.enabled')" />Share CSS Injections status<br />
<input type="checkbox" id="dtabs.base.changed" checked
onclick="toggleAnalytics('dtabs.base.changed')" />Share Base URI changed status<br />
<input type="checkbox" id="dtabs.base.tabs.anychanged" checked
onclick="toggleAnalytics('dtabs.base.tabs.anychanged')" />Share Tab Base URIs changed status<br />
<input type="checkbox" id="dtabs.tabs.count" checked
onclick="toggleAnalytics('dtabs.tabs.count')" />Share Tab count<br />
<input type="checkbox" id="dtabs.tabs.rolledup" checked
onclick="toggleAnalytics('dtabs.tabs.rolledup')" />Share Tab Bar Rolled Up Status<br />
<input type="checkbox" id="dtabs.tabs.locked" checked
onclick="toggleAnalytics('dtabs.tabs.locked')" />Share Tab Bar Locked Status<br />
</div>
<div id="dfoff">
<h3>
Off by default:<button onclick="analyticsToggleAll('dfoff',false)">
All Off</button><button onclick="analyticsToggleAll('dfoff',true)">All On</button>
</h3>
<input type="checkbox" id="dtabs.base.uri" onclick="toggleAnalytics('dtabs.base.uri')" />Share Global
Base URI<br />
<input type="checkbox" id="dtabs.tabs.all.base" onclick="toggleAnalytics('dtabs.tabs.all.base')" />Share
Tab Base URIs<br />
</div>
</div>
</div>
<div class="updatedialog">
<div class="updatedialogbody">
<p class="dialogtext">
An update for DTabs is available, would you like to apply it?
</p>
<div class="buttoncontainer">
<div class="button" onclick="update()">
<p>Yes</p>
</div>
<div class="button" onclick="dismissupdate(false)">
<p>No</p>
</div>
<div class="button" onclick="dismissupdate(true)">
<p>Never</p>
</div>
</div>
</div>
</div>
<div class="changelog">
<div class="changelogbody">
<h1>Changelog</h1>
DTabs has been updated to Version 11!<br />
<br />
<table>
<tr>
<td>[NEW]</td>
<td>Right-Click menu for tabs in the tab bar, Reload and rename tabs with ease!</td>
</tr>
<tr>
<td>[FIX]</td>
<td>The tab bar no longer collapses itself on startup when the window isn't maximized yet.</td>
</tr>
<tr>
<td>[FIX]</td>
<td>Fixed username "#0" population on accounts with new non-discriminated usernames.</td>
</tr>
<tr>
<td>[IMPR]</td>
<td>More visually appealing and concise icons.</td>
</tr>
<tr>
<td>[IMPR]</td>
<td>Electron updated for compatibility and security.</td>
</tr>
<tr>
<td>[IMPR]</td>
<td>Auto-Downgrade and security warning for those with old versions of Electron</td>
</tr>
</table>
<br />
<br />
<h2>Older changes from v10</h2>
<table>
<tr class="important">
<td>[NEW]</td>
<td>Analytics reporting, Disable and/or configure this in the Settings menu.</td>
</tr>
<tr>
<td>[NEW]</td>
<td>Scrolling tabs, now you can scroll tabs with the mouse wheel if there are too many.</td>
</tr>
<tr>
<td>[NEW]</td>
<td>New login flow, No longer polls discord by default.</td>
</tr>
<tr>
<td>[NEW]</td>
<td>Added Token-Change flow, which engages whenever your credentials change.</td>
</tr>
<tr>
<td>[NEW]</td>
<td>Window drag handle, indicated by <span class="fa" id="grabbar"></span> and a light grey
underline.
</td>
</tr>
<tr>
<td>[FIX]</td>
<td>Fixed a bug with the autoupdater in versions 9 and below.</td>
</tr>
<tr>
<td>[FIX]</td>
<td>Fixed video streams. You can now view streams from other people, aswell as share your camera.
</td>
</tr>
<tr>
<td>[FIX]</td>
<td>Fixed being unable to roll-down tabs when unmaximized.</td>
</tr>
<tr>
<td>[FIX]</td>
<td>Tab Roll-up is now unavailable where it would be impractical.</td>
</tr>
<tr>
<td>[IMPR]</td>
<td>Improved internal credential structure</td>
</tr>
<tr>
<td>[IMPR]</td>
<td>Improved auto updater for more granular updates.</td>
</tr>
</table>
<br />
<div class="buttoncontainer">
<div class="button" onclick="$`.changelog`.classList.remove('active');">
<p>OK</p>
</div>
</div>
</div>
</div>
<div class="tokenchange">
<div class="tokenchangebody" id="tchmain">
<p class="dialogtext">
DTabs detected a credential change on <b id="tokenchangetab"></b>.<br>
Have you made a change to your account?<br>
</p>
<div class="buttoncontainer">
<div class="button"
onclick="tchrelogorpwch(); $`#tchmain`.classList.remove('active'); $`#tchrelogorpwch`.classList.add('active');">
<p>I logged out and back in</p>
</div>
<div class="button"
onclick="tchrelogorpwch(); $`#tchmain`.classList.remove('active'); $`#tchrelogorpwch`.classList.add('active');">
<p>I changed my password</p>
</div>
<div class="button"
onclick="$`#tchmain`.classList.remove('active'); $`#tchswitch`.classList.add('active');">
<p>I switched accounts</p>
</div>
<div class="button"
onclick="$`#tchmain`.classList.remove('active'); $`#tchusernoaction`.classList.add('active');">
<p>No, I didn't</p>
</div>
<div class="button"
onclick="$`#tchmain`.classList.remove('active'); $`#tchignore`.classList.add('active');">
<p>Ignore Change</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="tchrelogorpwch">
<p class="dialogtext">
Got it, your new credentials have been saved.
</p>
<div class="buttoncontainer">
<div class="button"
onclick="tokenChangeState = null;$`.tokenchange`.classList.remove('active'); $`#tchrelogorpwch`.classList.remove('active');">
<p>OK</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="tchswitch">
<p class="dialogtext">
You indicated you have <b class="important">Switched Accounts</b> on this tab.<br>
<span class="important">Autofill will make a single automated request to discord servers</span><br>
How would you like to proceed?
</p>
<div class="buttoncontainer">
<div class="button"
onclick="$`#tchswitch`.classList.remove('active'); $`#tchrename`.classList.add('active');">
<p>Rename & Save</p>
</div>
<div class="button"
onclick="tchautofill(); $`#tchswitch`.classList.remove('active'); $`#tchrelogorpwch`.classList.add('active');">
<p>Autofill & Save</p>
</div>
<div class="button"
onclick="tokenChangeState = null;$`.tokenchange`.classList.remove('active'); $`#tchswitch`.classList.remove('active');">
<p>Don't save</p>
</div>
<div class="button"
onclick="$`#tchmain`.classList.add('active'); $`#tchswitch`.classList.remove('active');">
<p>I made a mistake</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="tchusernoaction">
<p class="dialogtext">
Something's wrong here, You have indicated <b class="important">No changes</b> to your account<br>
<span class="important">Resolving the conflict will make automated two automated requests to discord
servers.</span><br>
You may have been logged out, Ignoring this may cause this tab to fail to restore in the future.
</p>
<div class="buttoncontainer">
<div class="button" onclick="tchresolve();">
<p>Resolve Conflict</p>
</div>
<div class="button"
onclick="tokenChangeState = null;$`.tokenchange`.classList.remove('active'); $`#tchusernoaction`.classList.remove('active');">
<p>Ignore Change</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="tchignore">
<p class="dialogtext">
Are you sure you want to ignore this change?<br>
You may have to re-login to this tab later.
</p>
<div class="buttoncontainer">
<div class="button"
onclick="tokenChangeState = null;$`.tokenchange`.classList.remove('active'); $`#tchignore`.classList.remove('active');">
<p>Yes</p>
</div>
<div class="button"
onclick="$`#tchmain`.classList.add('active'); $`#tchignore`.classList.remove('active');">
<p>No</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="tchnewtabsetup">
<p class="dialogtext">
Tab login is complete! Would you like to name this tab or fill your username automatically?
<span class="important">Autofill will make a single automated request to discord servers</span>
</p>
<div class="buttoncontainer">
<div class="button"
onclick="$`#tchnewtabsetup`.classList.remove('active'); $`#tchrename`.classList.add('active');">
<p>Rename Manually</p>
</div>
<div class="button"
onclick="tchautofill(); $`#tchnewtabsetup`.classList.remove('active'); $`#tchrelogorpwch`.classList.add('active');">
<p>Autofill Info</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="tchrename">
<p class="dialogtext">
What would you like to name this tab?
</p>
<input type="text" class="tchinput" id="tchrenameinput" placeholder="Tab Name">
<div class="buttoncontainer">
<div class="button" onclick="tchrename();">
<p>Save</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="ctxrename">
<p class="dialogtext">
What would you like to name this tab?
</p>
<input type="text" class="tchinput" id="ctxrenameinput" placeholder="Tab Name">
<div class="buttoncontainer">
<div class="button" onclick="ctxrename(true);">
<p>Save</p>
</div>
</div>
</div>
<div class="tokenchangebody" id="tchresolve">
Let's figure out what's going on here.<br>
Select correct account below, or the Right button if they are the same.
<div class="buttoncontainer">
<div class="button" id="tchresolveold">
<p>Loading...</p>
</div>
<div class="button" id="tchresolvenew">
<p>Loading...</p>
</div>
</div>
</div>
</div>
<div class="mainbody"></div>
</body>
<script src="https://unpkg.com/axios@0.27.2/dist/axios.min.js"></script>
<script>
// VERSION=99;
const VERSION = "VERSION2=11.0;";
// This probably looks super weird, but, only change VERSION2. The simple explanation to why this is required is that versions <=9 have a broken version checker.
// Anyone who had v9 is permanently stuck on v9 unless they reinstall... whoops.
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const process = require("process");
var instance = axios.create({
validateStatus: (a) => {
return true;
},
});
//Mainjs version check.
//Starting in v11 the minimum supported electron version is likely 16+
//Older versions shipped with electron 10, which will cause a crash with this new code.
//This section serves to kill the app before it crashes, and to inform the user to update.
let firstUA = navigator.userAgent
let uamatch = firstUA.match(/Electron\/(\d+)/)
if (uamatch && uamatch[1] < 16) {
const { dialog } = require("electron").remote
dialog.showMessageBox({
message: `ERROR: DTabs MainJS/Electron is too old (${uamatch[1]} but expected 16). We'll try to revert you to the last supported version, but DTabs is likely to be unstable and insecure!\n\nPlease update DTabs to the latest version.`,
type: "error",
title: "DTabs: STARTUP ERROR"
})
let lastlegacyuri = "https://raw.githubusercontent.com/craftxbox/DTabs/legacy-reverts/v10.html"
instance.get(lastlegacyuri).then(function (response) {
if (response.status != 200) {
alert("DTabs was unable to revert. Please reinstall.");
return;
}
updatecontents = response.data;
fs.renameSync(path.resolve(__dirname, "index.html"), path.resolve(__dirname, "index.html.OLD-" + Date.now()));
fs.writeFileSync(path.resolve(__dirname, "index.html"), updatecontents, "utf8");
alert("DTabs has reverted to the last available legacy version. DTabs will now exit.");
require("electron").remote.getCurrentWindow().close()
});
}
const remote = require("@electron/remote")
var baseuri = localStorage.getItem("baseuri") || "https://discord.com";
let tokenChangeState = null;
let tokenChangeQueue = [];
$`#tabbuttons`.addEventListener("wheel", (event) => {
let target = $`#tabbuttons`;
const toLeft = event.deltaY < 0 && target.scrollLeft > 0;
const toRight = event.deltaY > 0 && target.scrollLeft < target.scrollWidth - target.clientWidth;
if (toLeft || toRight) {
event.preventDefault();
target.scrollLeft += event.deltaY;
}
});
var bWindow = remote.BrowserWindow.getFocusedWindow();
if (localStorage.getItem("uniqueId") == null) {
//probably the dumbest line of code i have ever written.
localStorage.setItem("uniqueId", crypto.createHash("sha256").update(crypto.randomBytes(1024)).digest("hex"));
}
function onresize() {
bWindow = remote.getCurrentWindow()
if (!bWindow.isMaximized()) {
//force rolled down when unmaximized
$`.rollupbtn`.style = "display:none";
$`#topbar`.style = "top:0px;";
$`.mainbody`.style = "top:30px;";
} else {
$`.rollupbtn`.style = "display:block";
if (localStorage.getItem("rolledup") == "true") {
$`#topbar`.style = "top:-27px;";
$`.mainbody`.style = "height: 100%; top:3px;";
} else {
$`#topbar`.style = "top:0px;";
$`.mainbody`.style = "top:30px;";
}
}
}
window.addEventListener("resize", () => {
onresize();
});
onresize();
// this is the file we get to check for updates. Change this if you're forking, otherwise you're just going to be autoupdating against the downstream :)
const indexHtmlFileGitRawUrl = "https://raw.githubusercontent.com/craftxbox/DTabs/master/index.html";
let tabtokens = {};
let csskeys = {};
$`#injecttoggle`.checked = localStorage.getItem("injectcss") == "true";
$`#locktabs`.checked = localStorage.getItem("tablock") == "true";
$`#injectpath`.textContent = localStorage.getItem("csspath") || "Select file";
lockTabs(localStorage.getItem("tablock") == "true");
function lockTabs(lock) {
if (lock) {
$`#addtab`.style = "display:none;";
$`#deletetab`.style = "display:none;";
} else {
$`#addtab`.style = "display:block;";
$`#deletetab`.style = "display:block;";
}
updateAnalytics();
}
function rollup() {
$`#topbar`.style = "top:-27px;";
$`.rollupbtn`.setAttribute("onclick", "rolldown()");
$`.rollupbtn`.textContent = "▼";
$`.mainbody`.style = "height: 100%; top:3px;";
localStorage.setItem("rolledup", true);
updateAnalytics();
}
function rolldown() {
$`#topbar`.style = "top:0px;";
$`.rollupbtn`.setAttribute("onclick", "rollup()");
$`.rollupbtn`.textContent = "▲";
$`.mainbody`.style = "top:30px;";
localStorage.setItem("rolledup", false);
updateAnalytics();
}
function settings() {
$`#tabselect`.innerHTML = "";
for (var i of $("#tabbuttons").children) {
if (i.classList.length < 2) continue;
if (i.classList[1] == "settingsbtn" || i.classList[1] == "rollupbtn") continue;
var sel = document.createElement("option");
sel.setAttribute("value", i.classList[2]);
sel.textContent = i.innerHTML;
$`#tabselect`.appendChild(sel);
}
if ($`.settings.active` != null) {
$`.settingsbtn`.classList.remove("active");
$`.settings`.classList.remove("active");
return;
}
$`.settingsbtn`.classList.add("active");
$`.settings`.classList.add("active");
}
//autoupdater
setInterval(updatecheck, 10800000);
var updatecontents = "";
var checkdisabled = false;
var verregex = /VERSION2=(\d+)(?:\.(\d+))?;/;
var oldverregex = /VERSION=(\d+);/;
let tabctx;
//only major changes trigger changelog. Minor changes will only be bugfixes anyways.
if (localStorage.getItem("lastVersion") == null ||
parseInt(localStorage.getItem("lastVersion").match(verregex)[1]) < parseInt(VERSION.match(verregex)[1])) {
localStorage.setItem("lastVersion", VERSION);
$`.changelog`.classList.add("active");
}
function updateAnalytics() {
if (_paq == null) return;
if (localStorage.getItem("analytics.meta.system.os") !== "false")
_paq.push([
"setCustomDimension",
(customDimensionId = 3),
(customDimensionValue = process.platform),
]);
if (localStorage.getItem("analytics.dtabs.css.enabled") !== "false")
_paq.push([
"setCustomDimension",
(customDimensionId = 5),
(customDimensionValue = localStorage.getItem("injectcss")),
]);
if (localStorage.getItem("analytics.dtabs.base.changed") !== "false")
_paq.push([
"setCustomDimension",
(customDimensionId = 6),
(customDimensionValue = (localStorage.getItem("baseuri") || "https://discord.com") != "https://discord.com"),
]);
if (localStorage.getItem("analytics.dtabs.base.tabs.anychanged") !== "false") {
if (Object.keys(tabtokens).length <= 1) return; //tabtokens aren't loaded yet
let anyChanged = false;
for (var i of Object.values(tabtokens)) {
if (i.baseuri != "https://discord.com") {
anyChanged = true;
break;
}
}
_paq.push(["setCustomDimension", (customDimensionId = 7), (customDimensionValue = anyChanged)]);
}
if (localStorage.getItem("analytics.dtabs.tabs.count") !== "false") {
if (Object.keys(tabtokens).length <= 1) return; //tabtokens aren't loaded yet
_paq.push([
"setCustomDimension",
(customDimensionId = 8),
(customDimensionValue = Object.keys(tabtokens).length - 1),
]);
}
if (localStorage.getItem("analytics.dtabs.tabs.rolledup") !== "false")
_paq.push([
"setCustomDimension",
(customDimensionId = 9),
(customDimensionValue = localStorage.getItem("rolledup")),
]);
if (localStorage.getItem("analytics.dtabs.tabs.locked") !== "false")
_paq.push([
"setCustomDimension",
(customDimensionId = 4),
(customDimensionValue = localStorage.getItem("tablock")),
]);
if (localStorage.getItem("analytics.dtabs.base.uri") === "true")
_paq.push([
"setCustomDimension",
(customDimensionId = 10),
(customDimensionValue = localStorage.getItem("baseuri") || "default"),
]);
if (localStorage.getItem("analytics.dtabs.tabs.all.base") === "true") {
if (Object.keys(tabtokens).length <= 1) return; //tabtokens aren't loaded yet
let bases = [];
for (var i of Object.values(tabtokens)) {
bases.push(i.baseuri);
}
_paq.push(["setCustomDimension", (customDimensionId = 11), (customDimensionValue = JSON.stringify(bases))]);
}
_paq.push(["trackEvent", "analytics", "update"]);
}
//dont even bother loading matomo if we already opted out.
if (localStorage.getItem("analytics.enableTotally") !== "false") {
var _paq = (window._paq = window._paq || []);
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setCustomDimension", (customDimensionId = 2), (customDimensionValue = VERSION)]);
_paq.push(["forgetUserOptOut"]); //If you opt out this code should never run, but it should if you ever opt back in
updateAnalytics();
_paq.push(["setUserId", localStorage.getItem("uniqueId")]);
_paq.push(["trackPageView"]);
_paq.push(["enableHeartBeatTimer", 1200]);
(function () {
var u = "https://crxb.cc/protected/matomo/";
_paq.push(["setTrackerUrl", u + "matomo.php"]);
_paq.push(["setSiteId", "1"]);
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0];
g.type = "text/javascript";
g.async = true;
g.src = u + "matomo.js";
s.parentNode.insertBefore(g, s);
})();
let analyticsKeys = Object.keys({ ...localStorage }).filter((i) => i.startsWith("analytics."));
console.log(analyticsKeys);
$`#analytics\\.enableTotally`.setAttribute("checked", localStorage.getItem("analytics.enableTotally") !== "false");
for (var i of analyticsKeys) {
if (localStorage.getItem(i) === "true") {
let element = $(`#${i.split("analytics.")[1].replaceAll(".", "\\.")}`)
if (!element) {
console.log(`No element for analytics key ${i}, this data point has likely been removed.`);
continue;
};
element.setAttribute("checked", true);
}
else if (localStorage.getItem(i) === "false") {
let element = $(`#${i.split("analytics.")[1].replaceAll(".", "\\.")}`)
if (!element) {
console.log(`No element for analytics key ${i}, this data point has likely been removed.`);
continue;
};
element.removeAttribute("checked");
}
}
}
function toggleAnalytics(path) {
if (path == "totally") {
if (localStorage.getItem("analytics.enableTotally") !== "false") {
localStorage.setItem("analytics.enableTotally", false);
_paq.push(["optUserOut"]);
} else {
localStorage.setItem("analytics.enableTotally", true);
alert("Analytics will be enabled at next restart. Thank you for your support.");
}
return;
} else {
if (localStorage.getItem(`analytics.${path}`) !== "false" /*true by default*/)
localStorage.setItem(`analytics.${path}`, false);
else if (localStorage.getItem(`analytics.${path}`) === "false") localStorage.setItem(`analytics.${path}`, true);
}
updateAnalytics();
}
function analyticsToggleAll(domain, to) {
let analyticsKeys = [...$$(`#${domain} input`)].map((i) => i.id);
for (var i of analyticsKeys) {
localStorage.setItem(`analytics.${i}`, to);
}
updateAnalytics();
}
function updatecheck(noprompt) {
if (checkdisabled) return;
instance.get(indexHtmlFileGitRawUrl).then(function (response) {
if (response.status != 200 && !checkdisabled) {
checkdisabled = true;
alert("DTabs was unable to check for updates!");
return;
}
updatecontents = response.data;
if (!verregex.test(updatecontents)) {