Added on save grab selected item name if applicable. Fixed clearing of selected item.

This commit is contained in:
Maxim Stewart 2019-03-19 16:19:18 -05:00
parent 7d6719510e
commit 8ea3c95100
7 changed files with 25 additions and 20 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.2 # Version: 0.1.4
Improved download options plus set warning on certain actions when nothing selected. Added on save grab selected item name if applicable. Fixed clearing of selected item.
# 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.2", "version": "0.1.4",
"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

@ -30,7 +30,7 @@ body, html {
</span> </span>
<script src="../scripts/sweetalert.min.js"></script> <script src="../scripts/sweetalert.js"></script>
<script src="../scripts/background.js"></script> <script src="../scripts/background.js"></script>
</body> </body>
</html> </html>

View File

@ -41,7 +41,7 @@
<script src="../scripts/events.js"></script> <script src="../scripts/events.js"></script>
<script src="../scripts/sweetalert.min.js"></script> <script src="../scripts/sweetalert.js"></script>
<script src="../scripts/sessionManager.js"></script> <script src="../scripts/sessionManager.js"></script>
</body> </body>

View File

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

View File

@ -3,16 +3,20 @@ const windowSys = browser.windows;
const regexp = /^[a-zA-Z0-9-_]+$/; // Alphanumeric, dash, underscore const regexp = /^[a-zA-Z0-9-_]+$/; // Alphanumeric, dash, underscore
const saveSession = (message = "What is this session's name? Allowed: a-z, A-Z, -, _") => { const saveSession = (elm = null, message = "What is this session's name? Allowed: a-z, A-Z, -, _") => {
let inputTag = document.createElement("INPUT"); let inputTag = document.createElement("INPUT");
inputTag.value = new Date().toLocaleString().split(',')[0].replace(/\//g, '-'); inputTag.value = new Date().toLocaleString().split(',')[0].replace(/\//g, '-');
if (elm !== null)
inputTag.value = elm.innerHTML;
swal(message, { swal(message, {
content: inputTag, content: inputTag,
buttons: true, buttons: true,
}).then((value) => { }).then((value) => {
if (value) { if (value) {
let enteryName = inputTag.value.replace(/ /g, "_"); let enteryName = inputTag.value.replace(/ /g, "_");
if (enteryName) { if (enteryName) {
if (enteryName.search(regexp) == -1) { if (enteryName.search(regexp) == -1) {
saveSession("Please try again...\nAllowed: a-z, A-Z, -, _") saveSession("Please try again...\nAllowed: a-z, A-Z, -, _")
@ -53,8 +57,8 @@ const saveSession = (message = "What is this session's name? Allowed: a-z, A-Z,
}); });
} }
const editSession = (message = "Editing selected session... Allowed: a-z, A-Z, -, _") => { const editSession = (elm = null, message = "Editing selected session... Allowed: a-z, A-Z, -, _") => {
let id = selectedItem.innerHTML; let id = elm.innerHTML;
let inputTag = document.createElement("INPUT"); let inputTag = document.createElement("INPUT");
inputTag.value = id; inputTag.value = id;
@ -77,7 +81,7 @@ const editSession = (message = "Editing selected session... Allowed: a-z, A-Z, -
saveToStorage(newName, JSON.stringify(json), true); saveToStorage(newName, JSON.stringify(json), true);
}); });
selectedItem.textContent = newName; elm.textContent = newName;
} else { } else {
swal("Canceled edit...", { swal("Canceled edit...", {
icon: "warning", icon: "warning",
@ -115,17 +119,17 @@ const saveToStorage = (name, data, fromEdit = false) => {
}); });
} }
const deleteFromStorage = () => { const deleteFromStorage = (elm = null) => {
swal({ swal({
title: "Are you sure?", title: "Are you sure?",
text: "Do you wish to delete session:\n" + selectedItem.innerHTML + "?", text: "Do you wish to delete session:\n" + elm.innerHTML + "?",
icon: "warning", icon: "warning",
buttons: true, buttons: true,
dangerMode: true, dangerMode: true,
}).then((willDelete) => { }).then((willDelete) => {
if (willDelete) { if (willDelete) {
storage.remove(selectedItem.innerHTML).then(() => { storage.remove(elm.innerHTML).then(() => {
selectedItem.parentElement.removeChild(selectedItem); elm.parentElement.removeChild(elm);
}); });
swal("Deleted session successfully...", { swal("Deleted session successfully...", {
icon: "success", icon: "success",
@ -145,7 +149,7 @@ const importSession = () => {
}); });
} }
const downloadSession = () => { const downloadSession = (elm = null) => {
let pTag = document.createElement("P"); let pTag = document.createElement("P");
let inputTag = document.createElement("INPUT"); let inputTag = document.createElement("INPUT");
let chkBoxTag = document.createElement("INPUT"); let chkBoxTag = document.createElement("INPUT");
@ -153,7 +157,7 @@ const downloadSession = () => {
let brTag = document.createElement("BR"); let brTag = document.createElement("BR");
var dlAnchorElem = document.getElementById('downloadAnchorElem'); var dlAnchorElem = document.getElementById('downloadAnchorElem');
let text = document.createTextNode("Append Date?"); let text = document.createTextNode("Append Date?");
let id = selectedItem.innerHTML; let id = elm.innerHTML;
let fileName = "session:" + id + ".json"; let fileName = "session:" + id + ".json";
chkBoxTag.type = "checkbox"; chkBoxTag.type = "checkbox";
inputTag.value = fileName; inputTag.value = fileName;