This commit is contained in:
Thomas Rupprecht 2018-12-27 10:37:31 +01:00
commit 956f82f744
14 changed files with 206 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/web-ext-artifacts

8
background/index.html Normal file
View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>/usr/space</title>
<script type="module" src="index.js"></script>
</head>
</html>

56
background/index.js Normal file
View File

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

BIN
icons/logo-19.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/logo-38.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
icons/logo-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
icons/logo-96.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

12
icons/logo-outline.svg Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="10cm" height="10cm" viewBox="0 0 100 100">
<g>
<rect width="100%" height="100%" fill="#ffffff"/>
<path d="M10 19.5A66 66 0 0 1 90 19.5L76.7 37.0A44 44 0 0 0 23.3 37.0Z" fill="none" stroke="#111111"/>
<path d="M10 53.7A44 44 0 0 1 90 53.7L70.0 62.8A22 22 0 0 0 30.0 62.8Z" fill="none" stroke="#666666"/>
<circle cx="50" cy="72" r="22" fill="none" stroke="#bbbbbb"/>
<text x="50" y="24" font-family="Liberation Sans" font-size="14px" text-anchor="middle" fill="#111111" dx="6px">/usr/space</text>
<text x="50" y="47" font-family="Liberation Sans" font-size="14px" text-anchor="middle" fill="#666666">Kernel</text>
<text x="50" y="72" font-family="Liberation Sans" font-size="14px" text-anchor="middle" fill="#bbbbbb" font-weight="bold" dy="5.5px">HW</text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 918 B

BIN
icons/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

12
icons/logo.svg Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="10cm" height="10cm" viewBox="0 0 100 100">
<g>
<rect width="100%" height="100%" fill="#ffffff"/>
<path d="M10 19.5A66 66 0 0 1 90 19.5L76.7 37.0A44 44 0 0 0 23.3 37.0Z" fill="#111111" stroke="none"/>
<path d="M10 53.7A44 44 0 0 1 90 53.7L70.0 62.8A22 22 0 0 0 30.0 62.8Z" fill="#666666" stroke="none"/>
<circle cx="50" cy="72" r="22" fill="#bbbbbb" stroke="none"/>
<text x="50" y="24" font-family="Liberation Sans" font-size="14px" text-anchor="middle" fill="#ffffff" dx="6px">/usr/space</text>
<text x="50" y="47" font-family="Liberation Sans" font-size="14px" text-anchor="middle" fill="#ffffff">Kernel</text>
<text x="50" y="72" font-family="Liberation Sans" font-size="14px" text-anchor="middle" fill="#ffffff" font-weight="bold" dy="5.5px">HW</text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 918 B

28
manifest.json Normal file
View File

@ -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/"
}
}

4
popup/index.css Normal file
View File

@ -0,0 +1,4 @@
#space-api {
font-family: monospace;
font-size: 10px;
}

43
popup/index.html Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>/usr/space</title>
<link rel="stylesheet" href="index.css"/>
</head>
<body>
<header class="panel-section panel-section-header">
<div class="icon-section-header"><img src="../icons/logo.svg" width="32" height="32" alt="/usr/space" /></div>
<div class="text-section-header">/usr/space</div>
</header>
<h2>Links</h2>
<div class="panel-section panel-section-list">
<div class="panel-list-item link" data-url="https://usrspace.at/">
<div class="icon"><img src="../icons/logo.svg" width="19" height="19" alt="/usr/space" /></div>
<div class="text">Homepage</div>
<div class="text-shortcut"></div>
</div>
<div class="panel-list-item link" data-url="https://www.usrspace.at/w/">
<div class="icon"></div>
<div class="text">Wiki</div>
<div class="text-shortcut"></div>
</div>
<div class="panel-list-item link" data-url="https://gitlab.usrspace.at/">
<div class="icon"></div>
<div class="text">Gitlab</div>
<div class="text-shortcut"></div>
</div>
<div class="panel-list-item link" data-url="https://cloud.usrspace.at/">
<div class="icon"></div>
<div class="text">NextCloud</div>
<div class="text-shortcut"></div>
</div>
</div>
<h2>Nächster Termine</h2>
<div id="calendar">loading...</div>
<h2>Infos</h2>
<pre><code id="space-api">loading...</code></pre>
<script src="index.js"></script>
</body>
</html>

42
popup/index.js Normal file
View File

@ -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, '&nbsp;').replace(/\n/g, '<br/>');
spaceApiElement.innerHTML = json;
// const jsonNode = document.createTextNode(json);
// spaceApiElement.innerText = '';
// spaceApiElement.append(jsonNode);
};