Skip to content

Commit 8fcf594

Browse files
authored
Merge branch 'main' into feature/more-enhancers
2 parents e68c744 + 42956bf commit 8fcf594

File tree

5 files changed

+66
-53
lines changed

5 files changed

+66
-53
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { CONFIG, type ModeType } from '../lib/config'
1+
import { CONFIG } from '../lib/config'
22
import type { CommentEvent, CommentSpot } from '../lib/enhancer'
33
import { logger } from '../lib/logger'
44
import { EnhancerRegistry, TextareaRegistry } from '../lib/registries'
5-
import { githubPrNewCommentContentScript } from '../playgrounds/github-playground'
65

76
const enhancers = new EnhancerRegistry()
87
const enhancedTextareas = new TextareaRegistry()
@@ -24,10 +23,6 @@ enhancedTextareas.setEventHandlers(
2423

2524
export default defineContentScript({
2625
main() {
27-
if ((CONFIG.MODE as ModeType) === 'PLAYGROUNDS_PR') {
28-
githubPrNewCommentContentScript()
29-
return
30-
}
3126
const textAreasOnPageLoad = document.querySelectorAll<HTMLTextAreaElement>(`textarea`)
3227
for (const textarea of textAreasOnPageLoad) {
3328
enhanceMaybe(textarea)

browser-extension/src/lib/enhancers/modifyDOM.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,40 @@ export function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement {
99
overtypeInput.placeholder = 'Add your comment here...'
1010
const overtypeContainer = overtypeWrapper.parentElement!.closest('div')!
1111
overtypeContainer.classList.add('overtype-container')
12+
13+
// Watch for class changes and restore if removed
14+
const observer = new MutationObserver((mutations) => {
15+
mutations.forEach((mutation) => {
16+
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
17+
if (!overtypeContainer.classList.contains('overtype-container')) {
18+
overtypeContainer.classList.add('overtype-container')
19+
}
20+
}
21+
})
22+
})
23+
24+
observer.observe(overtypeContainer, {
25+
attributeFilter: ['class'],
26+
attributes: true,
27+
})
28+
29+
// Find the button that contains the text "Preview"
30+
const writePreviewTabs = Array.from(
31+
(overtypeContainer.firstElementChild as HTMLElement).querySelectorAll('button'),
32+
)
33+
const writeTab = writePreviewTabs.find((button) => button.textContent.includes('Write'))
34+
const previewTab = writePreviewTabs.find((button) => button.textContent.includes('Preview'))
35+
36+
if (writeTab && previewTab) {
37+
// Hide the textarea when the user is on the "Preview" tab
38+
writeTab.addEventListener('click', () => {
39+
overtypeWrapper.style.display = 'inline-block'
40+
})
41+
42+
previewTab.addEventListener('click', () => {
43+
overtypeWrapper.style.display = 'none'
44+
})
45+
}
46+
1247
return overtypeContainer.parentElement!.closest('div')!
1348
}

browser-extension/src/lib/registries.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { OverTypeInstance } from 'overtype'
2+
import OverType from 'overtype'
23
import type { CommentEnhancer, CommentSpot } from './enhancer'
34
import { GitHubIssueAddCommentEnhancer } from './enhancers/github/githubIssueAddComment'
45
import { GitHubIssueNewCommentEnhancer } from './enhancers/github/githubIssueNewComment'
@@ -23,6 +24,27 @@ export class EnhancerRegistry {
2324
this.register(new GitHubIssueNewCommentEnhancer())
2425
this.register(new GitHubPRAddCommentEnhancer())
2526
this.register(new GitHubPRNewCommentEnhancer())
27+
const textColor = 'rgb(31, 35, 40)'
28+
const headingColor = 'rgb(174, 52, 151)'
29+
OverType.setTheme({
30+
colors: {
31+
blockquote: 'rgb(89, 99, 110)',
32+
code: '#59636e',
33+
codeBg: '#f6f8fa',
34+
cursor: '#f95738',
35+
em: 'rgb(126, 123, 255)',
36+
h1: headingColor,
37+
h2: headingColor,
38+
h3: headingColor,
39+
hr: '#5a7a9b',
40+
link: 'rgb(9, 105, 218)',
41+
selection: 'rgba(244, 211, 94, 0.4)',
42+
strong: 'rgb(45, 1, 142)',
43+
syntaxMarker: textColor,
44+
text: textColor,
45+
},
46+
name: 'custom-github',
47+
})
2648
}
2749

2850
private register<T extends CommentSpot>(enhancer: CommentEnhancer<T>): void {

browser-extension/src/playgrounds/github-playground.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

browser-extension/tests/har-fixture.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { vi } from 'vitest'
22

3+
// Mock MutationObserver for tests
4+
global.MutationObserver = vi.fn().mockImplementation(() => ({
5+
disconnect: vi.fn(),
6+
observe: vi.fn(),
7+
takeRecords: vi.fn(() => []),
8+
}))
9+
310
// Mock the OverType editor component
411
vi.mock('overtype', () => {
512
const mockConstructor = vi.fn().mockImplementation(() => [
@@ -15,6 +22,7 @@ vi.mock('overtype', () => {
1522
},
1623
])
1724
;(mockConstructor as any).setCodeHighlighter = vi.fn()
25+
;(mockConstructor as any).setTheme = vi.fn()
1826
return {
1927
default: mockConstructor,
2028
}

0 commit comments

Comments
 (0)