Created
May 6, 2018 06:08
-
-
Save psimonyi/081a57930eb685a52f69827fa982c334 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<meta charset='utf-8'> | |
<script src='example.js'></script> | |
<button type='button' class='browser-style' id='set'>Set</button> | |
<button type='button' class='browser-style' id='get'>Get</button> | |
<p id='output'></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function () { | |
let setter = document.getElementById('set'); | |
setter.addEventListener('click', saveSettings); | |
let getter = document.getElementById('get'); | |
getter.addEventListener('click', getSettings); | |
}) | |
function onGot (item) { | |
console.log(item) | |
document.getElementById('output').textContent = JSON.stringify(item); | |
} | |
function onError (error) { | |
console.log('Error:', error) | |
document.getElementById('output').textContent = JSON.stringify(item); | |
} | |
function getSettings () { | |
let gettingItem = browser.storage.local.get('kitten') | |
gettingItem.then(onGot, onError) | |
} | |
function saveSettings () { | |
browser.storage.local.set({ | |
kitten: {name:"Mog", eats:"mice"}, | |
monster: {name:"Kraken", eats:"people"} | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "example", | |
"browser_action": { | |
"browser_style": true, | |
"default_popup": "example.html" | |
}, | |
"permissions": [ | |
"storage" | |
], | |
"version": "0" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment