forked from XimeX/usrspace-browser-addon
store data in localStorage
This commit is contained in:
parent
4f717f7c80
commit
fc2ad7afad
|
@ -45,7 +45,8 @@ async function fetchNewData() {
|
|||
await browser.browserAction.setBadgeText({text: badgeText});
|
||||
await browser.browserAction.setBadgeBackgroundColor({color: badgeBgColor});
|
||||
|
||||
if (window.spaceApi && window.spaceApi.state.open !== spaceApiJson.state.open) {
|
||||
const spaceApi = JSON.parse(localStorage.getItem('spaceApi'));
|
||||
if (spaceApi && spaceApi.state.open !== spaceApiJson.state.open) {
|
||||
const state = browser.i18n.getMessage(spaceApiJson.state.open ? 'open' : 'closed');
|
||||
await browser.notifications.create('status-change', {
|
||||
type: 'basic',
|
||||
|
@ -56,8 +57,8 @@ async function fetchNewData() {
|
|||
}
|
||||
}
|
||||
|
||||
window.calendar = calendarJson;
|
||||
window.spaceApi = spaceApiJson;
|
||||
localStorage.setItem('calendar', JSON.stringify(calendarJson));
|
||||
localStorage.setItem('spaceApi', JSON.stringify(spaceApiJson));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
|
17
src/popup.js
17
src/popup.js
|
@ -49,20 +49,21 @@ async function init() {
|
|||
linkElement.addEventListener('click', linkElementClickListener);
|
||||
});
|
||||
|
||||
try {
|
||||
const page = await browser.runtime.getBackgroundPage();
|
||||
const calendar = JSON.parse(localStorage.getItem('calendar'));
|
||||
const spaceApi = JSON.parse(localStorage.getItem('spaceApi'));
|
||||
|
||||
updateNextEvent(page.calendar);
|
||||
updateSpaceApiJson(page.spaceApi);
|
||||
updateState(page.spaceApi);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (calendar) {
|
||||
updateNextEvent(calendar);
|
||||
}
|
||||
if (spaceApi) {
|
||||
updateSpaceApiJson(spaceApi);
|
||||
updateState(spaceApi);
|
||||
}
|
||||
}
|
||||
init();
|
||||
|
||||
/**
|
||||
* @param {object} nextEvents
|
||||
* @param {Array<object>} nextEvents
|
||||
*/
|
||||
function updateNextEvent(nextEvents) {
|
||||
const calendarElement = document.getElementById('calendar');
|
||||
|
|
Loading…
Reference in New Issue