Created
March 14, 2021 01:23
-
-
Save alahmnat/1e6b70200ae7613c170eeb582a3cd772 to your computer and use it in GitHub Desktop.
Session Buddy to Tab Session Manager export converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head></head> | |
<body> | |
<p> | |
<b>How to use this tool:</b> In Chrome, open Session Buddy. Click on the gear at the top-right, and select "Export". | |
</p> | |
<p> | |
In the export dialog, select "JSON" as the export type, and be sure to select both "Sessions" and "Windows" in the "Show" options. | |
</p> | |
<p> | |
Save the file to disk, then select it from the file browser prompt below. | |
</p> | |
<p> | |
Click "Convert" to receive a new JSON file that is compatible with Firefox's Tab Session Manager extension. | |
</p> | |
<p> | |
In Tab Session Manager, go to Settings > Sessions and use the new file in the "Import sessions" prompt. | |
</p> | |
<input type="file" id="file-selector"> | |
<button id="loader">Convert</button> | |
<script> | |
const fileSelector = document.getElementById('file-selector'); | |
var fileList; | |
fileSelector.addEventListener('change', (event) => { | |
fileList = event.target.files; | |
console.log(fileList); | |
}); | |
const loadButton = document.getElementById('loader'); | |
loadButton.addEventListener('click', (event) => { | |
readText(fileList[0]); | |
}); | |
function readText(file) { | |
console.log("file reading..."); | |
let reader = new FileReader(); | |
reader.readAsText(file); | |
var newData = new Array(); | |
reader.onload = function() { | |
var fixedResult = reader.result.substring(1); | |
var data = JSON.parse(fixedResult); | |
console.log(data); | |
data.sessions.forEach(function(item, index) { | |
var session = new Object(); | |
var tabCount = 0; | |
session.windowsNumber = item.windows.length; | |
if(item.created) { | |
session.date = new Date(item.created).getTime(); | |
session.sessionStartTime = new Date(item.generated).getTime(); | |
session.lastEditedTime = new Date(item.modified).getTime(); | |
} else { | |
session.date = new Date(item.generated).getTime(); | |
session.sessionStartTime = new Date(item.generated).getTime(); | |
session.lastEditedTime = new Date(item.generated).getTime(); | |
} | |
session.windows = new Object(); | |
session.windowsInfo = new Object(); | |
item.windows.forEach(function(window, idx){ | |
var thisWindow = new Object(); | |
var newTabs = new Object(); | |
window.tabs.forEach(function(tab, x){ | |
newTabs[tab.id] = { | |
"id" : tab.id, | |
"index" : tab.index, | |
"windowId" : tab.windowId, | |
"highlighted" : tab.highlighted, | |
"active" : tab.active, | |
"attention" : false, | |
"pinned" : false, | |
"status" : tab.status, | |
"hidden" : false, | |
"discarded" : false, | |
"incognito" : tab.incognito, | |
"width" : tab.width, | |
"height" : tab.height, | |
"lastAccessed" : new Date(item.modified).getTime(), | |
"audible" : tab.audible, | |
"mutedInfo" : tab.mutedInfo, | |
"isArticle" : false, | |
"isInReaderMode" : false, | |
"sharingState" : { | |
"camera" : false, | |
"microphone" : "false" | |
}, | |
"successorTabId" : -1, | |
"cookieStoreId" : "firefox-default", | |
"url" : tab.url, | |
"title" : tab.title, | |
"favIconUrl" : tab.favIconUrl | |
} | |
tabCount++; | |
}); | |
session.windows[window.id] = newTabs; | |
session.windowsInfo[window.id] = { | |
"id" : window.id, | |
"focused" : idx == 0 ? true : false, | |
"top" : window.top, | |
"left" : window.left, | |
"width" : window.width, | |
"height" : window.height, | |
"incognito" : false, | |
"type" : "normal", | |
"state" : "normal", | |
"alwaysOnTop" : false, | |
} | |
}); | |
session.tabsNumber = tabCount; | |
if(item.name) { | |
session.name = item.name; | |
} else { | |
session.name = "Unnamed Session"; | |
} | |
session.tag = new Array(); | |
session.id = uuidv4(); | |
newData.push(session); | |
}); | |
console.log(newData); | |
const outputData = new Blob([JSON.stringify(newData, null, " ")], { | |
type: "aplication/json" | |
}); | |
const fileName = "Converted - " + fileList[0].name; | |
let newLink = document.createElement("a"); | |
newLink.download = fileName; | |
if (window.webkitURL != null) { | |
newLink.href = window.webkitURL.createObjectURL(outputData); | |
} | |
else { | |
newLink.href = window.URL.createObjectURL(outputData); | |
newLink.style.display = "none"; | |
document.body.appendChild(newLink); | |
} | |
newLink.click(); | |
} | |
} | |
function uuidv4() { | |
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => | |
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) | |
); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment