-
-
Save jscher2000/9623b34ed793274396ac04b81cb81660 to your computer and use it in GitHub Desktop.
/* Open old session history file in a tab, open the web console, paste all of this, press Enter to execute. | |
If popup is blocked, allow popups then try again. */ | |
function scrub(t){t=t.replace(/&/g,'&'); t=t.replace(/>/g,'>'); t=t.replace(/</g,'<'); return t;} | |
if (window.confirm('Scrounge session URLs?')) var newwin=window.open(); | |
if (newwin){ | |
newwin.document.write('<!DOCTYPE html>\n<html><head><title>URLs Scrounged from Session History</title><meta http-equiv=\'Content-Type\' content=\'text/html; charset=UTF-8\'><style>.urllist>p{margin-left:2.25em}.urllist>p:nth-of-type(1){margin-left:0}</style></head>\n'); | |
newwin.document.write('<body><h1>URLs Scrounged from Session History</h1>\n'); | |
var out=new Array(); | |
var sess=document.body.textContent.split('"_closedWindows":['); | |
console.log(sess.length); | |
for (var n=0; n < sess.length; n++){ | |
if(n==1) out.push('<h1>Closed Windows</h1>'); | |
else out.push('<h1>Windows</h1>'); | |
var winds = sess[n].split('{"tabs":['); | |
for (var i=1; i < winds.length; i++) { | |
if (n==1) out.push('<h2 style=\'border-bottom:1px solid #000\'>Closed Window ' + i + '</h2><div style=\'margin-left:2.25em\'>'); | |
else out.push('<h2 style=\'border-bottom:1px solid #000\'>Window ' + i + '</h2><div style=\'margin-left:2.25em\'>'); | |
var wtabs = winds[i].split('"_closedTabs":['); | |
for (var m=0; m < wtabs.length; m++){ | |
var tabs = wtabs[m].split('{"entries":['); | |
for (var j=1; j < tabs.length; j++) { | |
if (m==1 && j==1) out.push('<div style=\'margin-left:2.25em\'><h3>(Closed Tabs)</h3>'); | |
out.push('<h3>Tab ' + j + '</h3>\n<div class=\'urllist\'>'); | |
var strTemp = tabs[j].split(',"children":[')[0]; // ignore children | |
var taburls = strTemp.split('{"url":"'); | |
for (var k=taburls.length - 1; k >= 1; k--) { | |
var strURL = taburls[k].substr(0, taburls[k].indexOf('","')); | |
var 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('<p>← Back <em>(earlier pages visited in this tab)</em>:</p>'); | |
out.push('<p><strong>' + scrub(strTitle) + '</strong><br><a href=\'' + strURL + '\' target=\'_blank\'>' + scrub(strURL) + '</a></p>'); | |
} | |
out.push('</div>'); | |
} | |
out.push('</div>'); | |
} | |
} | |
} | |
newwin.document.write(out.join('\n')); | |
newwin.document.write('\n</body>\n</html>'); | |
newwin.document.close(); | |
} |
Thank you for creating this.
I have a question: When I recover a session using this script, and import the file into my bookmarks library, each tab from a window is saved in its own folder. So if I recover 100 tabs from one window, 100 bookmark folders will be created. How do I change this behavior? I would like all tabs from one window to go into just one bookmark folder.
When I recover a session using this script, and import the file into my bookmarks library, each tab from a window is saved in its own folder.
Hi, the structure of the list generated by this script is quite different from an importable "bookmarks.html" file. I think you could generate a bookmarks.html file by combining code from two projects over here:
P.S. The h3 tag is the one used to indicate a folder name. Perhaps if you find/replace that to a different tag such as p then Firefox will not bother will all the folders? You might want to find/replace the h1 to h3 as an outer container.
Hi jecher2000,
I need your help urgently please. i would like to restore my previous session and i was able to use your 'Session History: https://www.jeffersonscher.com/res/scrounger.html' successfully but i could not reload the page bypassing the cache using Windows: Ctrl+Shift+r.
Please help me out, it's very urgent.
Thanks