docs: complete Context Bridge launch coordination by Epimetheus

Agent Coordination:
- Epimetheus (Architect) identity assigned and registered
- Connected to PS-SHA-∞ memory system (4,059 entries)
- Task claimed from marketplace
- Broadcasting to other agents

Launch Documentation Created:
- PUBLISH_TO_NPM.md - Complete npm publishing guide
- STRIPE_LIVE_SETUP.md - Stripe live mode setup guide
- AGENT_COORDINATION_REPORT.md - Full status and next steps
- EPIMETHEUS_SESSION_COMPLETE.md - Session summary
- Added all previous documentation to repo

Launch Status: 98% Complete
Blocked on: User actions (npm login + Stripe products)
Ready: Screenshots, testing, submissions, announcements

Next Steps:
1. User: npm login && npm publish (10 min)
2. User: Create Stripe products (5 min)
3. Capture 5 screenshots (15 min)
4. Manual testing on 4 platforms (20 min)
5. Submit to Chrome Web Store (30 min)
6. Launch announcements (10 min)

Total time to launch: ~90 minutes

Agent Body: qwen2.5-coder:7b (open source)
Memory Hash: 4e3d2012
Collaboration: ACTIVE

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Your Name
2026-02-14 12:35:50 -06:00
parent 72ca2f0e94
commit 2d84f62407
163 changed files with 31241 additions and 0 deletions

View File

@@ -0,0 +1,101 @@
/**
* Context Bridge - Request Queue
* Prevents rate limit exhaustion by queueing requests across tabs
*/
class RequestQueue {
constructor() {
this.queue = [];
this.processing = false;
this.requestCount = 0;
this.windowStart = Date.now();
this.RATE_LIMIT = 5000; // GitHub API: 5000 requests/hour
this.WINDOW_MS = 60 * 60 * 1000; // 1 hour
this.MIN_INTERVAL_MS = 100; // Minimum 100ms between requests
}
async enqueue(requestFn) {
return new Promise((resolve, reject) => {
this.queue.push({
fn: requestFn,
resolve,
reject,
timestamp: Date.now()
});
this.processQueue();
});
}
async processQueue() {
if (this.processing || this.queue.length === 0) {
return;
}
this.processing = true;
while (this.queue.length > 0) {
// Check if we're approaching rate limit
const now = Date.now();
const windowElapsed = now - this.windowStart;
if (windowElapsed > this.WINDOW_MS) {
// Reset window
this.windowStart = now;
this.requestCount = 0;
}
// If we're at 80% of rate limit, slow down
if (this.requestCount >= this.RATE_LIMIT * 0.8) {
console.warn('Context Bridge: Approaching rate limit, slowing down requests');
await this.sleep(1000); // Wait 1 second
}
// If we've hit the rate limit, wait for window reset
if (this.requestCount >= this.RATE_LIMIT) {
const waitTime = this.WINDOW_MS - windowElapsed;
console.warn(`Context Bridge: Rate limit reached, waiting ${Math.round(waitTime/1000)}s`);
await this.sleep(waitTime);
this.windowStart = Date.now();
this.requestCount = 0;
}
// Process next request
const request = this.queue.shift();
try {
const result = await request.fn();
this.requestCount++;
request.resolve(result);
} catch (error) {
request.reject(error);
}
// Minimum interval between requests
await this.sleep(this.MIN_INTERVAL_MS);
}
this.processing = false;
}
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
getStats() {
return {
queueLength: this.queue.length,
requestCount: this.requestCount,
windowStart: new Date(this.windowStart).toISOString(),
percentOfLimit: Math.round((this.requestCount / this.RATE_LIMIT) * 100)
};
}
}
// Export singleton
const requestQueue = new RequestQueue();
// Export for use in service worker
if (typeof module !== 'undefined' && module.exports) {
module.exports = requestQueue;
}

View File

@@ -0,0 +1,68 @@
/**
* Context Bridge - Background Service Worker
* Handles extension state and context URL storage
*/
// Listen for installation
chrome.runtime.onInstalled.addListener(() => {
console.log('Context Bridge installed');
// Set default state
chrome.storage.sync.get(['contextUrl'], (result) => {
if (!result.contextUrl) {
console.log('No context URL set yet');
} else {
console.log('Context URL loaded:', result.contextUrl);
}
});
});
// Listen for messages from content scripts
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'getContextUrl') {
chrome.storage.sync.get(['contextUrl', 'rawUrl'], (result) => {
sendResponse({
contextUrl: result.contextUrl,
rawUrl: result.rawUrl
});
});
return true; // Will respond asynchronously
}
if (request.action === 'setContextUrl') {
chrome.storage.sync.set({
contextUrl: request.contextUrl,
rawUrl: request.rawUrl
}, () => {
sendResponse({ success: true });
});
return true;
}
if (request.action === 'clearContext') {
chrome.storage.sync.remove(['contextUrl', 'rawUrl'], () => {
sendResponse({ success: true });
});
return true;
}
});
// Badge to show if context is set
chrome.storage.sync.get(['contextUrl'], (result) => {
if (result.contextUrl) {
chrome.action.setBadgeText({ text: '✓' });
chrome.action.setBadgeBackgroundColor({ color: '#10B981' });
}
});
// Listen for storage changes to update badge
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync' && changes.contextUrl) {
if (changes.contextUrl.newValue) {
chrome.action.setBadgeText({ text: '✓' });
chrome.action.setBadgeBackgroundColor({ color: '#10B981' });
} else {
chrome.action.setBadgeText({ text: '' });
}
}
});

View File

