diff --git a/background.js b/background.js index 03d6d39..3a44a50 100644 --- a/background.js +++ b/background.js @@ -1,5 +1,8 @@ "use strict"; +//Simple background script that seds a message to content script +// code mainly from: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/sendMessage + function onError(error) { console.error(`Error: ${error}`); } @@ -8,7 +11,7 @@ function sendMessageToTabs(tabs) { for (let tab of tabs) { browser.tabs.sendMessage( tab.id, - {overlay: "display"} + {trigger: "extension click"} ).then(response => { }).catch(onError); } diff --git a/dashboard-1.1-fx.xpi b/dashboard-1.1-fx.xpi new file mode 100644 index 0000000..8b69e97 Binary files /dev/null and b/dashboard-1.1-fx.xpi differ diff --git a/dashboard.js b/dashboard.js index 8672ab4..26487f2 100644 --- a/dashboard.js +++ b/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: ""}); + } }); \ No newline at end of file diff --git a/icons/favicon48.jpg b/icons/favicon48.jpg new file mode 100644 index 0000000..387cb0f Binary files /dev/null and b/icons/favicon48.jpg differ diff --git a/manifest.json b/manifest.json index 5e47614..62dec74 100644 --- a/manifest.json +++ b/manifest.json @@ -2,9 +2,9 @@ "manifest_version": 2, "name": "Dashboard", - "version": "1.0", + "version": "1.1", - "description": "Adds a Dashboard Header before Webpage header.", + "description": "Makes Dashboard available through shortcut to access wekan/nextcloud/authentik instances", "content_scripts": [ { @@ -13,26 +13,29 @@ "css": [ "css/dashboard.css" ] } ], + "icons":{ + "48": "icons/favicon48.jpg" + }, "web_accessible_resources": [ "css/style.css", "icons/Nextcloud_Logo.png", "icons/wekan_logo.png", "icons/goauthentik_logo.png", - "icons/favicon.jpg" + "icons/favicon48.jpg" ], "options_ui": { "page": "options.html" }, - - "permissions": ["storage","tabs"], - "browser_specific_settings": { "gecko": { - "id": "addon@example.com" + "id": "dashboard@viehlieb.org", + "strict_min_version": "58.0" } }, + "permissions": ["storage","tabs"], + "browser_action": { - "default_icon": "icons/favicon.jpg", + "default_icon": "icons/favicon48.jpg", "default_title": "Holsteincloud 3.0" }, "background": {