added a default 'Open SiteCompanion' button for unknown sites

This commit is contained in:
2026-01-18 19:41:00 -05:00
parent 47cf450bf5
commit 23d26d2913
3 changed files with 41 additions and 7 deletions

View File

@@ -342,6 +342,12 @@ chrome.runtime.onConnect.addListener((port) => {
});
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") {
const shortcutId = message.shortcutId || "";
if (shortcutId) {

View File

@@ -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");
if (toolbar) toolbar.remove();
@@ -437,7 +437,27 @@ function createToolbar(shortcuts, position = "bottom-right", themeMode = "light"
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");
label.textContent = "SiteCompanion";
label.style.fontSize = "12px";
@@ -506,23 +526,31 @@ async function refreshToolbar() {
shortcuts = [],
presets = [],
toolbarPosition = "bottom-right",
theme = "system"
theme = "system",
toolbarAutoHide = true
} = await chrome.storage.local.get([
"sites",
"workspaces",
"shortcuts",
"presets",
"toolbarPosition",
"theme"
"theme",
"toolbarAutoHide"
]);
const currentUrl = window.location.href;
const site = sites.find(s => matchUrl(currentUrl, s.urlPattern));
if (!site) {
if (toolbarAutoHide) {
const toolbar = document.getElementById("sitecompanion-toolbar");
if (toolbar) toolbar.remove();
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) {
shortcuts = presets;

View File

@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "SiteCompanion",
"version": "0.4.6",
"version": "0.4.7",
"description": "AI companion for site-bound text extraction and tasks.",
"permissions": ["storage", "activeTab"],
"host_permissions": ["<all_urls>"],