added a default 'Open SiteCompanion' button for unknown sites
This commit is contained in:
@@ -342,6 +342,12 @@ chrome.runtime.onConnect.addListener((port) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener((message) => {
|
chrome.runtime.onMessage.addListener((message) => {
|
||||||
|
if (message?.type === "OPEN_POPUP") {
|
||||||
|
if (chrome.action?.openPopup) {
|
||||||
|
void chrome.action.openPopup().catch(() => {});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (message?.type === "RUN_SHORTCUT") {
|
if (message?.type === "RUN_SHORTCUT") {
|
||||||
const shortcutId = message.shortcutId || "";
|
const shortcutId = message.shortcutId || "";
|
||||||
if (shortcutId) {
|
if (shortcutId) {
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ function getToolbarThemeTokens(mode) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createToolbar(shortcuts, position = "bottom-right", themeMode = "light") {
|
function createToolbar(shortcuts, position = "bottom-right", themeMode = "light", options = {}) {
|
||||||
let toolbar = document.getElementById("sitecompanion-toolbar");
|
let toolbar = document.getElementById("sitecompanion-toolbar");
|
||||||
if (toolbar) toolbar.remove();
|
if (toolbar) toolbar.remove();
|
||||||
|
|
||||||
@@ -437,7 +437,27 @@ function createToolbar(shortcuts, position = "bottom-right", themeMode = "light"
|
|||||||
color: ${tokens.ink};
|
color: ${tokens.ink};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (!shortcuts || !shortcuts.length) {
|
if (options?.unknown) {
|
||||||
|
const btn = document.createElement("button");
|
||||||
|
btn.type = "button";
|
||||||
|
btn.textContent = "Open SiteCompanion";
|
||||||
|
btn.style.cssText = `
|
||||||
|
padding: 6px 12px;
|
||||||
|
background: ${tokens.accent};
|
||||||
|
color: #fff9f3;
|
||||||
|
border: 1px solid ${tokens.accent};
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
box-shadow: 0 8px 20px ${tokens.glow};
|
||||||
|
`;
|
||||||
|
btn.addEventListener("click", () => {
|
||||||
|
chrome.runtime.sendMessage({ type: "OPEN_POPUP" }, () => {
|
||||||
|
void chrome.runtime.lastError;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
toolbar.appendChild(btn);
|
||||||
|
} else if (!shortcuts || !shortcuts.length) {
|
||||||
const label = document.createElement("span");
|
const label = document.createElement("span");
|
||||||
label.textContent = "SiteCompanion";
|
label.textContent = "SiteCompanion";
|
||||||
label.style.fontSize = "12px";
|
label.style.fontSize = "12px";
|
||||||
@@ -506,23 +526,31 @@ async function refreshToolbar() {
|
|||||||
shortcuts = [],
|
shortcuts = [],
|
||||||
presets = [],
|
presets = [],
|
||||||
toolbarPosition = "bottom-right",
|
toolbarPosition = "bottom-right",
|
||||||
theme = "system"
|
theme = "system",
|
||||||
|
toolbarAutoHide = true
|
||||||
} = await chrome.storage.local.get([
|
} = await chrome.storage.local.get([
|
||||||
"sites",
|
"sites",
|
||||||
"workspaces",
|
"workspaces",
|
||||||
"shortcuts",
|
"shortcuts",
|
||||||
"presets",
|
"presets",
|
||||||
"toolbarPosition",
|
"toolbarPosition",
|
||||||
"theme"
|
"theme",
|
||||||
|
"toolbarAutoHide"
|
||||||
]);
|
]);
|
||||||
const currentUrl = window.location.href;
|
const currentUrl = window.location.href;
|
||||||
const site = sites.find(s => matchUrl(currentUrl, s.urlPattern));
|
const site = sites.find(s => matchUrl(currentUrl, s.urlPattern));
|
||||||
|
|
||||||
if (!site) {
|
if (!site) {
|
||||||
|
if (toolbarAutoHide) {
|
||||||
const toolbar = document.getElementById("sitecompanion-toolbar");
|
const toolbar = document.getElementById("sitecompanion-toolbar");
|
||||||
if (toolbar) toolbar.remove();
|
if (toolbar) toolbar.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const resolvedTheme = resolveThemeValue(theme, null, null);
|
||||||
|
const themeMode = resolveThemeMode(resolvedTheme);
|
||||||
|
createToolbar([], toolbarPosition, themeMode, { unknown: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!shortcuts.length && Array.isArray(presets) && presets.length) {
|
if (!shortcuts.length && Array.isArray(presets) && presets.length) {
|
||||||
shortcuts = presets;
|
shortcuts = presets;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "SiteCompanion",
|
"name": "SiteCompanion",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"description": "AI companion for site-bound text extraction and tasks.",
|
"description": "AI companion for site-bound text extraction and tasks.",
|
||||||
"permissions": ["storage", "activeTab"],
|
"permissions": ["storage", "activeTab"],
|
||||||
"host_permissions": ["<all_urls>"],
|
"host_permissions": ["<all_urls>"],
|
||||||
|
|||||||
Reference in New Issue
Block a user