Skip to content

Commit f346da5

Browse files
authored
GitHub color theme (#38 closes #11)
2 parents 2373c23 + 031d2e3 commit f346da5

File tree

8 files changed

+52
-58
lines changed

8 files changed

+52
-58
lines changed

browser-extension/biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"files": {
1212
"ignoreUnknown": false,
13-
"includes": [".*", "src/**", "tests/**", "!src/overtype", "!src/playgrounds"]
13+
"includes": [".*", "*.config.ts", "src/**", "tests/**", "!src/overtype"]
1414
},
1515
"formatter": {
1616
"enabled": true,

browser-extension/playwright.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
import { defineConfig } from '@playwright/test'
33

44
export default defineConfig({
5+
reporter: [['html', { open: 'never' }]],
56
testDir: 'tests/e2e',
67
use: {
78
screenshot: 'only-on-failure',
8-
video: 'retain-on-failure',
99
trace: 'retain-on-failure',
10+
video: 'retain-on-failure',
1011
},
11-
reporter: [['html', { open: 'never' }]],
1212
})
13-

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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,22 @@ 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+
1229
return overtypeContainer.parentElement!.closest('div')!
1330
}

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 { GitHubPRAddCommentEnhancer } from './enhancers/github/githubPRAddComment'
@@ -19,6 +20,27 @@ export class EnhancerRegistry {
1920
// Register all available handlers
2021
this.register(new GitHubIssueAddCommentEnhancer())
2122
this.register(new GitHubPRAddCommentEnhancer())
23+
const textColor = 'rgb(31, 35, 40)'
24+
const headingColor = 'rgb(174, 52, 151)'
25+
OverType.setTheme({
26+
colors: {
27+
blockquote: 'rgb(89, 99, 110)',
28+
code: '#59636e',
29+
codeBg: '#f6f8fa',
30+
cursor: '#f95738',
31+
em: 'rgb(126, 123, 255)',
32+
h1: headingColor,
33+
h2: headingColor,
34+
h3: headingColor,
35+
hr: '#5a7a9b',
36+
link: 'rgb(9, 105, 218)',
37+
selection: 'rgba(244, 211, 94, 0.4)',
38+
strong: 'rgb(45, 1, 142)',
39+
syntaxMarker: textColor,
40+
text: textColor,
41+
},
42+
name: 'custom-github',
43+
})
2244
}
2345

2446
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
}

browser-extension/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default defineConfig({
55
plugins: [WxtVitest()],
66
test: {
77
environment: 'node',
8-
pool: 'threads',
98
globals: true,
9+
pool: 'threads',
1010
},
1111
})

0 commit comments

Comments
 (0)