From 23d26d2913bc5ac9d791eed9a71c15d4133e0b7d Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Sun, 18 Jan 2026 19:41:00 -0500 Subject: [PATCH] added a default 'Open SiteCompanion' button for unknown sites --- sitecompanion/background.js | 6 ++++++ sitecompanion/content.js | 40 +++++++++++++++++++++++++++++++------ sitecompanion/manifest.json | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/sitecompanion/background.js b/sitecompanion/background.js index 81573dd..d985768 100644 --- a/sitecompanion/background.js +++ b/sitecompanion/background.js @@ -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) { diff --git a/sitecompanion/content.js b/sitecompanion/content.js index c160eee..ef3371d 100644 --- a/sitecompanion/content.js +++ b/sitecompanion/content.js @@ -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,21 +526,29 @@ 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) { - const toolbar = document.getElementById("sitecompanion-toolbar"); - if (toolbar) toolbar.remove(); + 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; } diff --git a/sitecompanion/manifest.json b/sitecompanion/manifest.json index 8893f93..632cb92 100644 --- a/sitecompanion/manifest.json +++ b/sitecompanion/manifest.json @@ -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": [""],