Changed to SweetAlerts2

This commit is contained in:
Maxim Stewart 2020-02-26 02:21:16 -06:00
parent 5463be002e
commit c27108e3df
10 changed files with 3140 additions and 1523 deletions

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": " Easy Session Manager", "name": " Easy Session Manager",
"version": "0.2.1.0", "version": "0.2.2.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

@ -29,7 +29,7 @@ body, html {
</span> </span>
<script src="../scripts/libs/sweetalert.js"></script> <script src="../scripts/libs//sweetalert2.all.js"></script>
<script src="../scripts/background.js"></script> <script src="../scripts/background.js"></script>
</body> </body>
</html> </html>

View File

@ -42,7 +42,7 @@
<a id="downloadAnchorElem" href="#"></a> <a id="downloadAnchorElem" href="#"></a>
<script src="../scripts/libs/sweetalert.js"></script> <script src="../scripts/libs//sweetalert2.all.js"></script>
<script src="../scripts/utils.js"></script> <script src="../scripts/utils.js"></script>
<script src="../scripts/actions.js"></script> <script src="../scripts/actions.js"></script>
<script src="../scripts/session-manager.js"></script> <script src="../scripts/session-manager.js"></script>

View File

@ -1,5 +1,8 @@
const messageWindow = (type = "warning", message = "No message passed in...") => { const messageWindow = (type = "warning", message = "No message passed in...") => {
swal(message, { icon: type, }); Swal.fire({
text: message,
icon: type
});
} }
const getSavedSessionIDs = () => { const getSavedSessionIDs = () => {
@ -20,15 +23,14 @@ const saveToStorage = (name, data, action = "undefined", willReplace = false, sv
try { try {
const json = JSON.parse(results[name]); // If a session is found const json = JSON.parse(results[name]); // If a session is found
if (!willReplace) { if (!willReplace) {
swal({ Swal.fire({
title: "Replace?", title: "Replace?",
text: "Found a session with that name! Do you want to replace it?", text: "Found a session with that name! Do you want to replace it?",
icon: "warning", icon: "warning",
buttons: true, showCloseButton: true,
dangerMode: true, showCancelButton: true,
}).then((willReplace) => { }).then((willReplace) => {
if (willReplace) { if (willReplace.value) {
console.log("door 1");
storageApi.set({[name]: data}); storageApi.set({[name]: data});
sveElm.innerText = size + " | " + name; sveElm.innerText = size + " | " + name;
sveElm.name = name; sveElm.name = name;
@ -57,14 +59,14 @@ const saveToStorage = (name, data, action = "undefined", willReplace = false, sv
} }
const deleteFromStorage = (elm = null, name = null) => { const deleteFromStorage = (elm = null, name = null) => {
swal({ Swal.fire({
title: "Are you sure?", title: "Are you sure?",
text: "Do you wish to delete session:\n" + name + "?", text: "Do you wish to delete session:\n" + name + "?",
icon: "warning", icon: "warning",
buttons: true, showCloseButton: true,
dangerMode: true, showCancelButton: true,
}).then((willDelete) => { }).then((willDelete) => {
if (willDelete) { if (willDelete.value) {
storageApi.remove(name).then(() => { storageApi.remove(name).then(() => {
elm.parentElement.removeChild(elm); elm.parentElement.removeChild(elm);
}); });

View File

@ -1,17 +1,36 @@
const message1 = "What is this session's name? Allowed: a-z, A-Z, -, _"; const message1 = "What is this session's name? Allowed: a-z, A-Z, -, _";
const regexp = /^[a-zA-Z0-9-_]+$/; // Alphanumeric, dash, underscore const regexp = /^[a-zA-Z0-9-_]+$/; // Alphanumeric, dash, underscore
const messageWindow = (type = "warning", message = "No message passed in...") => {
Swal.fire({
text: message,
icon: type
});
}
const processor = (obj, enteryName = '', message = message1) => { const processor = (obj, enteryName = '', message = message1) => {
let data = obj.target.result; let data = obj.target.result;
let inputTag = document.createElement("INPUT"); let inputTag = document.createElement("INPUT");
let pTag = document.createElement("P");
let brTag = document.createElement("BR");
let textTag = document.createTextNode(message);
inputTag.value = enteryName; inputTag.value = enteryName;
swal(message, { pTag.append(textTag);
content: inputTag, pTag.appendChild(brTag);
buttons: true, pTag.appendChild(inputTag);
Swal.fire({
title: "Session Name:",
text: message,
html: pTag,
showCloseButton: true,
showCancelButton: true,
customClass: 'swal-modal', customClass: 'swal-modal',
}).then((value) => { }).then((result) => {
if (value) { if (result.value) {
enteryName = inputTag.value.replace(/ /g, "_"); enteryName = inputTag.value.replace(/ /g, "_");
if (enteryName.length < 0 || enteryName.length > 54 || enteryName.search(regexp) == -1) { if (enteryName.length < 0 || enteryName.length > 54 || enteryName.search(regexp) == -1) {
@ -21,21 +40,15 @@ const processor = (obj, enteryName = '', message = message1) => {
try { try {
console.log("Importing session..."); console.log("Importing session...");
JSON.parse(data); JSON.parse(data); // See if parsing fails and throw error
browser.storage.local.set({[enteryName]: data}); browser.storage.local.set({[enteryName]: data});
swal("Imported file successfully.", { messageWindow("success", "Imported file successfully.");
icon: "success",
});
} catch (e) { } catch (e) {
swal("Failed to import data. Not a JSON parsable file.", { messageWindow("error", "Failed to import data. Not a JSON parsable file.");
icon: "error",
});
return ; return ;
} }
} else { } else {
swal("Canceled import.", { messageWindow("warning", "Canceled import.");
icon: "warning",
});
} }
}); });
}; };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -21,14 +21,20 @@ const saveSession = (elm = null, name = null, message = message1) => {
let keys = Object.keys(sessionData); let keys = Object.keys(sessionData);
let keysLength = Object.keys(sessionData).length; let keysLength = Object.keys(sessionData).length;
let container = generateSelectionWindow(sessionData, keys, keysLength); let container = generateSelectionWindow(sessionData, keys, keysLength);
container.prepend(inputTag); let textTag = document.createTextNode(message);
let brTag = document.createElement("BR");
swal(message, { container.prepend(inputTag);
content: container, container.prepend(brTag);
buttons: true, container.prepend(message);
Swal.fire({
html: container,
showCloseButton: true,
showCancelButton: true,
customClass: 'swal-modal', customClass: 'swal-modal',
}).then((value) => { }).then((result) => {
if (value) { if (result.value) {
let enteryName = inputTag.value.replace(/ /g, "_"); let enteryName = inputTag.value.replace(/ /g, "_");
if (enteryName.length < 0 || enteryName.length > 54 || enteryName.search(regexp) == -1) { if (enteryName.length < 0 || enteryName.length > 54 || enteryName.search(regexp) == -1) {
@ -52,6 +58,7 @@ const editSession = (elm = null, name = null, message = message1) => {
let newSessionTag = document.createElement("INPUT"); let newSessionTag = document.createElement("INPUT");
let labelTag = document.createElement("LABEL"); let labelTag = document.createElement("LABEL");
let brTag = document.createElement("BR"); let brTag = document.createElement("BR");
let brTag2 = document.createElement("BR");
inputTag.value = id; inputTag.value = id;
newSessionTag.type = "checkbox"; newSessionTag.type = "checkbox";
@ -71,20 +78,27 @@ const editSession = (elm = null, name = null, message = message1) => {
keysLength = Object.keys(json).length; keysLength = Object.keys(json).length;
} catch (e) { } catch (e) {
messageWindow("warning", "Canceled edit; couldn't load any data..."); messageWindow("warning", "Canceled edit; couldn't load any data...");
return ;
} }
let container = generateSelectionWindow(json, keys, keysLength); let container = generateSelectionWindow(json, keys, keysLength);
let textTag = document.createTextNode(message);
container.prepend(labelTag); container.prepend(labelTag);
container.prepend(newSessionTag); container.prepend(newSessionTag);
container.prepend(brTag); container.prepend(brTag);
container.prepend(inputTag); container.prepend(inputTag);
container.prepend(brTag2);
container.prepend(message);
console.log("Editing session..."); console.log("Editing session...");
swal(message, { Swal.fire({
content: container, html: container,
buttons: true, showCloseButton: true,
showCancelButton: true,
customClass: 'swal-modal', customClass: 'swal-modal',
}).then((value) => { }).then((result) => {
if (value) { if (result.value) {
let newName = inputTag.value.replace(/ /g, "_"); let newName = inputTag.value.replace(/ /g, "_");
if (newName.length < 0 || newName.length > 54 || newName.search(regexp) == -1) { if (newName.length < 0 || newName.length > 54 || newName.search(regexp) == -1) {
@ -146,12 +160,14 @@ const downloadSession = (session = null) => {
pTag.append(brTag); pTag.append(brTag);
pTag.append(inputTag); pTag.append(inputTag);
swal("Download Session?", { Swal.fire({
content: pTag, text: "Download Session?",
buttons: true, html: pTag,
showCloseButton: true,
showCancelButton: true,
customClass: 'swal-modal', customClass: 'swal-modal',
}).then((willDl) => { }).then((willDl) => {
if (willDl) { if (willDl.value) {
if (chkBoxTag.checked) { if (chkBoxTag.checked) {
fileName = "session:" + id + ":" + new Date().toLocaleString() fileName = "session:" + id + ":" + new Date().toLocaleString()
.split(',')[0] .split(',')[0]
@ -181,11 +197,13 @@ const preLoadSession = (id) => {
loadSession(json, replaceTabs.checked); loadSession(json, replaceTabs.checked);
} else { } else {
let container = generateSelectionWindow(json, keys, keysLength); let container = generateSelectionWindow(json, keys, keysLength);
swal("Selective Open", { Swal.fire({
content: container, text: "Selective Open",
buttons: true, html: container,
showCloseButton: true,
showCancelButton: true,
}).then((willOpen) => { }).then((willOpen) => {
if (willOpen) { if (willOpen.value) {
json = getSelectionData(container, keys, keysLength); json = getSelectionData(container, keys, keysLength);
keysLength = Object.keys(json).length; keysLength = Object.keys(json).length;
if (keysLength > 0) { if (keysLength > 0) {

File diff suppressed because it is too large Load Diff