Compare commits

...

3 commits

Author SHA1 Message Date
Thomas Rupprecht fc2ad7afad store data in localStorage 2022-12-25 02:33:24 +01:00
Thomas Rupprecht 4f717f7c80 update package-lock 2022-12-25 01:56:54 +01:00
Thomas Rupprecht a1cf58d8d3 move manifest and _locales into src 2022-12-25 01:52:02 +01:00
7 changed files with 23 additions and 18 deletions

1
package-lock.json generated
View file

@ -7,6 +7,7 @@
"": {
"name": "usrspace-browser-addon",
"version": "0.8.0",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"webextension-polyfill": "^0.10.0"

View file

@ -11,7 +11,9 @@
"scripts": {
"copy-browser-polyfill": "cp node_modules/webextension-polyfill/dist/browser-polyfill.js src/browser-polyfill.js",
"copy-version": "sed -i 's/^\t\"version\": \".*\",$/\t\"version\": \"'$(rg '^\t\"version\": \"(.+)\",$' -r '$1' < package.json)'\",/' manifest.json",
"build": "web-ext build -o -n \"_usr_space-{version}.zip\" -i README.md package.json package-lock.json",
"prebuild": "cp LICENSE.txt src/",
"build": "web-ext build -o -s src/ -n \"_usr_space-{version}.zip\"",
"postbuild": "rm src/LICENSE.txt",
"test": "echo \"Error: no test specified\" && exit 0",
"postinstall": "npm run copy-browser-polyfill",
"preversion": "npm test",

View file

@ -45,19 +45,20 @@ 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',
title: browser.i18n.getMessage('stateNotificationTitle'),
message: browser.i18n.getMessage('stateNotificationMessage', state),
iconUrl: browser.runtime.getURL('src/icons/favicon.svg')
iconUrl: browser.runtime.getURL('icons/favicon.svg')
});
}
}
window.calendar = calendarJson;
window.spaceApi = spaceApiJson;
localStorage.setItem('calendar', JSON.stringify(calendarJson));
localStorage.setItem('spaceApi', JSON.stringify(spaceApiJson));
} catch (error) {
console.error(error);
}

View file

@ -4,18 +4,18 @@
"description": "__MSG_extensionDescription__",
"version": "0.8.0",
"icons": {
"48": "src/icons/favicon.svg",
"96": "src/icons/favicon.svg"
"48": "icons/favicon.svg",
"96": "icons/favicon.svg"
},
"background": {
"page": "src/background.html"
"page": "background.html"
},
"browser_action": {
"browser_style": true,
"default_title": "__MSG_buttonTitle__",
"default_icon": "src/icons/favicon.svg",
"default_icon": "icons/favicon.svg",
"default_area": "navbar",
"default_popup": "src/popup.html"
"default_popup": "popup.html"
},
"default_locale": "de",
"permissions": [

View file

@ -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');