Improved download options plus set warning on certain actions.

This commit is contained in:
Maxim Stewart 2019-03-19 15:34:43 -05:00
parent c84579000b
commit 7d6719510e
4 changed files with 46 additions and 17 deletions

View File

@ -4,8 +4,8 @@ Easy Session Manager allows you to manage your Firefox session by backing up or
# Download # Download
https://addons.mozilla.org/en-US/firefox/addon/easy-session-manager/ https://addons.mozilla.org/en-US/firefox/addon/easy-session-manager/
# Version: 0.1.0 # Version: 0.1.2
Improved look of action messages. (Save, Delete, Edit, etc...) Improved download options plus set warning on certain actions when nothing selected.
# Images # Images
![1 Default interface with no sessions. ](images/pic1.png) ![1 Default interface with no sessions. ](images/pic1.png)

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": " Easy Session Manager", "name": " Easy Session Manager",
"version": "0.1.0", "version": "0.1.2",
"description": " Easy Session Manager allows you to manage your Firefox session by backing up or loading your saved sessions.", "description": " Easy Session Manager allows you to manage your Firefox session by backing up or loading your saved sessions.",
"applications": { "applications": {

View File

@ -2,6 +2,7 @@ let selectedItem = null;
document.addEventListener("click", (e) => { document.addEventListener("click", (e) => {
if (e.button == 0) { // Left click if (e.button == 0) { // Left click
let name = e.target.name;
if (e.target.tagName == "LI") { if (e.target.tagName == "LI") {
if (selectedItem) { if (selectedItem) {
if (selectedItem == e.target && selectedItem.className == "selected") { if (selectedItem == e.target && selectedItem.className == "selected") {
@ -15,17 +16,21 @@ document.addEventListener("click", (e) => {
selectedItem = e.target; selectedItem = e.target;
selectedItem.setAttribute("class", "selected"); selectedItem.setAttribute("class", "selected");
} }
} else if (e.target.name == "save") { } else if (name == "save") {
saveSession(); saveSession();
} else if (e.target.name == "import") { } else if (name == "import") {
importSession(); importSession();
} else if (selectedItem) { } else if (selectedItem) {
if (e.target.name == "download") if (name == "download")
downloadSession(); downloadSession();
else if (e.target.name == "delete") else if (name == "delete")
deleteFromStorage(); deleteFromStorage();
else if (e.target.name == "edit") else if (name == "edit")
editSession(); editSession();
} else if (/(download|delete|edit)/.test(name)) {
swal("Select a session first...", {
icon: "warning",
});
} }
} }
}); });

View File

@ -146,19 +146,43 @@ const importSession = () => {
} }
const downloadSession = () => { const downloadSession = () => {
let pTag = document.createElement("P");
let inputTag = document.createElement("INPUT");
let chkBoxTag = document.createElement("INPUT");
let lblTag = document.createElement("LABEL");
let brTag = document.createElement("BR");
var dlAnchorElem = document.getElementById('downloadAnchorElem'); var dlAnchorElem = document.getElementById('downloadAnchorElem');
let text = document.createTextNode("Append Date?");
let id = selectedItem.innerHTML; let id = selectedItem.innerHTML;
fileName = "session:" + id + ":" + let fileName = "session:" + id + ".json";
new Date().toLocaleString().split(',')[0].replace(/\//g, "-") + ".json"; chkBoxTag.type = "checkbox";
inputTag.value = fileName;
chkBoxTag.id = "chkbx";
lblTag.htmlFor = "chkbx";
lblTag.append(text);
pTag.append(lblTag);
pTag.append(chkBoxTag);
pTag.append(brTag);
pTag.append(inputTag);
storage.get(id).then((storageResults) => { swal("Download Session?", {
let json = JSON.parse(storageResults[id]); content: pTag,
let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json)); buttons: true,
dlAnchorElem.setAttribute("href", dataStr); }).then((willDl) => { if (willDl) {
dlAnchorElem.setAttribute("download", fileName); if (chkBoxTag.checked) {
dlAnchorElem.click(); fileName = "session:" + id + ":" +
new Date().toLocaleString().split(',')[0].replace(/\//g, "-") + ".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 loadSession = (id = null) => { const loadSession = (id = null) => {