Added import feature.

This commit is contained in:
Maxim Stewart 2018-11-11 15:12:26 -06:00
parent b1e4119565
commit 3cb7ee5324
16 changed files with 110 additions and 7 deletions

View File

@ -4,8 +4,8 @@ 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.0.1
Released Program
# Version: 0.0.2
Added import functionality for json.
# Images
![1 Default interface with no sessions. ](images/pic1.png)
@ -15,3 +15,4 @@ Released Program
![5 Deleting a selected session. ](images/pic5.png)
![6 Editing a selected session. ](images/pic6.png)
![7 Downloading a selected session. ](images/pic7.png)
![8 Importiog a session json file. ](images/pic7.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 40 KiB

BIN
images/pic8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

BIN
src/images/icons/import.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": " Easy Session Manager",
"version": "0.0.1",
"version": "0.0.2",
"description": " Easy Session Manager allows you to manage your Firefox session by backing up or loading your saved sessions.",
"applications": {
@ -23,6 +23,8 @@
"unlimitedStorage"
],
"background": { "page": "pages/import.html" },
"browser_action": {
"default_icon": "images/icons/sessionManager.png",
"default_title": " Easy Session Manager",

57
src/pages/import.html Normal file
View File

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Easy Session Manager Import</title>
<link rel="shortcut icon" href="../images/icons/import.png">
<style media="screen">
body, html {
width: 100%;
height: 100%;
padding: 0em;
margin: 0em;
}
#inputId {
display: none;
}
#lableTag {
top: 48%;
margin: 0 auto;
color: rgba(255, 255, 255, 0.5);
}
.container {
width: 100%;
height: 100%;
background-image: url('../images/icons/import.png');
background-repeat: no-repeat;
background-position: center;
text-align: center;
background-color: rgba(41, 95, 115, 0.85);
}
.container:hover {
transition: 4;
background-color: rgba(41, 95, 115, 0.65);
cursor: pointer;
}
</style>
</head>
<body>
<div class="container" name="import">
<h1 id="lableTag">Select File</h1>
<input id="inputId" type="file" accept="application/json"/>
</div>
<script src="../scripts/background.js"></script>
</body>
</html>

View File

@ -7,12 +7,23 @@
<body>
<center>
<button type="button" name="import">
Import <img class="icon" src="../images/icons/import.png" alt="Import JSON"/>
<input id="inputId" type="file" />
</button>
<button type="button" name="save">
Save <img class="icon" src="../images/icons/save.png" alt="Save Image"/>
</button>
<button type="button" name="download">
Download <img class="icon" src="../images/icons/download.png" alt="Download Image"/>
</button>
<div id="savedSessions">
</div>
<button type="button" name="edit">
Edit <img class="icon" src="../images/icons/edit.png" alt="Edit Image"/>
</button>
@ -20,10 +31,6 @@
<button type="button" name="delete">
Delete <img class="icon" src="../images/icons/delete.png" alt="Delete Image"/>
</button>
<div id="savedSessions">
</div>
</center>

23
src/scripts/background.js Normal file
View File

@ -0,0 +1,23 @@
document.getElementById("inputId").onchange = (e) => {
var reader = new FileReader();
reader.onloadend = function(obj){
let data = obj.target.result;
let enteryName = prompt("What is this session's name?", "" + new Date().toLocaleString()
.split(',')[0]);
if (enteryName) {
browser.storage.local.set({[enteryName]: data});
}
};
if (e.target.files[0].type == "application/json")
reader.readAsText(e.target.files[0], {encoding: "string"});
};
document.addEventListener("click", (e) => {
if (e.button == 0) { // Left click
if (e.target.className == "container") {
document.getElementById("inputId").click();
}
}
});

View File

@ -17,6 +17,8 @@ document.addEventListener("click", (e) => {
}
} else if (e.target.name == "save") {
saveSession();
} else if (e.target.name == "import") {
importSession();
} else if (selectedItem) {
if (e.target.name == "download")
downloadSession();

View File

@ -37,6 +37,13 @@ const saveToStorage = (name, data) => {
storage.set({[name]: data});
}
const importSession = () => {
browser.tabs.create({
url: browser.extension.getURL("../pages/import.html"),
active: true
});
}
const downloadSession = () => {
var dlAnchorElem = document.getElementById('downloadAnchorElem');
let id = selectedItem.innerHTML;

View File

@ -19,6 +19,10 @@ button {
color: #000000;
}
#inputId {
display: none;
}
.selected {
background-color: #a3b83b;
box-shadow: 0px 5px 5px 5px #444444;