diff --git a/README.md b/README.md index 2189a28..48e03b9 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ Easy Session Manager allows you to manage your Firefox session by backing up or # Download https://addons.mozilla.org/en-US/firefox/addon/easy-session-manager/ -# Version: 0.1.4 -Added on save grab selected item name if applicable. Fixed clearing of selected item. +# Version: 0.1.6 +Added selective opening of tabs. +Added new or current session opening of tabs. # Images ![1 Default interface with no sessions. ](images/pic1.png) diff --git a/images/pic1.png b/images/pic1.png index e023c15..28df0df 100644 Binary files a/images/pic1.png and b/images/pic1.png differ diff --git a/images/pic2.png b/images/pic2.png index e8ce5ff..d09a4e3 100644 Binary files a/images/pic2.png and b/images/pic2.png differ diff --git a/images/pic3.png b/images/pic3.png index 572e720..ae6ac4d 100644 Binary files a/images/pic3.png and b/images/pic3.png differ diff --git a/images/pic4.png b/images/pic4.png index 31698b0..70bb283 100644 Binary files a/images/pic4.png and b/images/pic4.png differ diff --git a/images/pic5.png b/images/pic5.png index 0c5d561..d806f61 100644 Binary files a/images/pic5.png and b/images/pic5.png differ diff --git a/images/pic6.png b/images/pic6.png index 9b9e800..359f695 100644 Binary files a/images/pic6.png and b/images/pic6.png differ diff --git a/images/pic7.png b/images/pic7.png index a1da030..ac04356 100644 Binary files a/images/pic7.png and b/images/pic7.png differ diff --git a/src/images/icons/donate.png b/src/images/icons/donate.png new file mode 100644 index 0000000..c2a01b0 Binary files /dev/null and b/src/images/icons/donate.png differ diff --git a/src/pages/sessionManager.html b/src/pages/sessionManager.html index 15c914e..9f8a69e 100755 --- a/src/pages/sessionManager.html +++ b/src/pages/sessionManager.html @@ -7,42 +7,44 @@
- + + + - - +

