/** * 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 = ` Insert Context `; 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(); }