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.setBadgeText({text: badgeText});
|
||||||
await browser.browserAction.setBadgeBackgroundColor({color: badgeBgColor});
|
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');
|
const state = browser.i18n.getMessage(spaceApiJson.state.open ? 'open' : 'closed');
|
||||||
await browser.notifications.create('status-change', {
|
await browser.notifications.create('status-change', {
|
||||||
type: 'basic',
|
type: 'basic',
|
||||||
|
@ -56,8 +57,8 @@ async function fetchNewData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.calendar = calendarJson;
|
localStorage.setItem('calendar', JSON.stringify(calendarJson));
|
||||||
window.spaceApi = spaceApiJson;
|
localStorage.setItem('spaceApi', JSON.stringify(spaceApiJson));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
17
src/popup.js
17
src/popup.js
|
@ -49,20 +49,21 @@ async function init() {
|
||||||
linkElement.addEventListener('click', linkElementClickListener);
|
linkElement.addEventListener('click', linkElementClickListener);
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const calendar = JSON.parse(localStorage.getItem('calendar'));
|
||||||
const page = await browser.runtime.getBackgroundPage();
|
const spaceApi = JSON.parse(localStorage.getItem('spaceApi'));
|
||||||
|
|
||||||
updateNextEvent(page.calendar);
|
if (calendar) {
|
||||||
updateSpaceApiJson(page.spaceApi);
|
updateNextEvent(calendar);
|
||||||
updateState(page.spaceApi);
|
}
|
||||||
} catch (error) {
|
if (spaceApi) {
|
||||||
console.error(error);
|
updateSpaceApiJson(spaceApi);
|
||||||
|
updateState(spaceApi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} nextEvents
|
* @param {Array<object>} nextEvents
|
||||||
*/
|
*/
|
||||||
function updateNextEvent(nextEvents) {
|
function updateNextEvent(nextEvents) {
|
||||||
const calendarElement = document.getElementById('calendar');
|
const calendarElement = document.getElementById('calendar');
|
||||||
|
|
Loading…
Reference in a new issue