make dashboard accesible from everywhere to Plugin Click, ctrl + enter just in domainspace

This commit is contained in:
viehlieb 2022-03-11 14:06:32 +01:00
parent 0c8ce940a8
commit 07f663abb0
5 changed files with 54 additions and 20 deletions

View file

@ -7,3 +7,8 @@ As a user I want to easily switch between different applications.
Download zip file from git repository or run `zip -r -FS ../my-extension.zip * --exclude '*.git*'` Download zip file from git repository or run `zip -r -FS ../my-extension.zip * --exclude '*.git*'`
in firefox got to `about:addons` click `debug addon`, `load temporary addon` in firefox got to `about:addons` click `debug addon`, `load temporary addon`
USAGE:
Got to Addon Preferences and adjust baseUrl
Press ctrl + Enter on a webpage belonging to your domain to display the application Buttons for Wekan/Nextcloud/authentik
Press the icon on the top right extension bar to open dashboard on any webpage

View file

@ -1,3 +1,22 @@
browser.browserAction.onClicked.addListener((tab) => { "use strict";
console.log(tab.url);
}); function onError(error) {
console.error(`Error: ${error}`);
}
function sendMessageToTabs(tabs) {
for (let tab of tabs) {
browser.tabs.sendMessage(
tab.id,
{overlay: "display"}
).then(response => {
}).catch(onError);
}
}
browser.browserAction.onClicked.addListener(() => {
browser.tabs.query({
currentWindow: true,
active: true
}).then(sendMessageToTabs).catch(onError);
});

View file

@ -1,9 +1,18 @@
var buttonsize = 250; var buttonsize = 250;
var baseUrl="";
document.addEventListener("keyup", (event) => { document.addEventListener("keyup", (event) => {
if (event.ctrlKey && event.code == "Enter") { if (event.ctrlKey && event.code == "Enter") {
console.log("pressed"); if(document.location.host.includes(baseUrl))
var dashboard = document.querySelector('#lit-dashboard'); {
doStuff();
}
}
});
function doStuff()
{
var dashboard = document.querySelector('#lit-dashboard');
isFront = dashboard.style.display === 'block'; isFront = dashboard.style.display === 'block';
viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
viewportHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0); viewportHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
@ -13,8 +22,7 @@ document.addEventListener("keyup", (event) => {
dashboard.style.position = "fixed"; dashboard.style.position = "fixed";
dashboard.style.zIndex = "3000"; dashboard.style.zIndex = "3000";
dashboard.style.display = isFront ? 'none' : 'block'; dashboard.style.display = isFront ? 'none' : 'block';
} }
});
function onError(error) { function onError(error) {
console.log(`Error: ${error}`); console.log(`Error: ${error}`);
@ -64,7 +72,6 @@ function createButtons(baseUrl, dashboard)
function setDashboard(baseUrl) function setDashboard(baseUrl)
{ {
console.log(baseUrl);
if (document.getElementById('lit-dashboard')) if (document.getElementById('lit-dashboard'))
{ {
dashboard = document.getElementById('lit-dashboard'); dashboard = document.getElementById('lit-dashboard');
@ -92,7 +99,7 @@ function setDashboard(baseUrl)
// und gib ihm etwas Inhalt // und gib ihm etwas Inhalt
} }
function onGot(item) { function onGot(item) {
let baseUrl = "demo.local-it.org"; baseUrl = "demo.local-it.org";
if (item.baseUrl) { if (item.baseUrl) {
baseUrl = item.baseUrl; baseUrl = item.baseUrl;
} }
@ -101,3 +108,8 @@ function onGot(item) {
let getting = browser.storage.sync.get("baseUrl"); let getting = browser.storage.sync.get("baseUrl");
getting.then(onGot, onError); getting.then(onGot, onError);
browser.runtime.onMessage.addListener(request => {
doStuff();
return Promise.resolve({response: ""});
});

BIN
icons/favicon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View file

@ -8,7 +8,7 @@
"content_scripts": [ "content_scripts": [
{ {
"matches": ["*://*.local-it.org/*"], "matches": ["<all_urls>"],
"js": ["dashboard.js"], "js": ["dashboard.js"],
"css": [ "css/dashboard.css" ] "css": [ "css/dashboard.css" ]
} }
@ -17,28 +17,26 @@
"css/style.css", "css/style.css",
"icons/Nextcloud_Logo.png", "icons/Nextcloud_Logo.png",
"icons/wekan_logo.png", "icons/wekan_logo.png",
"icons/goauthentik_logo.png" "icons/goauthentik_logo.png",
"icons/favicon.jpg"
], ],
"options_ui": { "options_ui": {
"page": "options.html" "page": "options.html"
}, },
"permissions": ["storage"], "permissions": ["storage","tabs"],
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "addon@example.com" "id": "addon@example.com"
} }
}, },
"browser_action": {
"default_icon": "icons/favicon.jpg",
"default_title": "Holsteincloud 3.0"
},
"background": { "background": {
"scripts": ["background.js"] "scripts": ["background.js"]
}, }
"browser_action": {
"default_icon": {
"19": "button/geo-19.png",
"38": "button/geo-38.png"
},
"default_title": "Holsteincloud 3.0"
}
} }