Small fixes plus adding initial tab count code logic
This commit is contained in:
parent
9fc3062fde
commit
9bc91db106
|
@ -4,9 +4,9 @@ const messageWindow = (type = "warning", message = "No message passed in...") =>
|
||||||
|
|
||||||
const getSavedSessionIDs = () => {
|
const getSavedSessionIDs = () => {
|
||||||
storageApi.get(null).then((results) => {
|
storageApi.get(null).then((results) => {
|
||||||
let keys = Object.keys(results);
|
const sessions = Object.keys(results);
|
||||||
for (let key of keys) {
|
for (let session of sessions) {
|
||||||
appendToSavedSessionsList(key);
|
appendToSavedSessionsList(session);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,42 +2,46 @@ getSavedSessionIDs();
|
||||||
|
|
||||||
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;
|
const target = e.target;
|
||||||
|
const action = target.name;
|
||||||
|
|
||||||
if (/(download|delete|edit)/.test(name)) {
|
// Set selection first before doing any actions...
|
||||||
|
if (target.tagName == "LI" && target.className.includes("sessionLI")) {
|
||||||
if (selectedItem) {
|
if (selectedItem) {
|
||||||
if (name == "download")
|
if (selectedItem == target && selectedItem.className == "sessionLI selected") {
|
||||||
downloadSession(selectedItem);
|
|
||||||
else if (name == "delete")
|
|
||||||
deleteFromStorage(selectedItem);
|
|
||||||
else if (name == "edit")
|
|
||||||
editSession(selectedItem);
|
|
||||||
} else {
|
|
||||||
messageWindow("warning", "Select a session first...");
|
|
||||||
}
|
|
||||||
} else if (name == "save") {
|
|
||||||
saveSession(selectedItem);
|
|
||||||
} else if (name == "import") {
|
|
||||||
importSession();
|
|
||||||
} else if (name == "donate") {
|
|
||||||
doUrlAction("https://www.paypal.me/ITDominator",);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.target.tagName == "LI" && e.target.className.includes("sessionLI")) {
|
|
||||||
if (selectedItem) {
|
|
||||||
if (selectedItem == e.target && selectedItem.className == "sessionLI selected") {
|
|
||||||
selectedItem.setAttribute("class", "sessionLI");
|
selectedItem.setAttribute("class", "sessionLI");
|
||||||
selectedItem = null;
|
selectedItem = null;
|
||||||
} else {
|
} else {
|
||||||
selectedItem.setAttribute("class", "sessionLI");
|
selectedItem.setAttribute("class", "sessionLI");
|
||||||
selectedItem = e.target;
|
selectedItem = target;
|
||||||
selectedItem.setAttribute("class", "sessionLI selected");
|
selectedItem.setAttribute("class", "sessionLI selected");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectedItem = e.target;
|
selectedItem = target;
|
||||||
selectedItem.setAttribute("class", "sessionLI selected");
|
selectedItem.setAttribute("class", "sessionLI selected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If elm has certain action do it.
|
||||||
|
const selectedItemName = (selectedItem !== null) ? selectedItem.getAttribute("name") : "";
|
||||||
|
if (/(download|delete|edit)/.test(action)) {
|
||||||
|
if (selectedItem) {
|
||||||
|
if (action == "download")
|
||||||
|
downloadSession(selectedItemName);
|
||||||
|
else if (action == "delete")
|
||||||
|
deleteFromStorage(selectedItem);
|
||||||
|
else if (action == "edit")
|
||||||
|
editSession(selectedItem, selectedItemName);
|
||||||
|
} else {
|
||||||
|
messageWindow("warning", "Select a session first...");
|
||||||
|
}
|
||||||
|
} else if (action == "save") {
|
||||||
|
saveSession(selectedItem, selectedItemName);
|
||||||
|
} else if (action == "import") {
|
||||||
|
importSession();
|
||||||
|
} else if (action == "donate") {
|
||||||
|
doUrlAction("https://www.paypal.me/ITDominator",);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,7 +49,7 @@ document.addEventListener("dblclick", (e) => {
|
||||||
if (e.button == 0) { // Left click
|
if (e.button == 0) { // Left click
|
||||||
if (e.target.tagName == "LI" && e.target.className.includes("sessionLI")) {
|
if (e.target.tagName == "LI" && e.target.className.includes("sessionLI")) {
|
||||||
selectedItem = e.target;
|
selectedItem = e.target;
|
||||||
let id = selectedItem.innerText.trim();
|
const id = selectedItem.innerText.trim();
|
||||||
selectedItem.setAttribute("class", "sessionLI selected");
|
selectedItem.setAttribute("class", "sessionLI selected");
|
||||||
preLoadSession(id);
|
preLoadSession(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,13 @@ const windowApi = browser.windows;
|
||||||
const regexp = /^[a-zA-Z0-9-_]+$/; // Alphanumeric, dash, underscore
|
const regexp = /^[a-zA-Z0-9-_]+$/; // Alphanumeric, dash, underscore
|
||||||
|
|
||||||
|
|
||||||
const saveSession = (elm = null, message = message1) => {
|
const saveSession = (elm = null, name = null, message = message1) => {
|
||||||
let inputTag = document.createElement("INPUT");
|
let inputTag = document.createElement("INPUT");
|
||||||
let willReplace = false;
|
let willReplace = false;
|
||||||
inputTag.value = new Date().toLocaleString().split(',')[0].replace(/\//g, '-');
|
inputTag.value = new Date().toLocaleString().split(',')[0].replace(/\//g, '-');
|
||||||
|
|
||||||
if (elm !== null) {
|
if (elm !== null) {
|
||||||
inputTag.value = elm.innerText;
|
inputTag.value = name;
|
||||||
willReplace = true;
|
willReplace = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ const saveSession = (elm = null, message = message1) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const editSession = (elm = null, message = message1) => {
|
const editSession = (elm = null, name = null, message = message1) => {
|
||||||
let id = elm.innerText;
|
let id = name;
|
||||||
let inputTag = document.createElement("INPUT");
|
let inputTag = document.createElement("INPUT");
|
||||||
let newSessionTag = document.createElement("INPUT");
|
let newSessionTag = document.createElement("INPUT");
|
||||||
let labelTag = document.createElement("LABEL");
|
let labelTag = document.createElement("LABEL");
|
||||||
|
@ -85,28 +85,21 @@ const editSession = (elm = null, message = message1) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
json = getSelectionData(container, keys, keysLength);
|
json = getSelectionData(container, keys, keysLength);
|
||||||
|
if (newSessionTag.checked) { // If creating new session
|
||||||
// If creating new session
|
|
||||||
if (newSessionTag.checked) {
|
|
||||||
newName = checkSessionListForDuplicate(newName);
|
newName = checkSessionListForDuplicate(newName);
|
||||||
saveToStorage(newName, JSON.stringify(json), "save");
|
saveToStorage(newName, JSON.stringify(json), "save");
|
||||||
} else {
|
} else {
|
||||||
// If not creating new session and are the same name
|
if (newName == name) { // If not creating new session and are the same name
|
||||||
if (newName == id) {
|
|
||||||
storageApi.get(id).then((results) => {
|
storageApi.get(id).then((results) => {
|
||||||
storageApi.remove(id);
|
storageApi.remove(id);
|
||||||
saveToStorage(newName, JSON.stringify(json), "edit", true);
|
saveToStorage(newName, JSON.stringify(json), "edit", true);
|
||||||
}).then(() => {
|
}).then(() => { elm.innerText = newName; });
|
||||||
elm.innerText = newName;
|
|
||||||
});
|
|
||||||
} else { // If not creating new session and names are not the same rename
|
} else { // If not creating new session and names are not the same rename
|
||||||
storageApi.get(id).then((results) => {
|
storageApi.get(id).then((results) => {
|
||||||
storageApi.remove(id);
|
storageApi.remove(id);
|
||||||
newName = checkSessionListForDuplicate(newName);
|
newName = checkSessionListForDuplicate(newName);
|
||||||
saveToStorage(newName, JSON.stringify(json), "edit");
|
saveToStorage(newName, JSON.stringify(json), "edit");
|
||||||
}).then(() => {
|
}).then(() => { elm.innerText = newName; });
|
||||||
elm.innerText = newName;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,7 +109,7 @@ const editSession = (elm = null, message = message1) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadSession = (elm = null) => {
|
const downloadSession = (session = 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");
|
||||||
|
@ -124,9 +117,8 @@ const downloadSession = (elm = null) => {
|
||||||
let brTag = document.createElement("BR");
|
let brTag = document.createElement("BR");
|
||||||
let aTagElm = document.getElementById('downloadAnchorElem');
|
let aTagElm = document.getElementById('downloadAnchorElem');
|
||||||
let text = document.createTextNode("Append Date?");
|
let text = document.createTextNode("Append Date?");
|
||||||
let id = elm.innerText;
|
let fileName = "session:" + session + ".json";
|
||||||
let fileName = "session:" + id + ".json";
|
let id = session;
|
||||||
|
|
||||||
chkBoxTag.type = "checkbox";
|
chkBoxTag.type = "checkbox";
|
||||||
inputTag.value = fileName;
|
inputTag.value = fileName;
|
||||||
chkBoxTag.id = "chkbx";
|
chkBoxTag.id = "chkbx";
|
||||||
|
@ -144,14 +136,15 @@ const downloadSession = (elm = null) => {
|
||||||
}).then((willDl) => {
|
}).then((willDl) => {
|
||||||
if (willDl) {
|
if (willDl) {
|
||||||
if (chkBoxTag.checked) {
|
if (chkBoxTag.checked) {
|
||||||
fileName = "session:" + id + ":" +
|
fileName = "session:" + id + ":" + new Date().toLocaleString()
|
||||||
new Date().toLocaleString().split(',')[0].replace(/\//g, "-") + ".json";
|
.split(',')[0]
|
||||||
|
.replace(/\//g, "-") + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
storageApi.get(id).then((results) => {
|
storageApi.get(id).then((results) => {
|
||||||
let json = JSON.parse(results[id]);
|
let json = JSON.parse(results[id]);
|
||||||
console.log("Downloading: " + id);
|
|
||||||
let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json));
|
let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json));
|
||||||
|
console.log("Downloading: " + id);
|
||||||
doUrlAction(dataStr, fileName, true);
|
doUrlAction(dataStr, fileName, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,12 +59,12 @@ const checkSessionListForDuplicate = (newName) => {
|
||||||
return newName;
|
return newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const appendToSavedSessionsList = (enteryName) => {
|
const appendToSavedSessionsList = (enteryName, storeSize) => {
|
||||||
|
const text = document.createTextNode(storeSize + " | " + enteryName);
|
||||||
let liTag = document.createElement("LI");
|
let liTag = document.createElement("LI");
|
||||||
let text = document.createTextNode(enteryName.trim());
|
|
||||||
liTag.className = "sessionLI";
|
liTag.className = "sessionLI";
|
||||||
|
|
||||||
liTag.setAttribute("name", enteryName.trim());
|
liTag.setAttribute("name", enteryName);
|
||||||
liTag.append(text);
|
liTag.append(text);
|
||||||
document.getElementById("savedSessions").append(liTag);
|
document.getElementById("savedSessions").append(liTag);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue