add dashboard.xpi for directplugin installation
This commit is contained in:
parent
07f663abb0
commit
3ea78260b6
5 changed files with 46 additions and 28 deletions
50
dashboard.js
50
dashboard.js
|
|
@ -1,26 +1,29 @@
|
|||
var buttonsize = 250;
|
||||
var baseUrl="";
|
||||
|
||||
var buttonOffset = 250; //determines where the first of three buttons is rendered
|
||||
var baseUrl="default"; //shortcuts should only work when baseUrl is included in current url
|
||||
|
||||
document.addEventListener("keyup", (event) => {
|
||||
if (event.ctrlKey && event.code == "Enter") {
|
||||
if(document.location.host.includes(baseUrl))
|
||||
{
|
||||
doStuff();
|
||||
toggleDisplayBoard();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function doStuff()
|
||||
// displays the board as overlay
|
||||
function toggleDisplayBoard()
|
||||
{
|
||||
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.left = (document.documentElement.clientWidth/2) - 1.5*buttonOffset + 'px' ;
|
||||
dashboard.style.top = (viewportHeight/2) - buttonOffset + 'px';
|
||||
dashboard.style.position = "fixed";
|
||||
dashboard.style.zIndex = "3000";
|
||||
|
||||
dashboard.style.display = isFront ? 'none' : 'block';
|
||||
}
|
||||
|
||||
|
|
@ -28,49 +31,57 @@ function onError(error) {
|
|||
console.log(`Error: ${error}`);
|
||||
}
|
||||
|
||||
// gets rid of all the Buttons
|
||||
function deleteButtons(dashboard)
|
||||
{
|
||||
document.getElementById("dashboard-nextcloud-button").remove();
|
||||
document.getElementById("dashboard-wekan-button").remove();
|
||||
document.getElementById("dashboard-authentik-button").remove();
|
||||
}
|
||||
// adds the Buttons and the link prefixes
|
||||
// button.click() leads to prefix + baseUrl
|
||||
function createButtons(baseUrl, dashboard)
|
||||
{
|
||||
|
||||
links= {dashboard: "https://", wekan: "https://board.", nextcloud: "https://cloud." }
|
||||
|
||||
// Button to Wekan at links["wekan"]+baseUrl
|
||||
var wekanButton = document.createElement("button");
|
||||
//wekanButton.innerHTML = "Wekan";
|
||||
wekanButton.style.position= "relative";
|
||||
wekanButton.style.top= buttonsize + 'px';
|
||||
wekanButton.style.top= buttonOffset + 'px';
|
||||
wekanButton.setAttribute("class", "lit-button wekan-button");
|
||||
wekanButton.setAttribute("id", "dashboard-wekan-button");
|
||||
wekanButton.addEventListener ("click", function() {
|
||||
window.open(links["wekan"] + baseUrl, "_self");
|
||||
});
|
||||
|
||||
// Button to authentik at links["dashboard"]+baseUrl
|
||||
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");
|
||||
});
|
||||
|
||||
// Button to nextcloud at links["nextcloud"]+baseUrl
|
||||
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
|
||||
|
||||
// Append buttons to "lit-dashboard"
|
||||
dashboard.appendChild(nextcloudButton);
|
||||
dashboard.appendChild(wekanButton);
|
||||
dashboard.appendChild(authentikButton);
|
||||
}
|
||||
|
||||
function setDashboard(baseUrl)
|
||||
// creates or finds Dashboard
|
||||
// basic functionality:
|
||||
// initializes or finds dashboard div
|
||||
// prepends new div before document.body.firstChild
|
||||
function createOrFindDashboard(baseUrl)
|
||||
{
|
||||
if (document.getElementById('lit-dashboard'))
|
||||
{
|
||||
|
|
@ -95,21 +106,22 @@ function setDashboard(baseUrl)
|
|||
var currentDiv = document.body.firstChild;
|
||||
document.body.insertBefore(dashboard, currentDiv);
|
||||
}
|
||||
// erstelle ein neues div Element
|
||||
// und gib ihm etwas Inhalt
|
||||
}
|
||||
function onGot(item) {
|
||||
baseUrl = "demo.local-it.org";
|
||||
if (item.baseUrl) {
|
||||
baseUrl = item.baseUrl;
|
||||
}
|
||||
setDashboard(baseUrl);
|
||||
createOrFindDashboard(baseUrl);
|
||||
}
|
||||
|
||||
let getting = browser.storage.sync.get("baseUrl");
|
||||
getting.then(onGot, onError);
|
||||
|
||||
// listen to message from background.js
|
||||
browser.runtime.onMessage.addListener(request => {
|
||||
doStuff();
|
||||
return Promise.resolve({response: ""});
|
||||
if (request.trigger === "extension click")
|
||||
{
|
||||
toggleDisplayBoard();
|
||||
return Promise.resolve({response: ""});
|
||||
}
|
||||
});
|
||||
Reference in a new issue