commit 956f82f7443e9002081615c3068b46ac36a9c916 Author: Thomas Rupprecht Date: Thu Dec 27 10:37:31 2018 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..65b61b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/web-ext-artifacts \ No newline at end of file diff --git a/background/index.html b/background/index.html new file mode 100644 index 0000000..480157c --- /dev/null +++ b/background/index.html @@ -0,0 +1,8 @@ + + + + + /usr/space + + + \ No newline at end of file diff --git a/background/index.js b/background/index.js new file mode 100644 index 0000000..df9e152 --- /dev/null +++ b/background/index.js @@ -0,0 +1,56 @@ +const fetchJson = (url) => { + return fetch(url).then((response) => (response.json())); +}; + +const fetchCalendar = (days = null) => { + let url = 'https://usrspace.at/calendar.php?o=json'; + if (days) { + url += '&r=' + days; + } + return fetchJson(url); +}; + +const fetchSpaceApi = () => { + return fetchJson('https://usrspace.at/spaceapi'); +}; + +const updateBadge = (open) => { + let badgeText, badgeColor; + if (open) { + badgeText = browser.browserAction.setBadgeText({text: 'open'}); + badgeColor = browser.browserAction.setBadgeBackgroundColor({color: '#00ff00'}); + } else { + badgeText = browser.browserAction.setBadgeText({text: ''}); + badgeColor = browser.browserAction.setBadgeBackgroundColor({color: null}); + } + badgeText.then(() => { + + }).catch((error) => { + console.error(error); + }); + badgeColor.then(() => { + + }).catch((error) => { + console.error(error); + }); +}; + +const fetchNewData = () => { + fetchCalendar().then((json) => { + window.calendar = json; + }).catch((error) => { + console.error(error); + }); + + fetchSpaceApi().then((json) => { + window.spaceApi = json; + updateBadge(window.spaceApi.state.open); + }).catch((error) => { + console.error(error); + }); +}; + +fetchNewData(); +setInterval(() => { + fetchNewData(); +}, 5 * 60 * 1000); \ No newline at end of file diff --git a/icons/logo-19.png b/icons/logo-19.png new file mode 100644 index 0000000..70ec07f Binary files /dev/null and b/icons/logo-19.png differ diff --git a/icons/logo-38.png b/icons/logo-38.png new file mode 100644 index 0000000..9df2140 Binary files /dev/null and b/icons/logo-38.png differ diff --git a/icons/logo-48.png b/icons/logo-48.png new file mode 100644 index 0000000..0f94850 Binary files /dev/null and b/icons/logo-48.png differ diff --git a/icons/logo-96.png b/icons/logo-96.png new file mode 100644 index 0000000..57e2282 Binary files /dev/null and b/icons/logo-96.png differ diff --git a/icons/logo-outline.svg b/icons/logo-outline.svg new file mode 100644 index 0000000..72a0d22 --- /dev/null +++ b/icons/logo-outline.svg @@ -0,0 +1,12 @@ + + + + + + + + /usr/space + Kernel + HW + + diff --git a/icons/logo.png b/icons/logo.png new file mode 100644 index 0000000..6d923a1 Binary files /dev/null and b/icons/logo.png differ diff --git a/icons/logo.svg b/icons/logo.svg new file mode 100644 index 0000000..ca3ff89 --- /dev/null +++ b/icons/logo.svg @@ -0,0 +1,12 @@ + + + + + + + + /usr/space + Kernel + HW + + diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..7ebfbb5 --- /dev/null +++ b/manifest.json @@ -0,0 +1,28 @@ +{ + "manifest_version": 2, + "name": "/usr/space", + "version": "0.1", + "description": "An Add-on for the Hacker-/Maker-Space /usr/space.", + "icons": { + "48": "icons/logo.svg", + "96": "icons/logo.svg" + }, + "background": { + "page": "background/index.html" + }, + "browser_action": { + "browser_style": true, + "default_title": "/usr/space", + "default_icon": "icons/logo.svg", + "default_area": "navbar", + "default_popup": "popup/index.html" + }, + "permissions": [ + "https://usrspace.at/*", + "webRequest" + ], + "developer": { + "name": "Thomas Rupprecht", + "url": "https://blog.ximex.at/" + } +} diff --git a/popup/index.css b/popup/index.css new file mode 100644 index 0000000..c0f8eb0 --- /dev/null +++ b/popup/index.css @@ -0,0 +1,4 @@ +#space-api { + font-family: monospace; + font-size: 10px; +} \ No newline at end of file diff --git a/popup/index.html b/popup/index.html new file mode 100644 index 0000000..7251328 --- /dev/null +++ b/popup/index.html @@ -0,0 +1,43 @@ + + + + + /usr/space + + + +
+
/usr/space
+
/usr/space
+
+

Links

+
+ + + + +
+

Nächster Termine

+
loading...
+

Infos

+
loading...
+ + + + diff --git a/popup/index.js b/popup/index.js new file mode 100644 index 0000000..290429d --- /dev/null +++ b/popup/index.js @@ -0,0 +1,42 @@ +Array.from(document.getElementsByClassName('link')).forEach((element) => { + element.addEventListener('click', (event) => { + const newTab = browser.tabs.create({ + url: event.currentTarget.dataset.url + }); + newTab.then((data) => { + // console.log(data); + }).catch((error) => { + console.error(error); + }); + }); +}); + +browser.runtime.getBackgroundPage().then((page) => { + updateNextEvent(page.calendar[0]); + updateSpaceApiJson(page.spaceApi); +}).catch((error) => { + console.error(error); +}); + +const updateNextEvent = (nextEvent) => { + const calendarElement = document.getElementById('calendar'); + const strongElement = document.createElement('strong'); + strongElement.textContent = nextEvent.name; + const dateNode = document.createTextNode(' ' + new Date(nextEvent.begin).toLocaleString()); + calendarElement.innerText = ''; + calendarElement.append(strongElement); + calendarElement.append(dateNode); + if (nextEvent.location) { + const locationNode = document.createTextNode(' (' + nextEvent.location + ')'); + calendarElement.append(locationNode); + } +}; + +const updateSpaceApiJson = (spaceApi) => { + const spaceApiElement = document.getElementById('space-api'); + const json = JSON.stringify(spaceApi, null, 2).replace(/ /g, ' ').replace(/\n/g, '
'); + spaceApiElement.innerHTML = json; + // const jsonNode = document.createTextNode(json); + // spaceApiElement.innerText = ''; + // spaceApiElement.append(jsonNode); +};