@@ -0,0 +1,70 @@
/**
* Context Bridge - Cache Manager
* Manages in-memory caching of fetched contexts
*/
class ContextCache {
constructor(ttlMs = 5 * 60 * 1000) { // 5 minutes default
this.cache = new Map();
this.ttl = ttlMs;
}
set(url, content) {
this.cache.set(url, {
content,
timestamp: Date.now()
});
}
get(url) {
const entry = this.cache.get(url);
if (!entry) return null;
const age = Date.now() - entry.timestamp;
if (age > this.ttl) {
// Expired, remove it
this.cache.delete(url);
return null;
}
return entry.content;
}
clear() {
this.cache.clear();
}
// Get cache stats
getStats() {
const now = Date.now();
const entries = Array.from(this.cache.entries());
return {
size: entries.length,
validEntries: entries.filter(([_, v]) => (now - v.timestamp) <= this.ttl).length,
expiredEntries: entries.filter(([_, v]) => (now - v.timestamp) > this.ttl).length,
totalBytes: entries.reduce((sum, [_, v]) => sum + v.content.length, 0)
};
}
// Cleanup expired entries
cleanup() {
const now = Date.now();
for (const [url, entry] of this.cache.entries()) {
if (now - entry.timestamp > this.ttl) {
this.cache.delete(url);
}
}
}
}
// Export singleton
const contextCache = new ContextCache();
// Cleanup every minute
setInterval(() => contextCache.cleanup(), 60000);
// Export for use in content scripts
if (typeof module !== 'undefined' && module.exports) {
module.exports = contextCache;
}

View File

