103 lines
3.5 KiB
JavaScript
103 lines
3.5 KiB
JavaScript
var buttonsize = 250;
|
|
|
|
document.addEventListener("keyup", (event) => {
|
|
if (event.ctrlKey && event.code == "Enter") {
|
|
console.log("pressed");
|
|
var dashboard = document.querySelector('#lit-dashboard');
|
|
isFront = dashboard.style.display === 'block';
|
|
viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
|
|
viewportHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
|
|
console.log(viewportWidth + 'px');
|
|
dashboard.style.left = (document.documentElement.clientWidth/2) - 1.5*buttonsize + 'px' ;
|
|
dashboard.style.top = (viewportHeight/2) - buttonsize + 'px';
|
|
dashboard.style.position = "fixed";
|
|
dashboard.style.zIndex = "3000";
|
|
dashboard.style.display = isFront ? 'none' : 'block';
|
|
}
|
|
});
|
|
|
|
function onError(error) {
|
|
console.log(`Error: ${error}`);
|
|
}
|
|
|
|
function deleteButtons(dashboard)
|
|
{
|
|
document.getElementById("dashboard-nextcloud-button").remove();
|
|
document.getElementById("dashboard-wekan-button").remove();
|
|
document.getElementById("dashboard-authentik-button").remove();
|
|
}
|
|
function createButtons(baseUrl, dashboard)
|
|
{
|
|
|
|
links= {dashboard: "https://", wekan: "https://board.", nextcloud: "https://cloud." }
|
|
|
|
var wekanButton = document.createElement("button");
|
|
//wekanButton.innerHTML = "Wekan";
|
|
wekanButton.style.position= "relative";
|
|
wekanButton.style.top= buttonsize + 'px';
|
|
wekanButton.setAttribute("class", "lit-button wekan-button");
|
|
wekanButton.setAttribute("id", "dashboard-wekan-button");
|
|
wekanButton.addEventListener ("click", function() {
|
|
window.open(links["wekan"] + baseUrl, "_self");
|
|
});
|
|
|
|
var authentikButton = document.createElement("button");
|
|
//authentikButton.innerHTML = "Dashboard";
|
|
authentikButton.setAttribute("class", "lit-button authentik-button");
|
|
authentikButton.setAttribute("id", "dashboard-authentik-button");
|
|
authentikButton.addEventListener ("click", function() {
|
|
window.open(links["dashboard"] + baseUrl, "_self");
|
|
});
|
|
|
|
var nextcloudButton = document.createElement("button");
|
|
//nextcloudButton.innerHTML = "Nextcloud";
|
|
nextcloudButton.setAttribute("class", "lit-button nextcloud-button");
|
|
nextcloudButton.setAttribute("id", "dashboard-nextcloud-button");
|
|
nextcloudButton.addEventListener ("click", function() {
|
|
window.open(links["nextcloud"] + baseUrl, "_self");
|
|
});
|
|
// 2. Append somewhere
|
|
dashboard.appendChild(nextcloudButton);
|
|
dashboard.appendChild(wekanButton);
|
|
dashboard.appendChild(authentikButton);
|
|
}
|
|
|
|
function setDashboard(baseUrl)
|
|
{
|
|
console.log(baseUrl);
|
|
if (document.getElementById('lit-dashboard'))
|
|
{
|
|
dashboard = document.getElementById('lit-dashboard');
|
|
dashboard.style.position = "fixed";
|
|
dashboard.style.zIndex='3000';
|
|
dashboard.style.height = '60px';
|
|
dashboard.style.display = 'none';
|
|
deleteButtons(dashboard);
|
|
createButtons(baseUrl, dashboard);
|
|
}
|
|
|
|
else
|
|
{
|
|
var dashboard = document.createElement("div");
|
|
dashboard.setAttribute("id", "lit-dashboard");
|
|
dashboard.style.position = "fixed";
|
|
dashboard.style.zIndex='3000';
|
|
dashboard.style.height = '60px';
|
|
dashboard.style.display = 'none';
|
|
createButtons(baseUrl, dashboard);
|
|
var currentDiv = document.body.firstChild;
|
|
document.body.insertBefore(dashboard, currentDiv);
|
|
}
|
|
// erstelle ein neues div Element
|
|
// und gib ihm etwas Inhalt
|
|
}
|
|
function onGot(item) {
|
|
let baseUrl = "demo.local-it.org";
|
|
if (item.baseUrl) {
|
|
baseUrl = item.baseUrl;
|
|
}
|
|
setDashboard(baseUrl);
|
|
}
|
|
|
|
let getting = browser.storage.sync.get("baseUrl");
|
|
getting.then(onGot, onError);
|