-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscrounger.html
1052 lines (1050 loc) · 50 KB
/
scrounger.html
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
<!DOCTYPE html>
<html>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<title>Session History Scrounger for Firefox (with lz4 support) — Fx File Utilities</title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<nav>
<ul>
<li id="logo">Fx File Utilities</li>
<li><span id="current">Session History</span></li>
<li><a href="bookbackreader.html" title="Save JSON or Export HTML from bookmark backup files">Bookmark Backup</a></li>
<li><a href="searchjson.html" title="Read out search engine details">Search Engines</a></li>
<li><a href="extensionsjson.html" title="Read out extension details">Extensions</a></li>
</ul>
</nav>
<header>
<h1>Session History Scrounger for Firefox</h1>
</header>
<article>
<div id="main">
<p><em>Firefox creates various session history files as you browse, and then at shutdown creates sessionstore.jsonlz4. In Firefox 56+, the files are compressed using Mozilla's flavor of LZ4 compression (.jsonlz4 or .baklz4 file extension). The JSON data contains rich detail about your session, but this page is targeted toward extracting just the page URLs.</em></p>
<h2>Step 1: Load File</h2>
<p>Drag and drop one session history file onto the empty text box<span> (<button onclick="document.getElementById('sesshelp').style.display='block'; this.parentNode.style.display='none';">HELP</button>)</span>, or use the Browse... button on the right. This file is not sent to the network, it is only read within this page in Firefox.</p>
<div id="sesshelp" style="display:none; background-color:#ffc; padding:0 1em; border:1px solid #333; margin-bottom:1em;">
<p>This tool can read URLs out of the following types of session history files:</p>
<ul>
<li>Firefox 56+ compressed files such as recovery.jsonlz4 or previous.jsonlz4 from: [profile]\sessionstore-backups</li>
<li>Firefox 45-55 uncompressed files such as recovery.js or previous.js from: [profile]\sessionstore-backups</li>
<li>Session Manager 2.x .session files stored from: [profile]\sessions</li>
<li>Tab Session Manager "storage.js" file from: [profile]\browser-extension-data\Tab-Session-Manager@sienori (cannot be converted to a native Firefox sessionstore.js-format file)</li>
<li>Session Boss "storage.js" file from: [profile]\browser-extension-data\[email protected] (cannot be converted to a native Firefox sessionstore.js-format file)</li>
<li>OneTab "storage.js" file from: [profile]\browser-extension-data\[email protected] (cannot be converted to a native Firefox sessionstore.js-format file)</li>
</ul>
<p>If you are unfamiliar with how to locate your [profile] folder, please see: <a href="https://support.mozilla.org/kb/profiles-where-firefox-stores-user-data" target="_blank">Profiles - Where Firefox stores your bookmarks, passwords and other user data</a> on Mozilla Support.</p>
</div>
<div id="uploaddiv">
<textarea id="drop_zone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event);" style="width:80%" autocomplete="false" placeholder="Drop file here"></textarea>
<div style="position:absolute; right:0; top:0; width:calc(20% - 18px); cursor: pointer;" onclick="document.querySelector('#btnBrowse').click();" ;>
<p style="margin-top:2em; text-align:center;">Or open using: <br><br><input type="file" id="btnBrowse" onchange="loadFile(this);" style="width: 80px"></p>
</div>
</div>
<p><em>Note: To scrounge a different file, reload this page (Windows: Ctrl+r. Mac: Command+r). Or click the reload button in the address bar.</em></p>
<h2>Step 2: Extract URLs / Save Session Links</h2>
<p id="scrounge_options"><strong>HTML list options:</strong> <label><input type="checkbox" id="chkCWins" checked> Include Closed Windows</label> <label><input type="checkbox" id="chkCTabs"
checked> Include Closed Tabs</label> <label><input type="checkbox" id="chkBFH" checked> Include Back-Forward History</label><br>
<em>Possibly buggy:</em> <label><input type="checkbox" id="chkEmb"> Expand Embedded Sessions</label></p>
<p><strong>HTML list commands:</strong> <button onclick="parsejson(false)" id="btnScrounge" disabled>Scrounge URLs</button> (<em>Fallback:</em> <button onclick="parsejson(true)" id="btnDumblist" disabled>Unstructured URL list</button>) <button onclick="SaveList()" id="btnSave" disabled>Save List</button></p>
<p><strong>JSON file:</strong> <button onclick="SaveJSON()" id="btnJSON" disabled>Save Uncompressed JSON (sessionstore.js format)</button> <button onclick="SaveJSONEmbed()" id="btnEmbed" disabled>Save Embedded Session (first found only)</button> <button onclick="SaveJSONText()" id="btnText" disabled>Save Uncompressed JSON as text</button></p>
<p><strong>Troubleshooting:</strong> If turning off options doesn't make this latest version work, try the archival "old logic" version at <a href="scrounger_old.html">scrounger_old.html</a>.</p>
<div id="output" style="border-top:2px solid #000;">
<style type="text/css">
.bhtoggle {cursor: pointer;}
.bhtoggle:hover::after {
content: " {click to toggle display}";
color: blue;
}
.backhist {margin-left: 2.25em}
.backhist>div {display: none;}
.urllist>p>span {font-size: 0.75em;}
</style>
<script type="text/javascript">
function toggleBH(el) {
var tgtdiv = el.nextElementSibling;
if (tgtdiv.style.display != 'block') tgtdiv.style.display = 'block';
else tgtdiv.style.display = '';
}
</script>
<p class="attrib">Extracted using <a href="https://www.jeffersonscher.com/ffu/scrounger.html">https://www.jeffersonscher.com/ffu/scrounger.html</a></p>
</div>
</div><!-- #main -->
</article>
<footer>
<p>Copyright © 2024 Jefferson Scher (<a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause License</a>).
lz4.js © 2016 Pierre Curto (<a href="https://github.com/pierrec/node-lz4/blob/master/LICENSE">MIT License</a>; <a href="https://github.com/pierrec/node-lz4/tree/8b0027e08cb5d486e212b18b906d76a43f740f88/build">Sept. 1, 2016</a>).
FileSaver.js © 2016 Eli Grey (<a href="https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md">MIT License</a>; <a href="https://github.com/eligrey/FileSaver.js/tree/1.3.2">v1.3.2</a>).
MDN code samples © Mozilla Contributors or Public Domain (<a href="https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses">License</a>).
No claim to your data! Updated 2024-07-20. (<a href="scrounger_previous.html">Previous Version</a>; <a href="scrounger_20180826.html">Older Logic</a>)</p>
</footer>
<script type="text/javascript">
// Compatibility check
if (typeof (window.TextDecoder) !== 'function') {
var p1 = document.createElement('p');
p1.setAttribute('style', 'border:3px solid red; padding:12px 30px;');
p1.innerHTML = 'Unfortunately, this tool does not work in your current browser. Sorry. Please try Firefox, Chrome, Chromium or Opera instead. <br>' +
'(IE and Edge do not support <a href="https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder#Browser_compatibility">TextDecoder</a>. ' +
'IE also does not support <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Browser_compatibility">TypedArray.slice()</a>; unclear whether Edge or Safari supports it.)';
document.body.insertBefore(p1, document.body.firstChild);
}
// Clean up form controls on reload (i.e., not bypassing cache)
document.getElementById('drop_zone').value = '';
document.getElementById('btnScrounge').setAttribute('disabled', 'disabled');
document.getElementById('btnDumblist').setAttribute('disabled', 'disabled');
document.getElementById('btnSave').setAttribute('disabled', 'disabled');
document.getElementById('btnJSON').setAttribute('disabled', 'disabled');
document.getElementById('btnEmbed').setAttribute('disabled', 'disabled');
document.getElementById('btnText').setAttribute('disabled', 'disabled');
// Functions used in the page
function parsejson(blnDumblist) {
if (document.getElementById('scrounged')) {
if (!confirm('Remove previous list of windows and tabs now?')) return;
document.getElementById('scrounged').remove();
if (document.getElementById('msgproc')) document.getElementById('msgproc').remove();
}
var txt = document.getElementById('drop_zone');
if (txt.value.length > 0) {
document.getElementById('btnScrounge').setAttribute('disabled', 'disabled');
document.getElementById('btnDumblist').setAttribute('disabled', 'disabled');
document.getElementById('btnScrounge').insertAdjacentHTML('afterend', ' <span id="msgproc" style="font-style:italic">Processing...</span> ');
if (txt.value.indexOf('{"sessions":') === 0 && txt.value.indexOf('{"tabs":[') < 0) buildTSMList(txt);
else if (txt.value.indexOf('{"backupSessionStore":') === 0) buildSBossList(txt);
else if (txt.value.indexOf('{"state":"{\\"tabGroups\\":') === 0) buildOneTabList(txt);
else if (blnDumblist) buildURLList(txt);
else {
try {
var oSess = JSON.parse(txt.value);
} catch (err) {
console.log(err);
oSess = null;
}
if (oSess != null) {
//console.log('Calling buildListJSON()');
buildListJSON(oSess, true);
} else {
//console.log('Calling buildList()');
buildList(txt);
}
}
}
else alert('Session history file contents could not be read?');
}
function scrub(t) {
if (t.indexOf('data:') == 0 || t.indexOf('view-source:data:') == 0) return 'data-URI';
t = t.replace(/&/g, '&'); t = t.replace(/>/g, '>'); t = t.replace(/</g, '<');
return t;
}
var cleanQuotes = function (string) {
return string.replace(/\\"/g, '"');
}
var outJ = new Array();
function buildListJSON(obj, outer) {
//console.log('buildListJSON running');
if (outer === true) {
var finfo = document.querySelectorAll('#fileinfo span');
document.getElementById('output').insertAdjacentHTML('afterbegin', '\n<div id="scrounged"><h1 style="margin-bottom:0;">Session History</h1>\n<p style="margin-top:0;"><em>Extracted from</em> ' + finfo[0].textContent + ' <em>as of</em> ' + finfo[1].textContent + '.</p>\n</div>');
} else {
outJ.push('<div style="margin-left:2.25em; border-left: 3px double green; padding-left: 12px;">\n<h1><em>Embedded Session</em></h1>');
}
var blnCTabs = document.getElementById('chkCTabs').checked;
var blnCWins = document.getElementById('chkCWins').checked;
var blnBFH = document.getElementById('chkBFH').checked;
var blnEmb = document.getElementById('chkEmb').checked;
var winds, tabs, taburls, i, j, k, last, eSess, page = 0, tabcount = 0, txtPrivate = '';
// Current session open windows array
winds = obj.windows;
for (i = 0; i < winds.length; i++) {
if (i == 0) outJ.push('<div>\n <h2>Open Windows</h2>');
if (winds[i].isPrivate) txtPrivate = ' (Private)';
else txtPrivate = '';
outJ.push(' <h3 style=\'border-bottom:1px solid #000\'>Open Window ' + (i + 1) + txtPrivate + '</h3>\n <div style=\'margin-left:2.25em\'>');
// Current window open tabs array
tabs = winds[i].tabs;
for (j = 0; j < tabs.length; j++) {
//console.log('Window '+ (i+1) + ' Tab ' + (j+1));
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].hasOwnProperty('userContextId') && tabs[j].userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].userContextId + ']';
} else txtPrivate = '';
}
outJ.push(' <h4>Tab ' + (j + 1) + txtPrivate + '</h4>\n <div class=\'urllist\'>');
tabcount++;
// Current tab back-forward URLs array
taburls = tabs[j].entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].index - 1, 1);
last[0]['last'] = tabs[j].lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n <div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
outJ.push(' </div><!--End Tab-->');
// Got an embedded session? iterate!
if (blnEmb && last[0].url === 'about:sessionrestore') {
try {
eSess = tabs[j].formdata.id.sessionData;
if (eSess) buildListJSON(eSess, false);
} catch (err) { }
}
}
outJ.push(' </div><!--End Open Tabs-->');
// Current window closed tabs array
tabs = winds[i]._closedTabs;
for (j = 0; j < tabs.length; j++) {
if (j == 0) outJ.push(' <div style=\'margin-left:2.25em\'><h4 style=\'border-top:1px solid #888\'>(Closed Tabs)</h4>');
if (blnCTabs) {
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].state.hasOwnProperty('userContextId') && tabs[j].state.userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].state.userContextId + ']';
} else txtPrivate = '';
}
outJ.push(' <h4>Closed Tab ' + (j + 1) + txtPrivate + '</h4>\n <div class=\'urllist\'>');
// Current tab back-forward URLs array
taburls = tabs[j].state.entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].state.index - 1, 1);
last[0]['last'] = tabs[j].state.lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n <div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
outJ.push(' </div><!--End Tab-->');
// Got an embedded session? iterate!
if (blnEmb && last[0].url === 'about:sessionrestore') {
try {
eSess = tabs[j].formdata.id.sessionData;
if (eSess) buildListJSON(eSess, false);
} catch (err) { }
}
} else {
if (j == 0) outJ.push('<p>(Skipping ' + tabs.length + ' tabs)</p>');
}
}
if (tabs.length > 0) outJ.push(' </div><!--End Closed Tabs-->');
}
if (winds.length > 0) outJ.push('</div><!--End Open Windows-->');
// Current session closed windows array
try {
winds = obj._closedWindows;
} catch (err) {
winds = [];
}
for (i = 0; i < winds.length; i++) {
if (i == 0) outJ.push('<div>\n<h2>Closed Windows</h2>');
if (blnCWins) {
outJ.push(' <h3 style=\'border-bottom:1px solid #000\'>Closed Window ' + (i + 1) + '</h3>\n <div style=\'margin-left:2.25em\'>');
// Current window open tabs array
tabs = winds[i].tabs;
for (j = 0; j < tabs.length; j++) {
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].hasOwnProperty('userContextId') && tabs[j].userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].userContextId + ']';
} else txtPrivate = '';
}
outJ.push(' <h4>Tab ' + (j + 1) + txtPrivate + '</h4>\n <div class=\'urllist\'>');
tabcount++;
// Current tab back-forward URLs array
taburls = tabs[j].entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].index - 1, 1);
last[0]['last'] = tabs[j].lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n <div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
outJ.push(' </div><!--End Tab-->');
}
outJ.push(' </div><!--End Open Tabs-->');
// Current window closed tabs array
tabs = winds[i]._closedTabs;
for (j = 0; j < tabs.length; j++) {
if (j == 0) outJ.push(' <div style=\'margin-left:2.25em\'><h4 style=\'border-top:1px solid #888\'>(Closed Tabs)</h4>');
if (blnCTabs) {
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].state.hasOwnProperty('userContextId') && tabs[j].state.userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].state.userContextId + ']';
} else txtPrivate = '';
}
outJ.push(' <h4>Closed Tab ' + (j + 1) + txtPrivate + '</h4>\n <div class=\'urllist\'>');
tabcount++;
// Current tab back-forward URLs array
taburls = tabs[j].state.entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].state.index - 1, 1);
last[0]['last'] = tabs[j].state.lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n <div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
outJ.push(' </div><!--End Tab-->');
} else {
if (j == 0) outJ.push('<p>(Skipping ' + tabs.length + ' tabs)</p>');
}
}
if (tabs.length > 0) outJ.push(' </div><!--End Closed Tabs-->');
} else {
if (i == 0) outJ.push('<p>(Skipping ' + winds.length + ' windows)</p>');
}
}
if (winds.length > 0) outJ.push('</div><!--End Closed Windows-->');
// Last session open windows array
try {
winds = obj.lastSessionState.windows;
} catch (err) {
winds = [];
}
for (i = 0; i < winds.length; i++) {
if (i == 0) outJ.push('<h2 style=\'border-top:1px solid #888\'>Tabs from "Last Session State"</h2>\n<div>\n<h2>Open Windows</h2>');
outJ.push('<h3 style=\'border-bottom:1px solid #000\'>Open Window ' + (i + 1) + '</h3>\n<div style=\'margin-left:2.25em\'>');
// Current window open tabs array
tabs = winds[i].tabs;
for (j = 0; j < tabs.length; j++) {
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].hasOwnProperty('userContextId') && tabs[j].userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].userContextId + ']';
} else txtPrivate = '';
}
outJ.push(' <h4>Tab ' + (j + 1) + txtPrivate + '</h4>\n <div class=\'urllist\'>');
tabcount++;
// Current tab back-forward URLs array
taburls = tabs[j].entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].index - 1, 1);
last[0]['last'] = tabs[j].lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n<div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
outJ.push('</div>');
}
outJ.push('</div>');
// Current window closed tabs array
tabs = winds[i]._closedTabs;
for (j = 0; j < tabs.length; j++) {
if (j == 0) outJ.push('<div style=\'margin-left:2.25em\'><h4 style=\'border-top:1px solid #888\'>(Closed Tabs)</h4>');
if (blnCTabs) {
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].state.hasOwnProperty('userContextId') && tabs[j].state.userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].state.userContextId + ']';
} else txtPrivate = '';
}
outJ.push('<h4>Closed Tab ' + (j + 1) + txtPrivate + '</h4>\n<div class=\'urllist\'>');
// Current tab back-forward URLs array
taburls = tabs[j].state.entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].state.index - 1, 1);
last[0]['last'] = tabs[j].state.lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n<div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
} else {
if (j == 0) outJ.push('<p>(Skipping ' + tabs.length + ' tabs)</p>');
}
outJ.push('</div>');
}
outJ.push('</div>');
}
if (winds.length > 0) outJ.push('</div>');
// Last session closed windows array
try {
winds = obj.lastSessionState._closedWindows;
} catch (err) {
winds = [];
}
for (i = 0; i < winds.length; i++) {
if (i == 0) outJ.push('<div>\n<h2>Closed Windows</h2>');
if (blnCWins) {
outJ.push('<h3 style=\'border-bottom:1px solid #000\'>Closed Window ' + (i + 1) + '</h3>\n<div style=\'margin-left:2.25em\'>');
// Current window open tabs array
tabs = winds[i].tabs;
for (j = 0; j < tabs.length; j++) {
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].hasOwnProperty('userContextId') && tabs[j].userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].userContextId + ']';
} else txtPrivate = '';
}
outJ.push(' <h4>Tab ' + (j + 1) + txtPrivate + '</h4>\n <div class=\'urllist\'>');
tabcount++;
// Current tab back-forward URLs array
taburls = tabs[j].entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].index - 1, 1);
last[0]['last'] = tabs[j].lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n<div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
outJ.push('</div>');
}
outJ.push('</div>');
// Current window closed tabs array
tabs = winds[i]._closedTabs;
for (j = 0; j < tabs.length; j++) {
if (j == 0) outJ.push('<div style=\'margin-left:2.25em\'><h4 style=\'border-top:1px solid #888\'>(Closed Tabs)</h4>');
if (blnCTabs) {
if (txtPrivate.length == 0 && tabs[j].isPrivate) txtPrivate = ' (Private)';
else {
if (tabs[j].state.hasOwnProperty('userContextId') && tabs[j].state.userContextId != 0) {
txtPrivate = ' [Container ID ' + tabs[j].state.userContextId + ']';
} else txtPrivate = '';
}
outJ.push('<h4>Closed Tab ' + (j + 1) + txtPrivate + '</h4>\n<div class=\'urllist\'>');
tabcount++;
// Current tab back-forward URLs array
taburls = tabs[j].state.entries.slice();
//console.log('Tab ' + (j+1) + "; taburls.length=" + taburls.length);
// Output indexed page
last = taburls.splice(tabs[j].state.index - 1, 1);
last[0]['last'] = tabs[j].state.lastAccessed;
pushentry(last[0]);
page++;
if (blnBFH) {
// Output other pages, if any
if (taburls.length > 0) {
taburls.reverse();
for (k = 0; k < taburls.length; k++) {
if (k == 0) outJ.push(' <div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back-Forward History:</span>\n<div>');
pushentry(taburls[k]);
page++;
if (k == (taburls.length - 1)) outJ.push(' </div>\n </div>');
}
}
}
} else {
if (j == 0) outJ.push('<p>(Skipping ' + tabs.length + ' tabs)</p>');
}
outJ.push('</div>');
}
} else {
if (i == 0) outJ.push('<p>(Skipping ' + winds.length + ' windows)</p>');
}
outJ.push('</div>');
}
if (winds.length > 0) outJ.push('</div>');
//console.log('buildListJSON tab count=' + tabcount + ' and page count=' + page);
if (outer === true) {
flush();
document.getElementById('msgproc').insertAdjacentHTML('beforeend', '<span style="font-style:italic">done!</span> ');
document.getElementById('btnSave').removeAttribute('disabled');
} else {
outJ.push('<!--End Session--></div>');
}
}
function pushentry(oEntry) {
var strURL = oEntry.url;
var strTitle = oEntry.title || '[Title Not Available]';
if (strTitle.length == 0) strTitle = '[Title Not Available]';
if (oEntry.hasOwnProperty('last')) {
try {
var d = new Date(0);
d.setUTCSeconds((oEntry.last / 1000));
var strCurrent = ' <span>[' + d.toLocaleString() + ']</span>';
} catch(err){
strCurrent = '';
}
} else strCurrent = '';
outJ.push(' <p><strong>' + cleanQuotes(scrub(strTitle)) + '</strong>' + strCurrent + '<br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>');
}
function flush() {
//console.log(outJ.join('\n'));
document.getElementById('scrounged').insertAdjacentHTML('beforeend', outJ.join('\n'));
outJ = [];
}
function buildList(inp) {
var out = new Array();
var inpval = inp.value, sess, n, windows, i, wtabs, m, tabs, j, strTemp, taburl, k, strURL, strTitle, tabcount = 0, page = 0;
var arrSess = inpval.split('"lastSessionState":{"version":[');
sess = arrSess[0].split('"_closedWindows":[');
for (n = 0; n < sess.length; n++) {
winds = sess[n].split('{"tabs":[');
if (n == 0) {
out.push('<h2>Open Windows</h2>');
} else {
if (winds.length > 1) out.push('<h2>Closed Windows</h2>');
}
for (i = 1; i < winds.length; i++) {
if (n == 1) out.push('<h3 style=\'border-bottom:1px solid #000\'>Closed Window ' + i + '</h3>\n<div style=\'margin-left:2.25em\'>');
else out.push('<h3 style=\'border-bottom:1px solid #000\'>Open Window ' + i + '</h3>\n<div style=\'margin-left:2.25em\'>');
wtabs = winds[i].split('"_closedTabs":[');
for (m = 0; m < wtabs.length; m++) {
tabs = wtabs[m].split('{"entries":[');
for (j = 1; j < tabs.length; j++) {
if (m == 1 && j == 1) out.push('<div style=\'margin-left:2.25em\'><h4 style=\'border-top:1px solid #888\'>(Closed Tabs)</h4>');
out.push('<h4>Tab ' + j + '</h4>\n<div class=\'urllist\'>');
tabcount++;
strTemp = tabs[j].split(',"children":[')[0]; // ignore children
taburls = strTemp.split('{"url":"');
for (k = taburls.length - 1; k >= 1; k--) {
strURL = taburls[k].substr(0, taburls[k].indexOf('","'));
strTitle = taburls[k].split('"title":"')[1] || '[Title Not Available]';
strTitle = strTitle.substr(0, strTitle.indexOf('","'));
if (strTitle.length == 0) strTitle = '[Title Not Available]';
if (k == taburls.length - 2) out.push('<div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back <em>(earlier pages visited in this tab)</em>:</span>\n<div>');
out.push('<p><strong>' + cleanQuotes(scrub(strTitle)) + '</strong><br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>');
page++;
if (taburls.length > 2 && k == 1) out.push('</div></div>');
}
out.push('</div>');
}
out.push('</div>');
}
}
}
if (arrSess.length > 1) {
sess = arrSess[1].split('"_closedWindows":[');
for (n = 0; n < sess.length; n++) {
winds = sess[n].split('{"tabs":[');
if (n == 0) {
out.push('<h2 style=\'border-top:1px solid #888\'>Tabs from "Last Session State"</h2>');
out.push('<h2>Open Windows</h2>');
} else {
if (winds.length > 1) out.push('<h2>Closed Windows</h2>');
}
for (i = 1; i < winds.length; i++) {
if (n == 1) out.push('<h3 style=\'border-bottom:1px solid #000\'>Closed Window ' + i + '</h3>\n<div style=\'margin-left:2.25em\'>');
else out.push('<h3 style=\'border-bottom:1px solid #000\'>Open Window ' + i + '</h3>\n<div style=\'margin-left:2.25em\'>');
wtabs = winds[i].split('"_closedTabs":[');
for (m = 0; m < wtabs.length; m++) {
tabs = wtabs[m].split('{"entries":[');
for (j = 1; j < tabs.length; j++) {
if (m == 1 && j == 1) out.push('<div style=\'margin-left:2.25em\'><h4 style=\'border-top:1px solid #888\'>(Closed Tabs)</h4>');
out.push('<h4>Tab ' + j + '</h4>\n<div class=\'urllist\'>');
tabcount++;
strTemp = tabs[j].split(',"children":[')[0]; // ignore children
taburls = strTemp.split('{"url":"');
for (k = taburls.length - 1; k >= 1; k--) {
strURL = taburls[k].substr(0, taburls[k].indexOf('","'));
strTitle = taburls[k].split('"title":"')[1] || '[Title Not Available]';
strTitle = strTitle.substr(0, strTitle.indexOf('","'));
if (strTitle.length == 0) strTitle = '[Title Not Available]';
if (k == taburls.length - 2) out.push('<div class=\'backhist\'><span class=\'bhtoggle\' onclick=\'toggleBH(this);\'>← Back <em>(earlier pages visited in this tab)</em>:</span>\n<div>');
out.push('<p><strong>' + cleanQuotes(scrub(strTitle)) + '</strong><br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>');
page++;
if (taburls.length > 2 && k == 1) out.push('</div></div>');
}
out.push('</div>');
}
out.push('</div>');
}
}
}
}
var elOut = document.getElementById('output');
var finfo = document.querySelectorAll('#fileinfo span');
elOut.insertAdjacentHTML('afterbegin', '\n<div id="scrounged"><h1 style="margin-bottom:0;">Session History</h1>\n<p style="margin-top:0;"><em>Extracted from</em> ' + finfo[0].textContent + ' <em>as of</em> ' + finfo[1].textContent + '.</p>\n' + out.join('\n') + '\n</div><!--hi-->');
document.getElementById('msgproc').insertAdjacentHTML('beforeend', '<span style="font-style:italic">done!</span> ');
document.getElementById('btnSave').removeAttribute('disabled');
//console.log('buildList tab count=' + tabcount + ' and page count=' + page);
}
function buildTSMList(inp) {
//console.log('buildTSMList running');
var out = new Array();
var inpval = inp.value;
var sess = inpval.split('{"windows":');
for (var n = 1; n < sess.length; n++) {
var namesplit = sess[n].split(',"name":"');
if (namesplit.length === 2) {
out.push('<h2>Session ' + n + ': ' + namesplit[1].substr(0, namesplit[1].indexOf('","')) + '</h2>');
} else {
out.push('<h2>Session ' + n + '</h2>');
}
var tabs = namesplit[0].split(',"windowId":');
out.push('<div style=\'margin-left:2.25em\'>');
for (var j = 1; j < tabs.length; j++) {
out.push('<h4>Tab ' + j + '</h4>\n<div class=\'urllist\'>');
var strTemp = tabs[j];
var taburl = strTemp.split(',"url":"');
if (taburl.length === 2) {
strURL = taburl[1].substr(0, taburl[1].indexOf('","'));
var tabtitle = strTemp.split(',"title":"');
if (tabtitle.length === 2) {
strTitle = tabtitle[1].substr(0, tabtitle[1].indexOf('","')) || tabtitle[1].substr(0, tabtitle[1].indexOf('"}}'));
} else {
strTitle = '[Title Not Available]';
}
out.push('<p><strong>' + cleanQuotes(scrub(strTitle)) + '</strong><br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>');
} else {
out.push('<p>URL not found</p>');
}
out.push('</div>');
}
out.push('</div>');
}
var elOut = document.getElementById('output');
var finfo = document.querySelectorAll('#fileinfo span');
elOut.insertAdjacentHTML('afterbegin', '\n<div id="scrounged"><h1 style="margin-bottom:0;">Session Boss History</h1>\n<p style="margin-top:0;"><em>Extracted from</em> ' + finfo[0].textContent + ' <em>as of</em> ' + finfo[1].textContent + '.</p>\n' + out.join('\n') + '\n</div><!--hi-->');
document.getElementById('msgproc').insertAdjacentHTML('beforeend', '<span style="font-style:italic">done!</span> ');
document.getElementById('btnSave').removeAttribute('disabled');
}
function buildSBossList(inp) {
//console.log('buildSBossList running');
var out = new Array();
var inpval = inp.value;
var types = inpval.split('{"userSessions":[');
for (var t = types.length - 1; t >= 0; t--) {
if (t == 0) out.push('<h2>Automatic Backups</h2>');
if (t == 1) out.push('<h2>User-Saved Sessions</h2>');
var sess = types[t].split('"sessionName":"');
for (var n = 1; n < sess.length; n++) {
var namesplit = sess[n].split('","windows":');
if (namesplit.length === 2) {
out.push('<h3>Session ' + n + ': ' + namesplit[0] + '</h3>');
} else {
out.push('<h3>Session ' + n + '</h3>');
}
var tabslists = sess[n].split('"tabsOfWindow":{')[1];
var pretabmap = tabslists.split('"tabMap":{')[0];
var tabs = pretabmap.split('"url":"');
out.push('<div style=\'margin-left:2.25em\'>');
for (var j = 1; j < tabs.length; j++) {
out.push('<h4>Tab ' + j + '</h4>\n<div class=\'urllist\'>');
var strTemp = tabs[j];
var taburl = strTemp.split('","title":');
if (taburl.length === 2) {
strURL = taburl[0];
var tabtitle = strTemp.split(',"title":"');
if (tabtitle.length === 2) {
strTitle = tabtitle[1].substr(0, tabtitle[1].indexOf('","')) || tabtitle[1].substr(0, tabtitle[1].indexOf('"}}'));
} else {
strTitle = '[Title Not Available]';
}
out.push('<p><strong>' + cleanQuotes(scrub(strTitle)) + '</strong><br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>');
} else {
out.push('<p>URL not found?</p>');
}
out.push('</div>');
}
out.push('</div>');
}
}
var elOut = document.getElementById('output');
var finfo = document.querySelectorAll('#fileinfo span');
elOut.insertAdjacentHTML('afterbegin', '\n<div id="scrounged"><h1 style="margin-bottom:0;">Tab Session Manager History</h1>\n<p style="margin-top:0;"><em>Extracted from</em> ' + finfo[0].textContent + ' <em>as of</em> ' + finfo[1].textContent + '.</p>\n' + out.join('\n') + '\n</div><!--hi-->');
document.getElementById('msgproc').insertAdjacentHTML('beforeend', '<span style="font-style:italic">done!</span> ');
document.getElementById('btnSave').removeAttribute('disabled');
}
function buildOneTabList(inp) {
//console.log('buildOneTabList running');
var out = new Array();
var inpval = inp.value;
var sess = inpval.split('\\"tabsMeta\\":');
for (var n = 1; n < sess.length; n++) {
var namesplit = sess[n - 1].split(',\\"label\\":\\"');
if (namesplit.length === 2) {
out.push('<h2>Tab Group ' + n + ': ' + namesplit[1].substr(0, namesplit[1].indexOf('\\"')) + '</h2>');
} else {
out.push('<h2>Tab Group ' + n + '</h2>');
}
var tabs = sess[n].split(',\\"url\\":\\"');
out.push('<div style=\'margin-left:2.25em\'>');
for (var j = 1; j < tabs.length; j++) {
out.push('<h4>Tab ' + j + '</h4>\n<div class=\'urllist\'>');
var strTemp = tabs[j];
var strURL = strTemp.substr(0, strTemp.indexOf('\\",'));
var tabtitle = strTemp.split(',\\"title\\":\\"');
if (tabtitle.length === 2) {
strTitle = tabtitle[1].substr(0, tabtitle[1].indexOf('\\"}'));
} else {
strTitle = '[Title Not Available]';
}
out.push('<p><strong>' + cleanQuotes(scrub(strTitle)) + '</strong><br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>');
out.push('</div>');
}
out.push('</div>');
}
var elOut = document.getElementById('output');
var finfo = document.querySelectorAll('#fileinfo span');
elOut.insertAdjacentHTML('afterbegin', '\n<div id="scrounged"><h1 style="margin-bottom:0;">OneTab Tab Gropus</h1>\n<p style="margin-top:0;"><em>Extracted from</em> ' + finfo[0].textContent + ' <em>as of</em> ' + finfo[1].textContent + '.</p>\n' + out.join('\n') + '\n</div><!--hi-->');
document.getElementById('msgproc').insertAdjacentHTML('beforeend', '<span style="font-style:italic">done!</span> ');
document.getElementById('btnSave').removeAttribute('disabled');
}
function buildURLList(inp) {
//console.log('buildURLList running');
var out = new Array();
var taburls = inp.value.split('{"url":"'), k, strURL, strTitle;
out.push('<div class=\'urllist\'>');
for (k = taburls.length - 1; k >= 1; k--) {
strURL = taburls[k].substr(0, taburls[k].indexOf('","'));
strTitle = taburls[k].split('"title":"')[1] || '[Title Not Available]';
strTitle = strTitle.substr(0, strTitle.indexOf('","'));
if (strTitle.length == 0) strTitle = '[Title Not Available]';
out.push('<p><strong>' + cleanQuotes(scrub(strTitle)) + '</strong><br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>');
}
out.push('</div>');
var elOut = document.getElementById('output');
var finfo = document.querySelectorAll('#fileinfo span');
elOut.insertAdjacentHTML('afterbegin', '\n<div id="scrounged"><h1 style="margin-bottom:0;">Session History (Unstructured URL List)</h1>\n<p style="margin-top:0;"><em>Extracted from</em> ' + finfo[0].textContent + ' <em>as of</em> ' + finfo[1].textContent + '.</p>\n' + out.join('\n') + '\n</div><!--hi-->');
document.getElementById('msgproc').insertAdjacentHTML('beforeend', '<span style="font-style:italic">done!</span> ');
document.getElementById('btnSave').removeAttribute('disabled');
}
function SaveList() {
var fn = document.querySelectorAll('#fileinfo span')[0].textContent;
saveAs(
new Blob(
['<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Extracted Session History</title></head><body>' + document.getElementById('output').innerHTML + '</body></html>']
, { type: 'text/html;charset=UTF-8' }
)
, 'sessionhist(' + fn.replace(/\./g, '_') + ').html'
);
}
function CreateShortcut() {
saveAs(
new Blob(
['[InternetShortcut]\nURL=' + location.href]
, { type: 'application/x-ms-shortcut' }
)
, document.title + '.url'
);
}
function readfile(f) {
// Add notation below textarea
if (document.getElementById('fileinfo')) document.getElementById('fileinfo').remove();
document.getElementById('drop_zone').insertAdjacentHTML('afterend', '<p id="fileinfo">File name: <span>' + f.name + '</span>; Size: ' + f.size + '; last modified <span>' + new Date(f.lastModified).toLocaleString() + '</span></p>');
// Use a FileReader to pull the contents out of the file and drop it into the textarea element
var reader = new FileReader();
reader.onload = function (evt) { // handle result of the file read
if (typeof evt.target.result == 'string') document.getElementById('drop_zone').value = evt.target.result;
else {
let utf8decoder = new TextDecoder('utf-8');
var jsontxt = utf8decoder.decode(decomp(evt.target.result));
document.getElementById('drop_zone').value = jsontxt;
}
};
// Assume anything without .jsonlz4 or .baklz4 in the name is uncompressed
if (f.name.indexOf('.jsonlz4') == -1 && f.name.indexOf('.baklz4') == -1) reader.readAsText(f);
else reader.readAsArrayBuffer(f);
}
function decomp(arrbuff) {
// See: https://github.com/pierrec/node-lz4
// Create typed array from ArrayBuffer
var u8arrbuff = new Uint8Array(arrbuff);
// Is it a standard JSON file with jsonlz4 somewhere in its name?
if ('{' == String.fromCharCode(u8arrbuff[0])) {
return u8arrbuff;
}
// Compute uncompressed data size
var u8sz = u8arrbuff.slice(8, 12);
var origLen = u8sz[0] + (u8sz[1] * 256) + (u8sz[2] * 256 * 256) + (u8sz[3] * 256 * 256 * 256);
// Extract compressed data (past header)
jsonstart = 12;
var u8comp = u8arrbuff.slice(jsonstart);
// Create LZ4 buffer
var Buffer = require('buffer').Buffer;
var LZ4 = require('lz4');
var comp = new Buffer(u8comp);
var orig = new Buffer(origLen);
// Do the deed
var decomLen = LZ4.decodeBlock(comp, orig);
return orig.slice(0, decomLen);
}
function SaveJSON() {
// Check the JSON
var txt = document.getElementById('drop_zone').value;
if (txt.length === 0 || txt.indexOf('{') === -1) {
alert('Contents of the box do not look like JSON');
return;
}
if (txt.indexOf('{"sessions":') === 0 && txt.indexOf('{"tabs":[') < 0) {
alert('Contents of the box look like a Tab Session Manager storage.js file.\n\nCurrently unable to convert to Firefox\'s native format.');
return;
}
if (txt.indexOf('{"backupSessionStore":') === 0) {
alert('Contents of the box look like a Session Boss storage.js file.\n\nCurrently unable to convert to Firefox\'s native format.');
return;
}
if (txt.indexOf('{"state":"{\\"tabGroups\\":') === 0) {
alert('Contents of the box look like a OneTab storage.js file.\n\nCurrently unable to convert to Firefox\'s native format.');
return;
}
if (txt.indexOf('[SessionManager v2]') === 0) {
txt = txt.substr(txt.indexOf('{'));
}
try {
var oSess = JSON.parse(txt);
// Make blob and trigger save dialog
var fn = document.querySelectorAll('#fileinfo span')[0].textContent;
saveAs(
new Blob(
[JSON.stringify(oSess)]
, { type: 'application/json;charset=UTF-8' }
), 'sessionstore(' + fn.replace(/\./g, '_') + ').json'
);
} catch (err) {
alert('Not saving due to failure parsing JSON: ' + err.toString());
}
}
function SaveJSONEmbed() {
// Check the JSON
var txt = document.getElementById('drop_zone').value;
if (txt.length === 0 || txt.indexOf('{') === -1) {
alert('Contents of the box do not look like JSON');
return;
}
if (txt.indexOf('{"sessions":') === 0 && txt.indexOf('{"tabs":[') < 0) {
alert('Contents of the box look like a Tab Session Manager storage.js file.\n\nCurrently unable to convert to Firefox\'s native format.');
return;
}
if (txt.indexOf('{"backupSessionStore":') === 0) {
alert('Contents of the box look like a Session Boss storage.js file.\n\nCurrently unable to convert to Firefox\'s native format.');
return;
}
if (txt.indexOf('{"state":"{\\"tabGroups\\":') === 0) {
alert('Contents of the box look like a OneTab storage.js file.\n\nCurrently unable to convert to Firefox\'s native format.');
return;
}
if (txt.indexOf('[SessionManager v2]') === 0) {
txt = txt.substr(txt.indexOf('{'));
}
try {
var oSess = JSON.parse(txt);
// Iterate until we find the first embedded session
var winds, tabs, taburls, i, j, last, eSess = null;
// Current session open windows only
winds = oSess.windows;
eSessSearch:
for (i = 0; i < winds.length; i++) {
// Open tabs
tabs = winds[i].tabs;
for (j = 0; j < tabs.length; j++) {
taburls = tabs[j].entries.slice();
last = taburls.splice(tabs[j].index - 1, 1);
if (last[0].url === 'about:sessionrestore') {
try {
eSess = tabs[j].formdata.id.sessionData;
if (eSess) break eSessSearch;
} catch (err) { }
}
}
// Closed tabs
tabs = winds[i]._closedTabs;
for (j = 0; j < tabs.length; j++) {
taburls = tabs[j].state.entries.slice();
last = taburls.splice(tabs[j].state.index - 1, 1);
if (last[0].url === 'about:sessionrestore') {
try {
eSess = tabs[j].formdata.id.sessionData;
if (eSess) buildListJSON(eSess, false);
} catch (err) { }
}
}
}
if (eSess != null) {
// Make blob and trigger save dialog
var fn = document.querySelectorAll('#fileinfo span')[0].textContent;
saveAs(
new Blob(
[JSON.stringify(eSess)]
, { type: 'application/json;charset=UTF-8' }
), 'sessionstore(' + fn.replace(/\./g, '_') + '-embedded).json'
);
}
} catch (err) {
alert('Not saving due to failure parsing JSON: ' + err.toString());
}
}
function SaveJSONText() {
// Check the JSON
var txt = document.getElementById('drop_zone').value;
if (txt.length === 0) {
alert('Box is empty?');
return;
}
// Make blob and trigger save dialog
var fn = document.querySelectorAll('#fileinfo span')[0].textContent;
saveAs(
new Blob(
[txt]
, { type: 'text/plain;charset=UTF-8' }
), 'sessionstore(' + fn.replace(/\./g, '_') + ').txt'
);
}
// copied/adapted from https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/File_drag_and_drop
function drop_handler(ev) {
ev.preventDefault();
// Clear colors
dragleave_handler(ev);
// If dropped items aren't files, reject them
var dt = ev.dataTransfer;
if (dt.items) {
// Use DataTransferItemList interface to access the file(s) (break after first file opened)
for (var i = 0; i < dt.items.length; i++) {
if (dt.items[i].kind == "file") {
readfile(dt.items[i].getAsFile());
document.getElementById('btnScrounge').removeAttribute('disabled');
document.getElementById('btnDumblist').removeAttribute('disabled');
document.getElementById('btnJSON').removeAttribute('disabled');
document.getElementById('btnText').removeAttribute('disabled');
window.setTimeout(checkForEmbeds, 4000);
break;
}
}
} else { // ** NOT TESTED **
// Use DataTransfer interface to access the file(s) (break after first file opened)
for (var i = 0; i < dt.files.length; i++) {
readfile(dt.files[i]);
document.getElementById('btnScrounge').removeAttribute('disabled');
document.getElementById('btnDumblist').removeAttribute('disabled');
document.getElementById('btnJSON').removeAttribute('disabled');
document.getElementById('btnText').removeAttribute('disabled');
window.setTimeout(checkForEmbeds, 4000);
break;
}
}
}
function dragover_handler(ev) {
// Prevent default select and drag behavior
ev.preventDefault();
}
function dragend_handler(ev) {
//console.log("dragEnd");
// Remove all of the drag data
var dt = ev.dataTransfer;
if (dt.items) {
// Use DataTransferItemList interface to remove the drag data
for (var i = 0; i < dt.items.length; i++) {
dt.items.remove(i);
}
} else {
// Use DataTransfer interface to remove the drag data
ev.dataTransfer.clearData();
}
}
function dragenter_handler(ev) {