@@ -0,0 +1,207 @@
/**
* Context Bridge - ChatGPT Content Script
* Injects "Insert Context" button into ChatGPT interface
*/
console.log('Context Bridge: Loaded on ChatGPT');
let contextUrl = null;
let isInjected = false;
// Get context URL from storage
chrome.runtime.sendMessage({ action: 'getContextUrl' }, (response) => {
if (response && response.rawUrl) {
contextUrl = response.rawUrl;
injectButton();
}
});
// Listen for storage changes
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync' && changes.rawUrl) {
contextUrl = changes.rawUrl.newValue;
updateButton();
}
});
function injectButton() {
// Find the textarea (ChatGPT uses a textarea)
const textarea = document.querySelector('textarea[placeholder*="Message"]') ||
document.querySelector('textarea');
if (!textarea) {
setTimeout(injectButton, 500);
return;
}
// Check if button already exists
if (document.querySelector('.context-bridge-button')) {
return;
}
// Find the container with the send button
const formContainer = textarea.closest('form') || textarea.parentElement;
if (!formContainer) {
return;
}
// Create button
const button = document.createElement('button');
button.type = 'button';
button.className = 'context-bridge-button';
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
// Style to position near send button
button.style.position = 'absolute';
button.style.right = '60px';
button.style.bottom = '12px';
// Add click handler with improvements
let isInserting = false;
let lastInsertTime = 0;
const COOLDOWN_MS = 1000;
button.addEventListener('click', async (e) => {
e.preventDefault();
e.stopPropagation();
// Rate limiting
const now = Date.now();
if (now - lastInsertTime < COOLDOWN_MS || isInserting) {
return;
}
if (!contextUrl) {
alert('No context URL set. Click the Context Bridge extension icon to configure.');
return;
}
// Loading state
isInserting = true;
button.disabled = true;
button.classList.add('loading');
button.innerHTML = `
<svg class="context-bridge-icon spinning" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
</svg>
<span>Inserting...</span>
`;
try {
// Verify context is accessible
const response = await fetch(contextUrl);
if (!response.ok) {
throw new Error(`Failed to fetch context (HTTP ${response.status})`);
}
// Insert context message
const message = `Read ${contextUrl} first, then help me with: `;
// Set textarea value
textarea.value = message;
textarea.focus();
// Trigger input event so ChatGPT recognizes the change
const inputEvent = new Event('input', { bubbles: true });
textarea.dispatchEvent(inputEvent);
// Position cursor at end
textarea.setSelectionRange(message.length, message.length);
// Success state
lastInsertTime = now;
button.classList.remove('loading');
button.classList.add('injected');
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"/>
</svg>
<span>Context Inserted ✓</span>
`;
// Reset after 2 seconds
setTimeout(() => {
button.classList.remove('injected');
button.disabled = false;
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
isInserting = false;
}, 2000);
} catch (error) {
// Error state
console.error('Context Bridge error:', error);
button.classList.remove('loading');
button.classList.add('error');
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="15" y1="9" x2="9" y2="15"/>
<line x1="9" y1="9" x2="15" y2="15"/>
</svg>
<span>Failed</span>
`;
alert(`Failed to insert context:\n\n${error.message}\n\nPlease check:\n1. Context URL is accessible\n2. You're connected to the internet\n3. Try refreshing the page`);
setTimeout(() => {
button.classList.remove('error');
button.disabled = false;
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
isInserting = false;
}, 3000);
}
});
// Add button to the form
formContainer.style.position = 'relative';
formContainer.appendChild(button);
console.log('Context Bridge: Button injected on ChatGPT');
}
function updateButton() {
const button = document.querySelector('.context-bridge-button');
if (!button) {
if (contextUrl) {
injectButton();
}
}
}
// Watch for DOM changes (ChatGPT is a SPA)
const observer = new MutationObserver((mutations) => {
if (!document.querySelector('.context-bridge-button') && contextUrl) {
injectButton();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Initial injection
if (contextUrl) {
injectButton();
}

View File

@@ -0,0 +1,265 @@
/**
* Context Bridge - Improved Claude Content Script with Caching & Cleanup
*/
console.log('Context Bridge: Loaded on Claude.ai');
let contextUrl = null;
let isInjected = false;
let lastInsertTime = 0;
let isInserting = false;
const COOLDOWN_MS = 1000;
// Simple in-memory cache with 5-minute TTL
const cache = {
data: null,
url: null,
timestamp: null,
TTL: 5 * 60 * 1000, // 5 minutes
get(url) {
if (this.url !== url) return null;
if (!this.timestamp) return null;
if (Date.now() - this.timestamp > this.TTL) {
this.clear();
return null;
}
return this.data;
},
set(url, data) {
this.url = url;
this.data = data;
this.timestamp = Date.now();
},
clear() {
this.data = null;
this.url = null;
this.timestamp = null;
}
};
// Get context URL from storage
chrome.runtime.sendMessage({ action: 'getContextUrl' }, (response) => {
if (response && response.rawUrl) {
contextUrl = response.rawUrl;
injectButton();
}
});
// Listen for storage changes
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync' && changes.rawUrl) {
contextUrl = changes.rawUrl.newValue;
cache.clear(); // Clear cache when URL changes
updateButton();
}
});
function injectButton() {
// Find the input area (Claude uses a contenteditable div)
const inputArea = document.querySelector('[contenteditable="true"]');
if (!inputArea) {
// Retry in 500ms if input not found yet
setTimeout(injectButton, 500);
return;
}
// Check if button already exists
if (document.querySelector('.context-bridge-button')) {
return;
}
// Find the parent container
const inputContainer = inputArea.closest('div[class*="relative"]') || inputArea.parentElement;
if (!inputContainer) {
return;
}
// Create button
const button = document.createElement('button');
button.className = 'context-bridge-button';
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
// Add click handler with caching
button.addEventListener('click', async (e) => {
e.preventDefault();
e.stopPropagation();
// Rate limiting
const now = Date.now();
if (now - lastInsertTime < COOLDOWN_MS || isInserting) {
return;
}
if (!contextUrl) {
alert('No context URL set. Click the Context Bridge extension icon to configure.');
return;
}
// Loading state
isInserting = true;
button.disabled = true;
button.classList.add('loading');
button.innerHTML = `
<svg class="context-bridge-icon spinning" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
</svg>
<span>Inserting...</span>
`;
try {
// Check cache first
let contextContent = cache.get(contextUrl);
if (!contextContent) {
// Cache miss - fetch from network
const response = await fetch(contextUrl);
if (!response.ok) {
throw new Error(`Failed to fetch context (HTTP ${response.status})`);
}
contextContent = await response.text();
// Store in cache
cache.set(contextUrl, contextContent);
}
// Insert context message
const message = `Read ${contextUrl} first, then help me with: `;
// Insert into Claude's input
inputArea.focus();
// Try modern approach first
if (inputArea.isContentEditable) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(inputArea);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
const textNode = document.createTextNode(message);
range.insertNode(textNode);
range.setStartAfter(textNode);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
} else {
// Fallback for textarea
inputArea.value = message + (inputArea.value || '');
inputArea.setSelectionRange(message.length, message.length);
}
// Success state
lastInsertTime = now;
button.classList.remove('loading');
button.classList.add('injected');
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"/>
</svg>
<span>Context Inserted ✓</span>
`;
// Reset after 2 seconds
setTimeout(() => {
button.classList.remove('injected');
button.disabled = false;
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
isInserting = false;
}, 2000);
} catch (error) {
// Error state
console.error('Context Bridge error:', error);
button.classList.remove('loading');
button.classList.add('error');
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="15" y1="9" x2="9" y2="15"/>
<line x1="9" y1="9" x2="15" y2="15"/>
</svg>
<span>Failed to load</span>
`;
alert(`Failed to insert context:\n\n${error.message}\n\nPlease check:\n1. Context URL is accessible\n2. You're connected to the internet\n3. Try refreshing the page`);
// Reset button
setTimeout(() => {
button.classList.remove('error');
button.disabled = false;
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
isInserting = false;
}, 3000);
}
});
// Add button to the DOM
const sendButton = inputContainer.querySelector('button[aria-label*="Send"]') ||
inputContainer.querySelector('button[type="submit"]');
if (sendButton && sendButton.parentElement) {
sendButton.parentElement.insertBefore(button, sendButton);
} else {
inputContainer.appendChild(button);
}
console.log('Context Bridge: Button injected on Claude.ai');
}
function updateButton() {
const button = document.querySelector('.context-bridge-button');
if (!button) {
if (contextUrl) {
injectButton();
}
}
}
// Watch for DOM changes (Claude is a SPA)
const observer = new MutationObserver((mutations) => {
if (!document.querySelector('.context-bridge-button') && contextUrl) {
injectButton();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Cleanup on page unload
window.addEventListener('beforeunload', () => {
observer.disconnect();
cache.clear();
});
// Initial injection
if (contextUrl) {
injectButton();
}

View File

@@ -0,0 +1,229 @@
/**
* Context Bridge - Claude.ai Content Script
* Injects "Insert Context" button into Claude chat interface
*/
console.log('Context Bridge: Loaded on Claude.ai');
let contextUrl = null;
let isInjected = false;
// Get context URL from storage
chrome.runtime.sendMessage({ action: 'getContextUrl' }, (response) => {
if (response && response.rawUrl) {
contextUrl = response.rawUrl;
injectButton();
}
});
// Listen for storage changes
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync' && changes.rawUrl) {
contextUrl = changes.rawUrl.newValue;
updateButton();
}
});
function injectButton() {
// Find the input area (Claude uses a contenteditable div)
const inputArea = document.querySelector('[contenteditable="true"]');
if (!inputArea) {
// Retry in 500ms if input not found yet
setTimeout(injectButton, 500);
return;
}
// Check if button already exists
if (document.querySelector('.context-bridge-button')) {
return;
}
// Find the parent container
const inputContainer = inputArea.closest('div[class*="relative"]') || inputArea.parentElement;
if (!inputContainer) {
return;
}
// Create button
const button = document.createElement('button');
button.className = 'context-bridge-button';
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
// Add click handler
let isInserting = false;
let lastInsertTime = 0;
const COOLDOWN_MS = 1000; // 1 second cooldown
button.addEventListener('click', async (e) => {
e.preventDefault();
e.stopPropagation();
// Rate limiting
const now = Date.now();
if (now - lastInsertTime < COOLDOWN_MS) {
return; // Too soon, ignore click
}
// Prevent double-click
if (isInserting) {
return;
}
if (!contextUrl) {
alert('No context URL set. Click the Context Bridge extension icon to configure.');
return;
}
// Show loading state
isInserting = true;
button.disabled = true;
button.classList.add('loading');
button.innerHTML = `
<svg class="context-bridge-icon spinning" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
</svg>
<span>Inserting...</span>
`;
try {
// Fetch context to verify it's accessible
const response = await fetch(contextUrl);
if (!response.ok) {
throw new Error(`Failed to fetch context (HTTP ${response.status})`);
}
// Insert context message
const message = `Read ${contextUrl} first, then help me with: `;
// Insert into Claude's input
inputArea.focus();
// Try modern approach first
if (inputArea.isContentEditable) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(inputArea);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
// Try to insert text
const textNode = document.createTextNode(message);
range.insertNode(textNode);
range.setStartAfter(textNode);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
} else {
// Fallback for textarea
inputArea.value = message + inputArea.value;
inputArea.setSelectionRange(message.length, message.length);
}
// Success state
lastInsertTime = now;
button.classList.remove('loading');
button.classList.add('injected');
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"/>
</svg>
<span>Context Inserted ✓</span>
`;
// Reset after 2 seconds
setTimeout(() => {
button.classList.remove('injected');
button.disabled = false;
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
isInserting = false;
}, 2000);
} catch (error) {
// Error state
console.error('Context Bridge error:', error);
button.classList.remove('loading');
button.classList.add('error');
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="15" y1="9" x2="9" y2="15"/>
<line x1="9" y1="9" x2="15" y2="15"/>
</svg>
<span>Failed to load</span>
`;
alert(`Failed to insert context:\n\n${error.message}\n\nPlease check:\n1. Context URL is accessible\n2. You're connected to the internet\n3. Try refreshing the page`);
// Reset button
setTimeout(() => {
button.classList.remove('error');
button.disabled = false;
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
<div class="context-bridge-tooltip">Click to insert your context</div>
`;
isInserting = false;
}, 3000);
}
});
// Add button to the DOM
// Try to place it near the send button
const sendButton = inputContainer.querySelector('button[aria-label*="Send"]') ||
inputContainer.querySelector('button[type="submit"]');
if (sendButton && sendButton.parentElement) {
sendButton.parentElement.insertBefore(button, sendButton);
} else {
// Fallback: add to input container
inputContainer.appendChild(button);
}
console.log('Context Bridge: Button injected on Claude.ai');
}
function updateButton() {
const button = document.querySelector('.context-bridge-button');
if (!button) {
if (contextUrl) {
injectButton();
}
}
}
// Watch for DOM changes (Claude is a SPA)
const observer = new MutationObserver((mutations) => {
if (!document.querySelector('.context-bridge-button') && contextUrl) {
injectButton();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Initial injection
if (contextUrl) {
injectButton();
}

View File

@@ -0,0 +1,76 @@
// This is a template showing the improved pattern
// Apply to: chatgpt.js, copilot.js, gemini.js
// Key improvements to apply:
// 1. Rate limiting with cooldown
// 2. Loading/success/error states
// 3. Fetch context before inserting
// 4. Better error messages
// 5. Disabled state during operation
const COOLDOWN_MS = 1000;
let isInserting = false;
let lastInsertTime = 0;
button.addEventListener('click', async (e) => {
e.preventDefault();
e.stopPropagation();
// Rate limiting
const now = Date.now();
if (now - lastInsertTime < COOLDOWN_MS || isInserting) {
return;
}
if (!contextUrl) {
alert('No context URL set. Click the Context Bridge extension icon to configure.');
return;
}
// Loading state
isInserting = true;
button.disabled = true;
button.classList.add('loading');
button.innerHTML = `<svg class="context-bridge-icon spinning" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12a9 9 1 1-6.219-8.56"/></svg><span>Inserting...</span>`;
try {
// Verify context is accessible
const response = await fetch(contextUrl);
if (!response.ok) {
throw new Error(`Failed to fetch context (HTTP ${response.status})`);
}
// Insert message
const message = `Read ${contextUrl} first, then help me with: `;
inputArea.focus();
inputArea.value = message + (inputArea.value || '');
inputArea.setSelectionRange(message.length, message.length);
// Success state
lastInsertTime = now;
button.classList.remove('loading');
button.classList.add('injected');
button.innerHTML = `<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg><span>Context Inserted ✓</span>`;
setTimeout(() => {
button.classList.remove('injected');
button.disabled = false;
button.innerHTML = originalButtonHTML;
isInserting = false;
}, 2000);
} catch (error) {
// Error state
console.error('Context Bridge error:', error);
button.classList.remove('loading');
button.classList.add('error');
button.innerHTML = `<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg><span>Failed</span>`;
alert(`Failed to insert context:\n\n${error.message}\n\nPlease check:\n1. Context URL is accessible\n2. You're connected to the internet\n3. Try refreshing the page`);
setTimeout(() => {
button.classList.remove('error');
button.disabled = false;
button.innerHTML = originalButtonHTML;
isInserting = false;
}, 3000);
}
});

View File

@@ -0,0 +1,71 @@
/**
* Context Bridge - Microsoft Copilot Content Script
*/
console.log('Context Bridge: Loaded on Microsoft Copilot');
let contextUrl = null;
chrome.runtime.sendMessage({ action: 'getContextUrl' }, (response) => {
if (response && response.rawUrl) {
contextUrl = response.rawUrl;
injectButton();
}
});
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync' && changes.rawUrl) {
contextUrl = changes.rawUrl.newValue;
}
});
function injectButton() {
const textarea = document.querySelector('textarea') ||
document.querySelector('[contenteditable="true"]');
if (!textarea) {
setTimeout(injectButton, 500);
return;
}
if (document.querySelector('.context-bridge-button')) {
return;
}
const button = document.createElement('button');
button.type = 'button';
button.className = 'context-bridge-button';
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
`;
button.addEventListener('click', (e) => {
e.preventDefault();
if (!contextUrl) {
alert('No context URL set. Click the Context Bridge extension icon to configure.');
return;
}
const message = `Read ${contextUrl} first, then help me with: `;
textarea.value = message;
textarea.focus();
});
textarea.parentElement.appendChild(button);
console.log('Context Bridge: Button injected on Copilot');
}
const observer = new MutationObserver(() => {
if (!document.querySelector('.context-bridge-button') && contextUrl) {
injectButton();
}
});
observer.observe(document.body, { childList: true, subtree: true });
if (contextUrl) {
injectButton();
}

View File

@@ -0,0 +1,71 @@
/**
* Context Bridge - Google Gemini Content Script
*/
console.log('Context Bridge: Loaded on Google Gemini');
let contextUrl = null;
chrome.runtime.sendMessage({ action: 'getContextUrl' }, (response) => {
if (response && response.rawUrl) {
contextUrl = response.rawUrl;
injectButton();
}
});
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync' && changes.rawUrl) {
contextUrl = changes.rawUrl.newValue;
}
});
function injectButton() {
const textarea = document.querySelector('textarea') ||
document.querySelector('[contenteditable="true"]');
if (!textarea) {
setTimeout(injectButton, 500);
return;
}
if (document.querySelector('.context-bridge-button')) {
return;
}
const button = document.createElement('button');
button.type = 'button';
button.className = 'context-bridge-button';
button.innerHTML = `
<svg class="context-bridge-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
<polyline points="13 2 13 9 20 9"/>
</svg>
<span>Insert Context</span>
`;
button.addEventListener('click', (e) => {
e.preventDefault();
if (!contextUrl) {
alert('No context URL set. Click the Context Bridge extension icon to configure.');
return;
}
const message = `Read ${contextUrl} first, then help me with: `;
textarea.value = message;
textarea.focus();
});
textarea.parentElement.appendChild(button);
console.log('Context Bridge: Button injected on Gemini');
}
const observer = new MutationObserver(() => {
if (!document.querySelector('.context-bridge-button') && contextUrl) {
injectButton();
}
});
observer.observe(document.body, { childList: true, subtree: true });
if (contextUrl) {
injectButton();
}

View File

@@ -0,0 +1,176 @@
/* Context Bridge - Injection Button Styles */
.context-bridge-button {
position: relative;
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 12px;
background: linear-gradient(135deg, #F5A623 0%, #FF1D6C 38.2%, #9C27B0 61.8%, #2979FF 100%);
color: white;
border: none;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
z-index: 9999;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.context-bridge-button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.context-bridge-button:active:not(:disabled) {
transform: translateY(0);
}
.context-bridge-button:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.context-bridge-button.injected {
background: #10B981;
}
.context-bridge-button.error {
background: #EF4444;
}
.context-bridge-button.loading {
background: #667eea;
}
.context-bridge-icon {
width: 16px;
height: 16px;
}
.context-bridge-icon.spinning {
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* Tooltip */
.context-bridge-tooltip {
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
margin-bottom: 8px;
padding: 8px 12px;
background: rgba(0, 0, 0, 0.9);
color: white;
border-radius: 6px;
font-size: 12px;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
z-index: 10000;
}
.context-bridge-button:hover:not(:disabled) .context-bridge-tooltip {
opacity: 1;
}
/* Preview popup */
.context-bridge-preview {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 600px;
max-height: 80vh;
background: white;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
z-index: 10001;
overflow: hidden;
display: none;
}
.context-bridge-preview.show {
display: flex;
flex-direction: column;
}
.context-bridge-preview-header {
padding: 16px 20px;
background: linear-gradient(135deg, #F5A623 0%, #FF1D6C 38.2%, #9C27B0 61.8%, #2979FF 100%);
color: white;
display: flex;
justify-content: space-between;
align-items: center;
}
.context-bridge-preview-title {
font-size: 16px;
font-weight: 600;
}
.context-bridge-preview-close {
background: rgba(255, 255, 255, 0.2);
border: none;
color: white;
width: 28px;
height: 28px;
border-radius: 50%;
cursor: pointer;
font-size: 18px;
line-height: 1;
transition: background 0.2s;
}
.context-bridge-preview-close:hover {
background: rgba(255, 255, 255, 0.3);
}
.context-bridge-preview-content {
padding: 20px;
overflow-y: auto;
flex: 1;
font-size: 14px;
line-height: 1.6;
color: #333;
}
.context-bridge-preview-content pre {
background: #f5f5f5;
padding: 12px;
border-radius: 6px;
overflow-x: auto;
font-size: 13px;
}
.context-bridge-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 10000;
display: none;
}
.context-bridge-overlay.show {
display: block;
}
/* Loading spinner */
.context-bridge-spinner {
display: inline-block;
width: 14px;
height: 14px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 0.6s linear infinite;
}

View File

@@ -0,0 +1,33 @@
# Context Bridge Icons
## Current Status
SVG icon created: icon.svg (gradient purple "CB" logo)
## To Generate PNG Icons:
### Option 1: ImageMagick (recommended)
```bash
brew install imagemagick
for size in 16 32 48 128; do
convert icon.svg -resize ${size}x${size} icon${size}.png
done
```
### Option 2: Online Converter
1. Upload icon.svg to https://cloudconvert.com/svg-to-png
2. Generate 16x16, 32x32, 48x48, 128x128 versions
3. Save as icon16.png, icon32.png, icon48.png, icon128.png
### Option 3: Figma/Design Tool
1. Open icon.svg in Figma
2. Export as PNG at different sizes
## What The Extension Needs:
- icon16.png (16x16) - toolbar icon
- icon32.png (32x32) - extension management
- icon48.png (48x48) - extension management
- icon128.png (128x128) - Chrome Web Store
## Current Workaround:
The manifest.json references these icons, but Chrome will use a default icon if they're missing.
Extension will still function, just without custom icons.

View File

@@ -0,0 +1,66 @@
# 🎨 Icon Generation Instructions
## Option 1: Use Online Tool (Easiest - 2 minutes)
1. Go to: https://svgtopng.com or https://cloudconvert.com/svg-to-png
2. Upload `icon.svg` from this directory
3. Generate PNG at 128x128
4. Download the PNG
5. Go to: https://www.iloveimg.com/resize-image/resize-png
6. Upload the 128x128 PNG and create:
- 16x16 → save as `icon16.png`
- 32x32 → save as `icon32.png`
- 48x48 → save as `icon48.png`
- 128x128 → save as `icon128.png`
7. Copy all 4 PNG files to:
- `extension/icons/`
- `extension-firefox/icons/`
## Option 2: Install ImageMagick (Better)
```bash
# Install ImageMagick
brew install imagemagick
# Run the generation script
cd /Users/alexa/context-bridge/extension/icons
./generate-icons.sh
# Copy to Firefox version
cp icon*.png ../../extension-firefox/icons/
```
## Option 3: Use Figma/Sketch/Any Design Tool
1. Open `icon.svg` in your design tool
2. Export as PNG at these sizes:
- 16x16
- 32x32
- 48x48
- 128x128
3. Name them: `icon16.png`, `icon32.png`, `icon48.png`, `icon128.png`
4. Copy to both extension directories
---
## What the Icon Looks Like
- **Purple gradient background** (matches modern extension aesthetic)
- **Golden bridge arc** connecting two pillars
- **"CB" text** at bottom (Context Bridge)
- **Connection dots** showing the bridge metaphor
Clean, modern, professional. Ready for Chrome Web Store!
---
## Quick Validation
After generating, run:
```bash
ls -lh extension/icons/icon*.png
ls -lh extension-firefox/icons/icon*.png
```
You should see 4 PNG files in each directory.

View File

@@ -0,0 +1,20 @@
# Icons
Place icon files here:
- icon16.png (16x16)
- icon32.png (32x32)
- icon48.png (48x48)
- icon128.png (128x128)
## Design
Use the Context Bridge gradient:
- Colors: #F5A623#FF1D6C#9C27B0#2979FF
- Style: Modern, minimal
- Symbol: Bridge or document icon
## Generate
You can use any design tool or online icon generator.
Quick option: Use Favicon.io or similar to create from text "CB" or bridge emoji 🌉

View File

@@ -0,0 +1,35 @@
#!/bin/bash
# Generate PNG icons from SVG using sips (macOS built-in)
# Requires: macOS (for sips command)
set -e
echo "🎨 Generating PNG icons from SVG..."
# First, convert SVG to a large PNG that we can resize
# sips doesn't handle SVG directly, so we'll use a different approach
# Check if we have ImageMagick
if command -v convert &> /dev/null; then
echo "Using ImageMagick..."
convert -background none icon.svg -resize 16x16 icon16.png
convert -background none icon.svg -resize 32x32 icon32.png
convert -background none icon.svg -resize 48x48 icon48.png
convert -background none icon.svg -resize 128x128 icon128.png
elif command -v rsvg-convert &> /dev/null; then
echo "Using rsvg-convert..."
rsvg-convert -w 16 -h 16 icon.svg -o icon16.png
rsvg-convert -w 32 -h 32 icon.svg -o icon32.png
rsvg-convert -w 48 -h 48 icon.svg -o icon48.png
rsvg-convert -w 128 -h 128 icon.svg -o icon128.png
else
echo "⚠️ No SVG converter found. Using fallback method..."
echo "Please install ImageMagick: brew install imagemagick"
echo "Or librsvg: brew install librsvg"
exit 1
fi
echo "✅ Generated all icon sizes!"
ls -lh icon*.png

View File

@@ -0,0 +1,41 @@
<svg width="128" height="128" viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">
<!-- Gradient background -->
<defs>
<linearGradient id="bgGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#667eea;stop-opacity:1" />
<stop offset="100%" style="stop-color:#764ba2;stop-opacity:1" />
</linearGradient>
<linearGradient id="bridgeGrad" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#fbbf24;stop-opacity:1" />
<stop offset="100%" style="stop-color:#f59e0b;stop-opacity:1" />
</linearGradient>
</defs>
<!-- Rounded square background -->
<rect width="128" height="128" rx="24" fill="url(#bgGrad)"/>
<!-- Bridge icon - simplified connecting arc -->
<g transform="translate(24, 48)">
<!-- Left pillar -->
<rect x="0" y="20" width="12" height="32" fill="white" rx="2"/>
<!-- Right pillar -->
<rect x="68" y="20" width="12" height="32" fill="white" rx="2"/>
<!-- Bridge arc -->
<path d="M 6 20 Q 40 -5, 74 20"
stroke="url(#bridgeGrad)"
stroke-width="8"
fill="none"
stroke-linecap="round"/>
<!-- Connection dots -->
<circle cx="6" cy="20" r="5" fill="#fbbf24"/>
<circle cx="74" cy="20" r="5" fill="#fbbf24"/>
<circle cx="40" cy="-5" r="6" fill="#fbbf24"/>
</g>
<!-- Subtle text -->
<text x="64" y="105" font-family="Arial, sans-serif" font-size="16" font-weight="bold"
text-anchor="middle" fill="white" opacity="0.9">CB</text>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,67 @@
{
"manifest_version": 3,
"name": "Context Bridge",
"version": "0.1.0",
"description": "Stop re-explaining yourself to AI assistants. One-click context injection for Claude, ChatGPT, and more.",
"permissions": [
"storage",
"activeTab"
],
"host_permissions": [
"https://claude.ai/*",
"https://chat.openai.com/*",
"https://chatgpt.com/*",
"https://copilot.microsoft.com/*",
"https://gemini.google.com/*"
],
"background": {
"service_worker": "background/service-worker.js"
},
"content_scripts": [
{
"matches": ["https://claude.ai/*"],
"js": ["content/claude.js"],
"css": ["content/styles.css"],
"run_at": "document_end"
},
{
"matches": ["https://chat.openai.com/*", "https://chatgpt.com/*"],
"js": ["content/chatgpt.js"],
"css": ["content/styles.css"],
"run_at": "document_end"
},
{
"matches": ["https://copilot.microsoft.com/*"],
"js": ["content/copilot.js"],
"css": ["content/styles.css"],
"run_at": "document_end"
},
{
"matches": ["https://gemini.google.com/*"],
"js": ["content/gemini.js"],
"css": ["content/styles.css"],
"run_at": "document_end"
}
],
"action": {
"default_popup": "popup/popup.html",
"default_icon": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
},
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"web_accessible_resources": [
{
"resources": ["icons/*"],
"matches": ["<all_urls>"]
}
]
}

View File

@@ -0,0 +1,215 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 400px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #0a0a0a;
color: #fff;
}
.popup-container {
padding: 20px;
}
.header {
text-align: center;
margin-bottom: 24px;
}
.header h1 {
font-size: 20px;
font-weight: 700;
margin-bottom: 4px;
}
.subtitle {
font-size: 13px;
color: #888;
}
.section {
margin-bottom: 20px;
}
.empty-state {
text-align: center;
padding: 20px;
background: rgba(255, 255, 255, 0.05);
border-radius: 8px;
}
.empty-state p {
margin-bottom: 12px;
color: #ccc;
}
.hint {
font-size: 12px;
color: #888;
margin-bottom: 8px;
}
.empty-state code {
display: block;
background: rgba(0, 0, 0, 0.3);
padding: 6px 12px;
border-radius: 4px;
font-size: 12px;
margin: 6px 0;
font-family: 'Monaco', 'Courier New', monospace;
}
.status-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 12px;
background: #10B981;
border-radius: 20px;
font-size: 13px;
font-weight: 600;
margin-bottom: 16px;
}
.badge-icon {
font-size: 14px;
}
.url-display {
margin-bottom: 16px;
}
.url-display label {
display: block;
font-size: 13px;
color: #888;
margin-bottom: 8px;
}
.url-box {
display: flex;
gap: 8px;
align-items: center;
}
.url-box input {
flex: 1;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
color: #fff;
padding: 8px 12px;
border-radius: 6px;
font-size: 12px;
font-family: 'Monaco', 'Courier New', monospace;
}
.icon-btn {
background: rgba(255, 255, 255, 0.1);
border: none;
color: #fff;
width: 32px;
height: 32px;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.2s;
}
.icon-btn:hover {
background: rgba(255, 255, 255, 0.15);
}
.actions {
display: flex;
gap: 8px;
margin-bottom: 16px;
}
.btn {
flex: 1;
padding: 10px 16px;
border: none;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.btn-primary {
background: linear-gradient(135deg, #F5A623 0%, #FF1D6C 38.2%, #9C27B0 61.8%, #2979FF 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(255, 29, 108, 0.3);
}
.btn-secondary {
background: rgba(255, 255, 255, 0.1);
color: white;
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.15);
}
label {
display: block;
font-size: 13px;
color: #ccc;
margin-bottom: 8px;
}
input[type="text"] {
width: 100%;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
color: #fff;
padding: 10px 12px;
border-radius: 6px;
font-size: 13px;
margin-bottom: 12px;
}
input[type="text"]:focus {
outline: none;
border-color: #FF1D6C;
}
.btn-group {
display: flex;
gap: 8px;
}
.footer {
padding-top: 16px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
text-align: center;
font-size: 12px;
color: #888;
}
.footer a {
color: #FF1D6C;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
.footer span {
margin: 0 8px;
}

View File

@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Context Bridge</title>
<link rel="stylesheet" href="popup.css">
</head>
<body>
<div class="popup-container">
<div class="header">
<h1>🌉 Context Bridge</h1>
<p class="subtitle">One-click context for AI</p>
</div>
<div id="no-context" class="section" style="display: none;">
<div class="empty-state">
<p>No context URL set yet.</p>
<p class="hint">Create one with the CLI:</p>
<code>npm install -g @context-bridge/cli</code>
<code>context init</code>
<code>context url --raw</code>
</div>
</div>
<div id="has-context" class="section" style="display: none;">
<div class="status-badge">
<span class="badge-icon"></span>
<span>Context active</span>
</div>
<div class="url-display">
<label>Your Context URL:</label>
<div class="url-box">
<input type="text" id="context-url-display" readonly>
<button id="copy-btn" class="icon-btn" title="Copy">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
</button>
</div>
</div>
<div class="actions">
<button id="preview-btn" class="btn btn-secondary">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
Preview Context
</button>
<button id="change-btn" class="btn btn-secondary">Change URL</button>
</div>
</div>
<div id="set-context" class="section" style="display: none;">
<label for="context-url-input">Enter your context URL:</label>
<input type="text" id="context-url-input" placeholder="https://gist.github.com/.../raw/...">
<div class="btn-group">
<button id="save-btn" class="btn btn-primary">Save</button>
<button id="cancel-btn" class="btn btn-secondary">Cancel</button>
</div>
</div>
<div class="footer">
<a href="https://context-bridge.pages.dev" target="_blank">Website</a>
<span></span>
<a href="https://github.com/blackboxprogramming/context-bridge" target="_blank">GitHub</a>
<span></span>
<a href="#" id="clear-btn">Clear</a>
</div>
</div>
<script src="popup.js"></script>
</body>
</html>

View File

@@ -0,0 +1,224 @@
/**
* Context Bridge - Popup Script
*/
let contextUrl = null;
let rawUrl = null;
// Load state
chrome.storage.sync.get(['contextUrl', 'rawUrl'], (result) => {
contextUrl = result.contextUrl;
rawUrl = result.rawUrl;
updateUI();
});
function updateUI() {
const noContext = document.getElementById('no-context');
const hasContext = document.getElementById('has-context');
const setContext = document.getElementById('set-context');
if (rawUrl) {
noContext.style.display = 'none';
hasContext.style.display = 'block';
setContext.style.display = 'none';
document.getElementById('context-url-display').value = rawUrl;
} else {
noContext.style.display = 'block';
hasContext.style.display = 'none';
setContext.style.display = 'none';
}
}
// Copy button
document.getElementById('copy-btn')?.addEventListener('click', () => {
const input = document.getElementById('context-url-display');
input.select();
document.execCommand('copy');
const btn = document.getElementById('copy-btn');
btn.innerHTML = '<span>✓</span>';
setTimeout(() => {
btn.innerHTML = `
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
`;
}, 1000);
});
// Preview button
document.getElementById('preview-btn')?.addEventListener('click', async () => {
if (!rawUrl) return;
const btn = document.getElementById('preview-btn');
btn.innerHTML = '<span class="spinner">⏳</span> Loading...';
btn.disabled = true;
try {
const response = await fetch(rawUrl);
const content = await response.text();
// Escape HTML to prevent XSS
const escapeHtml = (text) => {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
};
// Open in new tab with safely escaped content
const previewWindow = window.open('', '_blank');
previewWindow.document.write(`
<!DOCTYPE html>
<html>
<head>
<title>Context Preview</title>
<meta charset="UTF-8">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
max-width: 800px;
margin: 40px auto;
padding: 20px;
line-height: 1.6;
background: #fff;
color: #1a1a1a;
}
pre {
background: #f5f5f5;
padding: 16px;
border-radius: 8px;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
font-family: 'SF Mono', Monaco, 'Courier New', monospace;
font-size: 14px;
line-height: 1.5;
}
h1 {
color: #667eea;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
}
.meta {
color: #666;
font-size: 14px;
margin-top: -10px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<h1>Your Context Preview</h1>
<div class="meta">Source: ${escapeHtml(rawUrl)}</div>
<pre>${escapeHtml(content)}</pre>
</body>
</html>
`);
previewWindow.document.close();
} catch (error) {
alert('Failed to load context: ' + error.message);
} finally {
btn.innerHTML = `
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
Preview Context
`;
btn.disabled = false;
}
});
// Change button
document.getElementById('change-btn')?.addEventListener('click', () => {
document.getElementById('has-context').style.display = 'none';
document.getElementById('set-context').style.display = 'block';
document.getElementById('context-url-input').value = rawUrl || '';
});
// Save button
document.getElementById('save-btn')?.addEventListener('click', async () => {
const url = document.getElementById('context-url-input').value.trim();
const btn = document.getElementById('save-btn');
const originalText = btn.innerHTML;
if (!url) {
alert('Please enter a URL');
return;
}
// Better URL validation - check actual domain
let urlObj;
try {
urlObj = new URL(url);
} catch (e) {
alert('Invalid URL format. Please enter a valid URL.');
return;
}
// Check if it's from GitHub domains
const validDomains = ['gist.github.com', 'gist.githubusercontent.com', 'raw.githubusercontent.com'];
const isValidDomain = validDomains.some(domain => urlObj.hostname === domain || urlObj.hostname.endsWith('.' + domain));
if (!isValidDomain) {
alert('Please enter a valid GitHub Gist raw URL.\n\nAccepted domains:\n- gist.github.com\n- gist.githubusercontent.com\n- raw.githubusercontent.com');
return;
}
// Validate URL actually returns content
btn.innerHTML = '⏳ Validating...';
btn.disabled = true;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const content = await response.text();
if (content.length === 0) {
throw new Error('URL returned empty content');
}
// Check if it looks like HTML instead of markdown/text
if (content.trim().startsWith('<!DOCTYPE') || content.trim().startsWith('<html')) {
throw new Error('URL returned HTML instead of raw content. Make sure to use the raw URL from your gist.');
}
// Success! Save it
chrome.storage.sync.set({
rawUrl: url,
contextUrl: url
}, () => {
rawUrl = url;
contextUrl = url;
btn.innerHTML = '✓ Saved!';
setTimeout(() => {
updateUI();
}, 1000);
});
} catch (error) {
alert(`Failed to validate URL:\n\n${error.message}\n\nPlease check:\n1. URL is accessible\n2. It's the raw gist URL\n3. You're connected to the internet`);
btn.innerHTML = originalText;
btn.disabled = false;
}
});
// Cancel button
document.getElementById('cancel-btn')?.addEventListener('click', () => {
updateUI();
});
// Clear button
document.getElementById('clear-btn')?.addEventListener('click', (e) => {
e.preventDefault();
if (confirm('Clear your context URL?')) {
chrome.storage.sync.remove(['contextUrl', 'rawUrl'], () => {
contextUrl = null;
rawUrl = null;
updateUI();
});
}
});

View File

@@ -0,0 +1,75 @@
/**
* Context Bridge - Storage Monitor
* Monitors chrome.storage.sync usage and warns when approaching quota
*/
const STORAGE_QUOTA = 102400; // 100KB Chrome sync storage limit
const WARN_THRESHOLD = 0.9; // Warn at 90%
const ITEM_QUOTA = 8192; // 8KB per item limit
async function checkStorageUsage() {
return new Promise((resolve) => {
chrome.storage.sync.getBytesInUse(null, (bytesInUse) => {
const percentUsed = bytesInUse / STORAGE_QUOTA;
const isNearLimit = percentUsed >= WARN_THRESHOLD;
resolve({
bytesInUse,
bytesRemaining: STORAGE_QUOTA - bytesInUse,
percentUsed: Math.round(percentUsed * 100),
isNearLimit,
quota: STORAGE_QUOTA
});
});
});
}
async function checkItemSize(key, value) {
const size = new Blob([JSON.stringify(value)]).size;
const isTooBig = size > ITEM_QUOTA;
return {
key,
size,
isTooBig,
quota: ITEM_QUOTA,
percentOfQuota: Math.round((size / ITEM_QUOTA) * 100)
};
}
async function displayStorageWarning() {
const usage = await checkStorageUsage();
if (usage.isNearLimit) {
const warningDiv = document.createElement('div');
warningDiv.className = 'storage-warning';
warningDiv.innerHTML = `
<strong>⚠️ Storage Warning</strong>
<p>You're using ${usage.percentUsed}% of available storage.</p>
<p>Consider cleaning up old data or switching to local storage.</p>
`;
const container = document.querySelector('.container');
if (container) {
container.insertBefore(warningDiv, container.firstChild);
}
}
return usage;
}
// Monitor storage on popup open
if (typeof chrome !== 'undefined' && chrome.storage) {
displayStorageWarning().then(usage => {
console.log('Storage usage:', usage);
});
}
// Export for use in popup.js
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
checkStorageUsage,
checkItemSize,
displayStorageWarning
};
}