Compare commits

..

9 Commits

Author SHA1 Message Date
Thomas Rupprecht 5e0182c513 0.8.7 2023-01-20 16:08:31 +01:00
Thomas Rupprecht c216676084 open usrspace.at homepage on install 2023-01-20 16:06:17 +01:00
Thomas Rupprecht 60c367521e remove persistent flag in manifest config 2023-01-20 16:00:08 +01:00
Thomas Rupprecht 05c6cb5cfa remove unnecessary permissions 2023-01-20 15:59:56 +01:00
Thomas Rupprecht 8202083710 use globalThis instead of window to also work in service worker 2023-01-06 02:19:12 +01:00
Thomas Rupprecht f97b9a7538 improve config 2023-01-06 02:02:50 +01:00
Thomas Rupprecht 85fd3fd86a improve badges 2023-01-05 21:51:25 +01:00
Thomas Rupprecht 5dc8680a09 improve README 2023-01-05 21:44:47 +01:00
Thomas Rupprecht 7a255136d2 add badges to README 2023-01-05 21:41:49 +01:00
7 changed files with 67 additions and 52 deletions

View File

@ -1,8 +1,13 @@
# /usr/space Web-Ext (Firefox Add-on)
# /usr/space Web-Extension (Firefox Add-on)
[![Mozilla Add-on](https://img.shields.io/amo/v/usr-space?style=for-the-badge)](https://addons.mozilla.org/de/firefox/addon/usr-space/)
[![Mozilla Add-on](https://img.shields.io/amo/dw/usr-space?style=for-the-badge)](https://addons.mozilla.org/de/firefox/addon/usr-space/)
[![Mozilla Add-on](https://img.shields.io/amo/users/usr-space?style=for-the-badge)](https://addons.mozilla.org/de/firefox/addon/usr-space/)
[![Mozilla Add-on](https://img.shields.io/amo/stars/usr-space?style=for-the-badge)](https://addons.mozilla.org/de/firefox/addon/usr-space/)
## Features
- Show if someone is in the Space
- Looks for connected dynamic IPs (DHCP)
- Looks for connected dynamic IPs (DHCP) (provided by backend)
- Refreshes every 5min
- Show the next event
- Quick-Links (Homepage, Wiki, Gitea, Nextcloud)
@ -26,7 +31,7 @@ Some useful options:
- `--firefox-apk=...`
- `--android-device=...`
Example: `npm run watch:firefox-android -- --firefox-apk=org.mozilla.fenix --firefox-device=XXXXXXXX`.
Example: `npm run watch:firefox-android -- --firefox-apk=org.mozilla.fenix --firefox-device=XXXXXXXX`
## Build
```ssh

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "usrspace-browser-addon",
"version": "0.8.6",
"version": "0.8.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "usrspace-browser-addon",
"version": "0.8.6",
"version": "0.8.7",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {

View File

@ -1,7 +1,7 @@
{
"name": "usrspace-browser-addon",
"description": "WebExtension for the Hacker-/Maker-Space /usr/space",
"version": "0.8.6",
"version": "0.8.7",
"dependencies": {
"webextension-polyfill": "^0.10.0"
},

View File

@ -1,7 +1,15 @@
import Config from './config.js';
import { REFRESH_TIMEOUT, API_URLS, BADGE_COLORS } from './config.js';
document.querySelector('html').setAttribute('lang', browser.i18n.getUILanguage());
browser.runtime.onInstalled.addListener(async (details) => {
if (details.reason === 'install') {
await browser.tabs.create({
url: 'https://www.usrspace.at/',
});
}
});
/**
* @param {string} url
* @returns {Promise<any>}
@ -16,7 +24,7 @@ async function fetchJson(url) {
* @returns {Promise<Array<object>>}
*/
function fetchCalendar(days = 28) {
let url = `${Config.calenderUrl}?o=json`;
let url = `${API_URLS.calender}?o=json`;
if (days) {
url += `&r=${days}`;
}
@ -27,7 +35,7 @@ function fetchCalendar(days = 28) {
* @returns {Promise<object>}
*/
function fetchSpaceApi() {
return fetchJson(Config.spaceApiUrl);
return fetchJson(API_URLS.spaceApi);
}
async function fetchNewData() {
@ -43,7 +51,7 @@ async function fetchNewData() {
)) ?? false;
const badgeText = browser.i18n.getMessage(spaceApiJson.state.open ? 'badgeOpen' : eventActive ? 'badgeEvent' : 'badgeClosed');
const badgeBgColor = spaceApiJson.state.open ? Config.openColor : eventActive ? Config.eventColor : Config.closedColor;
const badgeBgColor = spaceApiJson.state.open ? BADGE_COLORS.open : eventActive ? BADGE_COLORS.event : BADGE_COLORS.closed;
await browser.browserAction.setBadgeText({text: badgeText});
await browser.browserAction.setBadgeBackgroundColor({color: badgeBgColor});
@ -87,20 +95,20 @@ function startFetching() {
browser.alarms.onAlarm.addListener(handleAlarm);
const now = new Date();
now.setMinutes(Math.ceil((now.getMinutes() + 1) / Config.refreshTimeout) * Config.refreshTimeout, 0, 0);
now.setMinutes(Math.ceil((now.getMinutes() + 1) / REFRESH_TIMEOUT) * REFRESH_TIMEOUT, 0, 0);
browser.alarms.create('fetchData', {
when: now.getTime(),
periodInMinutes: Config.refreshTimeout,
periodInMinutes: REFRESH_TIMEOUT,
});
}
window.addEventListener('offline', async () => {
globalThis.addEventListener('offline', async () => {
browser.alarms.onAlarm.removeListener(handleAlarm);
await browser.alarms.clear('fetchData');
});
window.addEventListener('online', () => {
globalThis.addEventListener('online', () => {
startFetching();
});
if (window.navigator.onLine) {
if (globalThis.navigator.onLine) {
startFetching();
}

View File

@ -1,30 +1,35 @@
export default {
refreshTimeout: 5,
spaceApiUrl: 'https://www.usrspace.at/spaceapi.json',
calenderUrl: 'https://www.usrspace.at/calendar.php',
openColor: '#33cc33',
closedColor: '#cc3333',
eventColor: '#9933cc',
quickLinks: [
{
iconTemplateId: 'template-icon-homepage',
url: 'https://www.usrspace.at/',
text: 'Homepage',
},
{
iconTemplateId: 'template-icon-wiki',
url: 'https://wiki.usrspace.at/',
text: 'Wiki',
},
{
iconTemplateId: 'template-icon-gitea',
url: 'https://gitea.usrspace.at/',
text: 'Gitea',
},
{
iconTemplateId: 'template-icon-nextcloud',
url: 'https://cloud.usrspace.at/',
text: 'Nextcloud',
},
],
export const REFRESH_TIMEOUT = 5;
export const API_URLS = {
spaceApi: 'https://www.usrspace.at/spaceapi.json',
calender: 'https://www.usrspace.at/calendar.php',
};
export const BADGE_COLORS = {
open: '#33cc33',
closed: '#cc3333',
event: '#9933cc',
};
export const QUICK_LINKS = [
{
iconTemplateId: 'template-icon-homepage',
url: 'https://www.usrspace.at/',
text: 'Homepage',
},
{
iconTemplateId: 'template-icon-wiki',
url: 'https://wiki.usrspace.at/',
text: 'Wiki',
},
{
iconTemplateId: 'template-icon-gitea',
url: 'https://gitea.usrspace.at/',
text: 'Gitea',
},
{
iconTemplateId: 'template-icon-nextcloud',
url: 'https://cloud.usrspace.at/',
text: 'Nextcloud',
},
];

View File

@ -2,14 +2,13 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "0.8.6",
"version": "0.8.7",
"icons": {
"48": "icons/favicon.svg",
"96": "icons/favicon.svg"
},
"background": {
"page": "background.html",
"persistent": true
"page": "background.html"
},
"browser_action": {
"browser_style": true,
@ -20,11 +19,9 @@
},
"default_locale": "de",
"permissions": [
"https://www.usrspace.at/*",
"alarms",
"notifications",
"storage",
"webRequest"
"storage"
],
"author": "Thomas Rupprecht",
"homepage_url": "https://gitea.usrspace.at/XimeX/usrspace-browser-addon",

View File

@ -1,4 +1,4 @@
import Config from './config.js';
import { QUICK_LINKS } from './config.js';
const dateTimeFormat = Intl.DateTimeFormat([], {dateStyle: 'medium', timeStyle: 'short'});
@ -18,7 +18,7 @@ function setL10n() {
function setLinks() {
const listElement = document.getElementById('link-list');
Config.quickLinks.forEach((quickLink) => {
QUICK_LINKS.forEach((quickLink) => {
const template = getCleanTemplateById('template-link-item');
template.querySelector('.link').dataset.url = quickLink.url;