Skip to content

Commit 11a9897

Browse files
committed
Simplify.
1 parent c8b6e8a commit 11a9897

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,6 @@ function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot
1515
type,
1616
}
1717

18-
// Add textarea debugging info for har:view testing
19-
if (textarea && (window as any).gitcassoDebugMode) {
20-
const rect = textarea.getBoundingClientRect();
21-
(message as any).textareaInfo = {
22-
id: textarea.id || '',
23-
name: textarea.name || '',
24-
className: textarea.className || '',
25-
tagName: textarea.tagName,
26-
placeholder: textarea.placeholder || '',
27-
value: textarea.value ? textarea.value.substring(0, 50) + '...' : '',
28-
parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '',
29-
position: {
30-
top: rect.top,
31-
left: rect.left,
32-
width: rect.width,
33-
height: rect.height
34-
}
35-
};
36-
}
37-
3818
browser.runtime.sendMessage(message).catch((error) => {
3919
logger.debug('Failed to send event to background:', error)
4020
})

browser-extension/tests/har-view.ts

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
360360
console.warn('Failed to patch sendEventToBackground function');
361361
}
362362
363-
// Enable debug mode for textarea info capture
364-
window.gitcassoDebugMode = true;
365363
366364
// Mock necessary APIs before executing
367365
window.chrome = window.chrome || {
@@ -386,17 +384,41 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
386384
if (message && message.spot && message.type) {
387385
try {
388386
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
387+
388+
// Capture textarea debugging info here instead of in production code
389+
let textareaInfo = null;
390+
if (message.type === 'ENHANCED' && window.gitcassoTextareaRegistry) {
391+
const textareas = document.querySelectorAll('textarea');
392+
for (const textarea of textareas) {
393+
const enhanced = window.gitcassoTextareaRegistry.get(textarea);
394+
if (enhanced && enhanced.spot.unique_key === message.spot.unique_key) {
395+
const rect = textarea.getBoundingClientRect();
396+
textareaInfo = {
397+
id: textarea.id || '',
398+
name: textarea.name || '',
399+
className: textarea.className || '',
400+
tagName: textarea.tagName,
401+
placeholder: textarea.placeholder || '',
402+
value: textarea.value ? textarea.value.substring(0, 50) + '...' : '',
403+
parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '',
404+
position: {
405+
top: rect.top,
406+
left: rect.left,
407+
width: rect.width,
408+
height: rect.height
409+
}
410+
};
411+
break;
412+
}
413+
}
414+
}
415+
389416
const trackingData = Object.assign({}, message.spot, {
390417
timestamp: Date.now(),
391-
action: message.type
418+
action: message.type,
419+
textareaInfo
392420
});
393421
394-
// Include textarea info if available in the message
395-
if (message.textareaInfo) {
396-
trackingData.textareaInfo = message.textareaInfo;
397-
console.log('Textarea info captured:', message.textareaInfo);
398-
}
399-
400422
window.gitcassoCommentSpots.push(trackingData);
401423
console.log('CommentSpot captured via sendMessage:', trackingData);
402424
console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length);
@@ -537,42 +559,43 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
537559
backdrop-filter: blur(10px);
538560
\`;
539561
540-
// Function to update CommentSpot display
562+
// Simplified display formatting
563+
const styles = {
564+
header: 'font-weight: bold; margin-bottom: 8px; color: #333;',
565+
spotContainer: 'margin-bottom: 12px; padding: 8px; border: 1px solid #eee; border-radius: 4px;',
566+
spotTitle: 'font-weight: bold; color: #555;',
567+
jsonPre: 'margin: 4px 0; font-size: 10px;',
568+
textareaHeader: 'font-weight: bold; color: #007acc; margin-top: 8px;',
569+
textareaPre: 'margin: 4px 0; font-size: 10px; color: #666;',
570+
noInfo: 'color: #999; font-style: italic; margin-top: 4px;',
571+
empty: 'color: #666; font-style: italic;'
572+
};
573+
574+
function formatSpot(spot, index) {
575+
const { textareaInfo, ...spotData } = spot;
576+
return \`
577+
<div style="\${styles.spotContainer}">
578+
<div style="\${styles.spotTitle}">Spot \${index + 1}:</div>
579+
<pre style="\${styles.jsonPre}">\${JSON.stringify(spotData, null, 2)}</pre>
580+
\${textareaInfo
581+
? \`<div style="\${styles.textareaHeader}">Textarea Info:</div>
582+
<pre style="\${styles.textareaPre}">\${JSON.stringify(textareaInfo, null, 2)}</pre>\`
583+
: \`<div style="\${styles.noInfo}">No textarea info captured</div>\`
584+
}
585+
</div>
586+
\`;
587+
}
588+
541589
function updateCommentSpotDisplay() {
542590
const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : [];
543591
544-
// Debug logging
545-
if (window.gitcassoCommentSpots) {
546-
console.log('Raw gitcassoCommentSpots array:', window.gitcassoCommentSpots);
547-
}
548592
console.log('Spots for display:', spots);
549593
console.log('All textareas on page:', document.querySelectorAll('textarea').length);
550594
551-
let content = '';
552-
if (spots.length > 0) {
553-
content = \`<div style="font-weight: bold; margin-bottom: 8px; color: #333;">CommentSpots (\${spots.length}):</div>\`;
554-
555-
spots.forEach((spot, index) => {
556-
const hasTextareaInfo = spot.textareaInfo;
557-
const spotData = Object.assign({}, spot);
558-
delete spotData.textareaInfo; // Remove from main display
559-
560-
content += \`<div style="margin-bottom: 12px; padding: 8px; border: 1px solid #eee; border-radius: 4px;">\`;
561-
content += \`<div style="font-weight: bold; color: #555;">Spot \${index + 1}:</div>\`;
562-
content += \`<pre style="margin: 4px 0; font-size: 10px;">\${JSON.stringify(spotData, null, 2)}</pre>\`;
563-
564-
if (hasTextareaInfo) {
565-
content += \`<div style="font-weight: bold; color: #007acc; margin-top: 8px;">Textarea Info:</div>\`;
566-
content += \`<pre style="margin: 4px 0; font-size: 10px; color: #666;">\${JSON.stringify(spot.textareaInfo, null, 2)}</pre>\`;
567-
} else {
568-
content += \`<div style="color: #999; font-style: italic; margin-top: 4px;">No textarea info captured</div>\`;
569-
}
570-
571-
content += \`</div>\`;
572-
});
573-
} else {
574-
content = '<div style="color: #666; font-style: italic;">No CommentSpots detected yet...<br><small>Textareas found: ' + document.querySelectorAll('textarea').length + '</small></div>';
575-
}
595+
const content = spots.length > 0
596+
? \`<div style="\${styles.header}">CommentSpots (\${spots.length}):</div>
597+
\${spots.map(formatSpot).join('')}\`
598+
: \`<div style="\${styles.empty}">No CommentSpots detected yet...<br><small>Textareas found: \${document.querySelectorAll('textarea').length}</small></div>\`;
576599
577600
commentSpotDisplay.innerHTML = content;
578601
}

0 commit comments

Comments
 (0)