Skip to content

Commit

Permalink
Add settings for API key
Browse files Browse the repository at this point in the history
  • Loading branch information
julijonas committed Jan 20, 2018
1 parent e83eb90 commit 042e2c8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions emojifier.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
let apiKey;
browser.storage.local.get('apiKey').then((data) => {
apiKey = data.apiKey;
console.log('API key', apiKey);
});

let imgNode;

Expand Down
8 changes: 7 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
"48": "icons/border-48.png"
},

"options_ui": {
"page": "options.html"
},

"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["emojifier.js"]
}
]
],

"permissions": ["storage"]

}
19 changes: 19 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
</head>

<body>

<form>
<label>Microsoft API key<input type="text" id="apiKey" ></label>
<button type="submit">Save</button>
</form>

<script src="options.js"></script>

</body>

</html>
24 changes: 24 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function saveOptions(e) {
e.preventDefault();
console.log(document)
browser.storage.local.set({
apiKey: document.querySelector("#apiKey").value
});
}

function restoreOptions() {

function setCurrentChoice(result) {
document.querySelector("#apiKey").value = result.apiKey || "";
}

function onError(error) {
console.log(`Error: ${error}`);
}

var getting = browser.storage.local.get("apiKey");
getting.then(setCurrentChoice, onError);
}

document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);

0 comments on commit 042e2c8

Please sign in to comment.