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,
"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.",
"applications": {

View File

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

View File

@ -42,7 +42,7 @@
<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/actions.js"></script>
<script src="../scripts/session-manager.js"></script>

View File

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

View File

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

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

File diff suppressed because it is too large Load Diff