mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-20 08:13:41 +02:00
finishing my update of the quicknote extension, to get it to use the WebExtensions Storage API.
This commit is contained in:
@@ -4,24 +4,30 @@
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
font-size: 10px;
|
||||
background: white;
|
||||
background: background: rgb(240,240,240);
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 300px;
|
||||
background: rgb(240,240,240);
|
||||
border: 1px solid #ccc;
|
||||
margin: 0 auto;
|
||||
padding: 2px;
|
||||
height: inherit;
|
||||
}
|
||||
|
||||
.outer-wrapper {
|
||||
overflow: auto;
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
background: rgb(240,240,240);
|
||||
}
|
||||
|
||||
.clearfix {
|
||||
|
||||
@@ -20,7 +20,7 @@ initialize();
|
||||
|
||||
function initialize() {
|
||||
chrome.storage.local.get(null,function(results) {
|
||||
var noteKeys = Object.keys(results)
|
||||
var noteKeys = Object.keys(results);
|
||||
for(i = 0; i < noteKeys.length; i++) {
|
||||
var curKey = noteKeys[i];
|
||||
var curValue = results[curKey];
|
||||
@@ -34,15 +34,26 @@ function initialize() {
|
||||
function addNote() {
|
||||
var noteTitle = inputTitle.value;
|
||||
var noteBody = inputBody.value;
|
||||
|
||||
if(!chrome.storage.local.get(noteTitle) && noteTitle !== '' && noteBody !== '') {
|
||||
inputTitle.value = '';
|
||||
inputBody.value = '';
|
||||
displayNote(noteTitle,noteBody);
|
||||
storeNote(noteTitle,noteBody);
|
||||
}
|
||||
chrome.storage.local.get(noteTitle, function(result) {
|
||||
var objTest = Object.keys(result);
|
||||
if(objTest.length < 1 && noteTitle !== '' && noteBody !== '') {
|
||||
inputTitle.value = '';
|
||||
inputBody.value = '';
|
||||
displayNote(noteTitle,noteBody);
|
||||
storeNote(noteTitle,noteBody);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* function to store a new note in storage */
|
||||
|
||||
function storeNote(title, body) {
|
||||
chrome.storage.local.set({ [title] : body }, function() {
|
||||
});
|
||||
}
|
||||
|
||||
/* function to display a note in the note box */
|
||||
|
||||
function displayNote(title, body) {
|
||||
|
||||
/* create note display box */
|
||||
@@ -133,18 +144,17 @@ function displayNote(title, body) {
|
||||
}
|
||||
|
||||
|
||||
/* functions to update and store notes */
|
||||
|
||||
/* function to update notes */
|
||||
|
||||
function updateNote(delNote,newTitle,newBody) {
|
||||
chrome.storage.local.set({ newTitle : newBody }, function() {
|
||||
chrome.storage.local.remove(delNote);
|
||||
displayNote(newTitle, newBody);
|
||||
});
|
||||
}
|
||||
|
||||
function storeNote(title, body) {
|
||||
chrome.storage.local.set({ title : body }, function() {
|
||||
chrome.storage.local.set({ [newTitle] : newBody }, function() {
|
||||
if(delNote !== newTitle) {
|
||||
chrome.storage.local.remove(delNote, function() {
|
||||
displayNote(newTitle, newBody);
|
||||
});
|
||||
} else {
|
||||
displayNote(newTitle, newBody);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user