Skip to content

Commit 4e23963

Browse files
committed
Prepare to show commentSpot on page.
1 parent 3375fd4 commit 4e23963

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

browser-extension/tests/har-view.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,25 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
332332
console.log('Fetched content script, patching webextension-polyfill...');
333333
334334
// Replace the problematic webextension-polyfill error check
335-
const patchedCode = code.replace(
335+
let patchedCode = code.replace(
336336
/throw new Error\\("This script should only be loaded in a browser extension\\."/g,
337337
'console.warn("Webextension-polyfill check bypassed for HAR testing"'
338338
);
339+
340+
// Patch the content script to track CommentSpots globally
341+
patchedCode = patchedCode.replace(
342+
/sendEventToBackground\\('ENHANCED', spot\\)/g,
343+
\`sendEventToBackground('ENHANCED', spot);
344+
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
345+
window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'ENHANCED'});\`
346+
);
347+
348+
patchedCode = patchedCode.replace(
349+
/sendEventToBackground\\('DESTROYED', spot\\)/g,
350+
\`sendEventToBackground('DESTROYED', spot);
351+
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
352+
window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'DESTROYED'});\`
353+
);
339354
340355
// Mock necessary APIs before executing
341356
window.chrome = window.chrome || {
@@ -347,6 +362,9 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
347362
}
348363
};
349364
window.browser = window.chrome;
365+
366+
// Create a global registry to track comment spots for debugging
367+
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
350368
351369
// Execute the patched script
352370
const script = document.createElement('script');
@@ -442,6 +460,53 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
442460
});
443461
444462
document.body.appendChild(rebuildButton);
463+
464+
// Create CommentSpot display
465+
const commentSpotDisplay = document.createElement('div');
466+
commentSpotDisplay.id = 'gitcasso-comment-spots';
467+
commentSpotDisplay.style.cssText = \`
468+
position: fixed;
469+
top: 80px;
470+
right: 20px;
471+
width: 300px;
472+
max-height: 400px;
473+
background: rgba(255, 255, 255, 0.95);
474+
border: 1px solid #ddd;
475+
border-radius: 8px;
476+
padding: 15px;
477+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
478+
font-size: 11px;
479+
line-height: 1.4;
480+
overflow-y: auto;
481+
z-index: 999998;
482+
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
483+
backdrop-filter: blur(10px);
484+
\`;
485+
486+
// Function to update CommentSpot display
487+
function updateCommentSpotDisplay() {
488+
const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : [];
489+
490+
const content = spots.length > 0
491+
? \`<div style="font-weight: bold; margin-bottom: 8px; color: #333;">CommentSpots (\${spots.length}):</div><pre style="margin: 0; white-space: pre-wrap;">\${JSON.stringify(spots, null, 2)}</pre>\`
492+
: '<div style="color: #666; font-style: italic;">No CommentSpots detected yet...</div>';
493+
494+
commentSpotDisplay.innerHTML = content;
495+
}
496+
497+
// Initial update
498+
updateCommentSpotDisplay();
499+
500+
// Update display periodically
501+
setInterval(updateCommentSpotDisplay, 2000);
502+
503+
document.body.appendChild(commentSpotDisplay);
504+
505+
// Expose textarea registry access function globally
506+
window.gitcassoGetCommentSpots = function() {
507+
// Return the global comment spots array
508+
return window.gitcassoCommentSpots || [];
509+
};
445510
</script>
446511
`
447512
if (!html.includes('</body>')) {

0 commit comments

Comments
 (0)