initial commit

This commit is contained in:
Maxim Stewart 2018-11-11 03:04:55 -06:00
parent 5bf5b82b13
commit ac3716cd4d
11 changed files with 279 additions and 0 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# Session Manager
Session Manager allows you to manage your Firefox session by backing up or loading your saved sessions.
# Download
https://addons.mozilla.org/en-US/firefox/addon/tab-groups-with-search-manager/
# Version: 0.0.1
Released Program

BIN
src/images/icons/delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
src/images/icons/edit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

BIN
src/images/icons/save.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

31
src/manifest.json Normal file
View File

@ -0,0 +1,31 @@
{
"manifest_version": 2,
"name": "Session Manager",
"version": "0.0.1",
"description": "Session Manager allows you to manage your Firefox session by backing up or loading your saved sessions.",
"applications": {
"gecko": {
"id": "sessionManager@itdominator.com",
"strict_min_version": "55.0"
}
},
"icons": {
"48": "images/icons/sessionManager.png",
"96": "images/icons/sessionManager.png"
},
"permissions": [
"tabs",
"storage",
"unlimitedStorage"
],
"browser_action": {
"default_icon": "images/icons/sessionManager.png",
"default_title": "Session Manager",
"default_popup": "pages/sessionManager.html"
}
}

35
src/pages/sessionManager.html Executable file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../styles/styles.css"/>
</head>
<body>
<center>
<button type="button" name="save">
Save <img class="icon" src="../images/icons/save.png" alt="Save Image"/>
</button>
<button type="button" name="download">
Download <img class="icon" src="../images/icons/download.png" alt="Download Image"/>
</button>
<button type="button" name="edit">
Edit <img class="icon" src="../images/icons/edit.png" alt="Edit Image"/>
</button>
<button type="button" name="delete">
Delete <img class="icon" src="../images/icons/delete.png" alt="Delete Image"/>
</button>
<div id="savedSessions">
</div>
</center>
<a id="downloadAnchorElem" href="#"></a>
<script src="../scripts/events.js"></script>
<script src="../scripts/sessionManager.js"></script>
</body>
</html>

37
src/scripts/events.js Normal file
View File

@ -0,0 +1,37 @@
let selectedItem = null;
document.addEventListener("click", (e) => {
if (e.button == 0) { // Left click
if (e.target.tagName == "LI") {
if (selectedItem) {
if (selectedItem == e.target && selectedItem.className == "selected") {
selectedItem.setAttribute("class", "");
} else {
selectedItem.setAttribute("class", "");
selectedItem = e.target;
selectedItem.setAttribute("class", "selected");
}
} else {
selectedItem = e.target;
selectedItem.setAttribute("class", "selected");
}
} else if (e.target.name == "save") {
saveSession();
} else if (selectedItem) {
if (e.target.name == "download")
downloadSession();
else if (e.target.name == "delete")
deleteFromStorage();
else if (e.target.name == "edit")
editSession();
}
}
});
document.addEventListener("dblclick", (e) => {
if (e.button == 0) { // Left click
if (e.target.tagName == "LI") {
loadSession(e.target.innerHTML.trim());
}
}
});

View File

@ -0,0 +1,137 @@
const storage = browser.storage.local;
const windowSys = browser.windows;
const saveSession = () => {
let enteryName = prompt("What is this session's name?", "" + new Date().toLocaleString()
.split(',')[0]);
if (enteryName) {
console.log("Saving session...");
windowSys.getAll({ populate: true, windowTypes: ["normal"] }).then((windows) => {
let sessionData = {};
for (let i = 0; i < windows.length; i++) {
let links = [];
for (var ii = 0; ii < windows[i].tabs.length; ii++) {
if (!windows[i].tabs[ii].url.includes("about:")) {
links.push(
{"link" : windows[i].tabs[ii].url.trim()}
);
}
}
sessionData["WindowID:" + windows[i].id] = links;
}
saveToStorage(enteryName, JSON.stringify(sessionData));
}).then(() => {
if (document.getElementsByName(enteryName).length == 0) {
appendToSavedSessionsList(enteryName);
}
});
} else {
console.log("Canceled save...");
}
}
const saveToStorage = (name, data) => {
storage.set({[name]: data});
}
const downloadSession = () => {
var dlAnchorElem = document.getElementById('downloadAnchorElem');
let id = selectedItem.innerHTML;
fileName = "session:" + id + ":" +
new Date().toLocaleString().split(',')[0]
.replace("/", "-") + ".json";
storage.get(id).then((storageResults) => {
let json = JSON.parse(storageResults[id]);
let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json));
dlAnchorElem.setAttribute("href", dataStr);
dlAnchorElem.setAttribute("download", fileName);
dlAnchorElem.click();
});
}
const deleteFromStorage = () => {
let action = confirm("Do you wish to delete session: " + selectedItem.innerHTML + "?");
if (action) {
storage.remove(selectedItem.innerHTML).then(() => {
selectedItem.parentElement.removeChild(selectedItem);
});
}
}
const editSession = () => {
let id = selectedItem.innerHTML;
let newName = prompt("Editing selected session...", id);
if (newName != null) {
storage.get(id).then((storageResults) => {
storage.remove(id);
json = JSON.parse(storageResults[id]);
saveToStorage(newName, JSON.stringify(json));
});
selectedItem.innerHTML = newName;
}
}
const loadSession = (id = null) => {
console.log("Loading session...");
try {
storage.get(id).then((storageResults) => {
let json = JSON.parse(storageResults[id]);
let keys = Object.keys(json);
browser.windows.getAll().then((windows) => {
windowSys.getCurrent({populate: true}).then((currentWindow) => {
// Clear out windows
for (var i = 0; i < windows.length; i++) {
if (currentWindow.id != windows[i].id) {
windowSys.remove(windows[i].id);
}
}
}, windows);
});
// Open windows and populate with proper tabs
keys.forEach((key) => {
let store = json[key];
let urls = [];
for (var i = 0; i < store.length; i++) {
urls.push(store[i].link);
}
windowSys.create({ url: urls });
});
// Finalize clear out windows
windowSys.getCurrent({populate: true}).then((currentWindow) => {
windowSys.remove(currentWindow.id);
});
});
} catch (e) { console.log(e); }
}
const getSavedSessionIDs = () => {
console.log("Getting saved sessions...");
storage.get(null).then((storageResults) => {
let keys = Object.keys(storageResults);
for (let key of keys) {
appendToSavedSessionsList(key);
}
});
}
const appendToSavedSessionsList = (enteryName) => {
let liTag = document.createElement("LI");
let text = document.createTextNode(enteryName);
liTag.setAttribute("name", enteryName);
liTag.append(text);
document.getElementById("savedSessions").append(liTag);
}
getSavedSessionIDs();

30
src/styles/styles.css Normal file
View File

@ -0,0 +1,30 @@
body { width: 450px; }
ul, li { list-style: none; }
li {
background-color: #0a1827;
color: #ffffff;
margin: 1em 0em;
padding: 1.5em;
text-align: center;
}
li:hover {
background-color: #1e4573;
cursor: pointer;
}
button {
background-color: #ffffff;
color: #000000;
}
.selected {
background-color: #a3b83b;
box-shadow: 0px 5px 5px 5px #444444;
}
.icon {
width: 25px;
height: 25px;
}