+ + + +
- - - - - - - - + + +
+ + + + + - - - diff --git a/src/scripts/events.js b/src/scripts/events.js index 928826e..7b72ad9 100644 --- a/src/scripts/events.js +++ b/src/scripts/events.js @@ -1,45 +1,150 @@ let selectedItem = null; +const toggleSelect = (name) => { + let checkboxes = document.getElementsByName(name); + for (var i = 0; i < checkboxes.length; i++) { + checkboxes[i].checked = !checkboxes[i].checked; + } +} + document.addEventListener("click", (e) => { if (e.button == 0) { // Left click let name = e.target.name; - if (e.target.tagName == "LI") { + + if (/(download|delete|edit)/.test(name)) { if (selectedItem) { - if (selectedItem == e.target && selectedItem.className == "selected") { - selectedItem.setAttribute("class", ""); - selectedItem = null; - } else { - selectedItem.setAttribute("class", ""); - selectedItem = e.target; - selectedItem.setAttribute("class", "selected"); - } + if (name == "download") + downloadSession(selectedItem); + else if (name == "delete") + deleteFromStorage(selectedItem); + else if (name == "edit") + editSession(selectedItem); } else { - selectedItem = e.target; - selectedItem.setAttribute("class", "selected"); + swal("Select a session first...", { + icon: "warning", + }); } } else if (name == "save") { saveSession(selectedItem); } else if (name == "import") { importSession(); - } else if (selectedItem) { - if (name == "download") - downloadSession(selectedItem); - else if (name == "delete") - deleteFromStorage(selectedItem); - else if (name == "edit") - editSession(selectedItem); - } else if (/(download|delete|edit)/.test(name)) { - swal("Select a session first...", { - icon: "warning", - }); + } else if (name == "donate") { + var dlAnchorElem = document.getElementById('downloadAnchorElem'); + dlAnchorElem.setAttribute("href", "https://www.paypal.me/ITDominator"); + dlAnchorElem.setAttribute("_blank", ""); + dlAnchorElem.click(); + } + + 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 = null; + } else { + selectedItem.setAttribute("class", "sessionLI"); + selectedItem = e.target; + selectedItem.setAttribute("class", "sessionLI selected"); + } + } else { + selectedItem = e.target; + selectedItem.setAttribute("class", "sessionLI selected"); + } } } }); document.addEventListener("dblclick", (e) => { if (e.button == 0) { // Left click - if (e.target.tagName == "LI") { - loadSession(e.target.innerHTML.trim()); + if (e.target.tagName == "LI" && e.target.className.includes("sessionLI")) { + selectedItem = e.target; + selectedItem.setAttribute("class", "sessionLI selected"); + try { + let id = e.target.innerHTML.trim(); + storage.get(id).then(storageResults => { + let json = JSON.parse(storageResults[id]); + let keys = Object.keys(json); + let keysLength = Object.keys(json).length; + let replaceTabs = document.getElementsByName("replaceTabs")[0]; + let selectiveOpen = document.getElementsByName("selectiveOpen")[0]; + + if (!selectiveOpen.checked) { + loadSession(json, replaceTabs.checked); + } else { + let container = document.createElement("DIV"); + let ulTemplate = document.querySelector('#ulTemplate'); + let liTemplate = document.querySelector('#liTemplate'); + + for (let i = 0; i < keysLength; i++) { + let ulClone = document.importNode(ulTemplate.content, true); + let ulTag = ulClone.querySelector('.collection'); + let h2Txt = document.createTextNode("Window: " + (i + 1)); + let store = json[keys[i]]; + let j = 0; + + store.forEach(tab => { + let liClone = document.importNode(liTemplate.content, true); + let inptTag = liClone.querySelector("input"); + let lblTag = liClone.querySelector("label"); + let labelTxt = document.createTextNode(tab.link); + inptTag.id = "Win" + i + "Li" + j; + lblTag.htmlFor = "Win" + i + "Li" + j; + lblTag.title = tab.link; + inptTag.setAttribute("name", "Win" + i); + lblTag.appendChild(labelTxt); + ulTag.appendChild(liClone); + j++; + }); + + container.id = "editSelectionContainer"; + ulClone.querySelector('#selectAll') + .addEventListener("click", function () { + toggleSelect("Win" + i); + }); + ulClone.querySelector('.ulHeader').appendChild(h2Txt); + container.appendChild(ulClone); + } + + swal("Selective Open", { + content: container, + buttons: true, + }).then((willOpen) => { + if (willOpen) { + let sessionData = {}; + let ulTags = container.querySelectorAll("ul"); + + for (let i = 0; i < keysLength; i++) { + let links = []; + + for (var ii = 0; ii < ulTags[i].children.length; ii++) { + let li = ulTags[i].children[ii]; + if (li.children[0].checked) { + links.push( + {"link" : li.children[1].title.trim()} + ); + } + } + + if (links.length > 0) { + sessionData[keys[i]] = links; + } + } + + json = sessionData; + keysLength = Object.keys(json).length; + if (keysLength > 0) { + loadSession(json, replaceTabs.checked); + } else { + swal("Canceled operation; no tabs were selected...", { + icon: "warning", + }); + } + } + }); + } + }); + } catch (e) { + console.log(e); + } } } }); diff --git a/src/scripts/sessionManager.js b/src/scripts/sessionManager.js index 45240e7..a82ebe6 100644 --- a/src/scripts/sessionManager.js +++ b/src/scripts/sessionManager.js @@ -172,7 +172,8 @@ const downloadSession = (elm = null) => { swal("Download Session?", { content: pTag, buttons: true, - }).then((willDl) => { if (willDl) { + }).then((willDl) => { + if (willDl) { if (chkBoxTag.checked) { fileName = "session:" + id + ":" + new Date().toLocaleString().split(',')[0].replace(/\//g, "-") + ".json"; @@ -183,24 +184,23 @@ const downloadSession = (elm = null) => { let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json)); dlAnchorElem.setAttribute("href", dataStr); dlAnchorElem.setAttribute("download", fileName); + dlAnchorElem.setAttribute("target", ""); dlAnchorElem.click(); }); } }); } -const loadSession = (id = null) => { +const loadSession = (json = null, replaceTabs = false) => { console.log("Loading session..."); + let keys = Object.keys(json); + let keysLength = Object.keys(json).length; try { - storage.get(id).then(storageResults => { - let json = JSON.parse(storageResults[id]); - let keys = Object.keys(json); - let keysLength = Object.keys(json).length; - - browser.windows.getAll().then(windows => { - windowSys.getCurrent({populate: true}).then(currentWindow => { - let wasCurrentTabId = null; + browser.windows.getAll().then(windows => { + windowSys.getCurrent({populate: true}).then(currentWindow => { + let wasCurrentTabId = null; + if (replaceTabs) { // Clear all windows but main then load... // Clear all non-current windows and then current window's tabs for (let i = 0; i < windows.length; i++) { if (currentWindow.id != windows[i].id) { @@ -223,26 +223,35 @@ const loadSession = (id = null) => { store.forEach(tab => { browser.tabs.create({ url: tab.link }); }); + browser.tabs.remove(wasCurrentTabId); // If more than one window, load tabs to new windows. - browser.tabs.remove(wasCurrentTabId); if (keysLength > 1) { - for (let i = 1; i < keysLength; i++) { - let store = json[keys[i]]; - let urls = []; - - for (let j = 0; j < store.length; j++) { - urls.push(store[j].link); - } - windowSys.create({ url: urls }); - } + windowMaker(1, keysLength, keys, json) } - }); + } else { // Load into new windows... + if (keysLength > 0) { + windowMaker(0, keysLength, keys, json) + } + } + }); }); } catch (e) { console.log(e); } } +const windowMaker = (i, keysLength, keys, json) => { + for (; i < keysLength; i++) { + let store = json[keys[i]]; + let urls = []; + + for (let j = 0; j < store.length; j++) { + urls.push(store[j].link); + } + windowSys.create({ url: urls }); + } +} + const getSavedSessionIDs = () => { console.log("Getting saved sessions..."); storage.get(null).then((storageResults) => { @@ -254,9 +263,10 @@ const getSavedSessionIDs = () => { } const appendToSavedSessionsList = (enteryName) => { - let liTag = document.createElement("LI"); - let text = document.createTextNode(enteryName); - liTag.setAttribute("name", enteryName); + let liTag = document.createElement("LI"); + let text = document.createTextNode(enteryName.trim()); + liTag.setAttribute("name", enteryName.trim()); + liTag.className = "sessionLI"; liTag.append(text); document.getElementById("savedSessions").append(liTag); } diff --git a/src/styles/styles.css b/src/styles/styles.css index 72c55e9..5ea3d55 100644 --- a/src/styles/styles.css +++ b/src/styles/styles.css @@ -6,36 +6,51 @@ body { ul, li { list-style: none; } -li { - background-color: #0a1827; - color: #ffffff; - margin: 1em 0em; - padding: 1.5em; - text-align: center; -} - -li:hover { - background-color: #1e4573; - cursor: pointer; -} - -button { +input[type=image] { + width: 2.5em; + height: 2.5em; + padding: 0.4em; background-color: #ffffff; color: #000000; } +input[type=image]:hover { + cursor: pointer; + background-color: #a3b83b; + color: #ffffff; +} + #savedSessions { - height: 445px; - min-height: 445px; - max-height: 445px; + height: 365px; + min-height: 365x; + max-height: 365px; overflow-x: hidden; overflow-y: auto; + margin-bottom: 0.6em; + margin-top: 0.6em; +} + +#editSelectionContainer { + height: 350px; + min-height: 350x; + max-height: 350px; + white-space: nowrap; + display: block; + overflow-x: auto; +} + +#editSelectionContainer > ul > li { + float: left; } #inputId { display: none; } +#selectAll { + margin-bottom: 1.5em; +} + #lableTag { top: 48%; margin: 0 auto; @@ -59,6 +74,19 @@ button { cursor: pointer; } +.sessionLI { + background-color: #0a1827; + color: #ffffff; + margin: 1em 0em; + padding: 1.5em; + text-align: center; +} + +.sessionLI:hover { + background-color: #1e4573; + cursor: pointer; +} + .selected { background-color: #a3b83b; box-shadow: 0px 5px 5px 5px #444444;