forked from XimeX/usrspace-browser-addon
improve config
This commit is contained in:
parent
85fd3fd86a
commit
f97b9a7538
|
@ -1,4 +1,4 @@
|
|||
import Config from './config.js';
|
||||
import { REFRESH_TIMEOUT, API_URLS, BADGE_COLORS } from './config.js';
|
||||
|
||||
document.querySelector('html').setAttribute('lang', browser.i18n.getUILanguage());
|
||||
|
||||
|
@ -16,7 +16,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 +27,7 @@ function fetchCalendar(days = 28) {
|
|||
* @returns {Promise<object>}
|
||||
*/
|
||||
function fetchSpaceApi() {
|
||||
return fetchJson(Config.spaceApiUrl);
|
||||
return fetchJson(API_URLS.spaceApi);
|
||||
}
|
||||
|
||||
async function fetchNewData() {
|
||||
|
@ -43,7 +43,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,10 +87,10 @@ 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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
];
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue