Skip to content

Commit b342218

Browse files
committed
Don't let GitHub clobber the class name.
1 parent b124c2e commit b342218

File tree

6 files changed

+74
-55
lines changed

6 files changed

+74
-55
lines changed
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// playwright.config.ts
2-
import { defineConfig } from '@playwright/test'
2+
import { defineConfig } from "@playwright/test";
33

44
export default defineConfig({
5-
testDir: 'tests/e2e',
5+
testDir: "tests/e2e",
66
use: {
7-
screenshot: 'only-on-failure',
8-
video: 'retain-on-failure',
9-
trace: 'retain-on-failure',
7+
screenshot: "only-on-failure",
8+
video: "retain-on-failure",
9+
trace: "retain-on-failure",
1010
},
11-
reporter: [['html', { open: 'never' }]],
12-
})
13-
11+
reporter: [["html", { open: "never" }]],
12+
});

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ export class EnhancerRegistry {
2121
this.register(new GitHubIssueAddCommentEnhancer())
2222
this.register(new GitHubPRAddCommentEnhancer())
2323
const textColor = 'rgb(31, 35, 40)'
24+
const headingColor = 'rgb(174, 52, 151)'
2425
OverType.setTheme({
2526
colors: {
2627
blockquote: 'rgb(89, 99, 110)',
2728
code: '#59636e',
2829
codeBg: '#f6f8fa',
2930
cursor: '#f95738',
3031
em: 'rgb(126, 123, 255)',
31-
h1: textColor,
32-
h2: textColor,
33-
h3: textColor,
32+
h1: headingColor,
33+
h2: headingColor,
34+
h3: headingColor,
3435
hr: '#5a7a9b',
3536
link: 'rgb(9, 105, 218)',
3637
selection: 'rgba(244, 211, 94, 0.4)',
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
import hljs from 'highlight.js'
2-
import OverType from 'overtype'
1+
import hljs from "highlight.js";
2+
import OverType from "overtype";
33

44
export function githubPrNewCommentContentScript() {
5-
if (window.location.hostname !== 'github.com') {
6-
return
5+
if (window.location.hostname !== "github.com") {
6+
return;
77
}
8-
OverType.setCodeHighlighter(hljsHighlighter)
9-
const ghCommentBox = document.getElementById('new_comment_field') as HTMLTextAreaElement | null
8+
OverType.setCodeHighlighter(hljsHighlighter);
9+
const ghCommentBox = document.getElementById(
10+
"new_comment_field",
11+
) as HTMLTextAreaElement | null;
1012
if (ghCommentBox) {
11-
const overtypeContainer = modifyDOM(ghCommentBox)
13+
const overtypeContainer = modifyDOM(ghCommentBox);
1214
new OverType(overtypeContainer, {
1315
autoResize: true,
14-
minHeight: '102px',
15-
padding: 'var(--base-size-8)',
16-
placeholder: 'Add your comment here...',
17-
})
16+
minHeight: "102px",
17+
padding: "var(--base-size-8)",
18+
placeholder: "Add your comment here...",
19+
});
1820
}
1921
}
2022

2123
function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement {
22-
overtypeInput.classList.add('overtype-input')
23-
const overtypePreview = document.createElement('div')
24-
overtypePreview.classList.add('overtype-preview')
25-
overtypeInput.insertAdjacentElement('afterend', overtypePreview)
26-
const overtypeWrapper = overtypeInput.parentElement!.closest('div')!
27-
overtypeWrapper.classList.add('overtype-wrapper')
28-
overtypeInput.placeholder = 'Add your comment here...'
29-
const overtypeContainer = overtypeWrapper.parentElement!.closest('div')!
30-
overtypeContainer.classList.add('overtype-container')
31-
return overtypeContainer.parentElement!.closest('div')!
24+
overtypeInput.classList.add("overtype-input");
25+
const overtypePreview = document.createElement("div");
26+
overtypePreview.classList.add("overtype-preview");
27+
overtypeInput.insertAdjacentElement("afterend", overtypePreview);
28+
const overtypeWrapper = overtypeInput.parentElement!.closest("div")!;
29+
overtypeWrapper.classList.add("overtype-wrapper");
30+
overtypeInput.placeholder = "Add your comment here...";
31+
const overtypeContainer = overtypeWrapper.parentElement!.closest("div")!;
32+
overtypeContainer.classList.add("overtype-container");
33+
return overtypeContainer.parentElement!.closest("div")!;
3234
}
3335

3436
function hljsHighlighter(code: string, language?: string) {
3537
try {
3638
if (language && hljs.getLanguage(language)) {
37-
const result = hljs.highlight(code, { language })
38-
return result.value
39+
const result = hljs.highlight(code, { language });
40+
return result.value;
3941
} else {
40-
const result = hljs.highlightAuto(code)
41-
return result.value
42+
const result = hljs.highlightAuto(code);
43+
return result.value;
4244
}
4345
} catch (error) {
44-
console.warn('highlight.js highlighting failed:', error)
45-
return code
46+
console.warn("highlight.js highlighting failed:", error);
47+
return code;
4648
}
4749
}

browser-extension/vitest.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { defineConfig } from 'vitest/config'
2-
import { WxtVitest } from 'wxt/testing'
1+
import { defineConfig } from "vitest/config";
2+
import { WxtVitest } from "wxt/testing";
33

44
export default defineConfig({
55
plugins: [WxtVitest()],
66
test: {
7-
environment: 'node',
8-
pool: 'threads',
7+
environment: "node",
8+
pool: "threads",
99
globals: true,
1010
},
11-
})
11+
});

browser-extension/wxt.config.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { defineConfig } from 'wxt'
1+
import { defineConfig } from "wxt";
22

33
export default defineConfig({
44
manifest: {
55
description:
6-
'Syntax highlighting and autosave for comments on GitHub (and other other markdown-friendly websites).',
7-
host_permissions: ['https://*/*', 'http://*/*'],
6+
"Syntax highlighting and autosave for comments on GitHub (and other other markdown-friendly websites).",
7+
host_permissions: ["https://*/*", "http://*/*"],
88
icons: {
9-
16: '/icons/icon-16.png',
10-
48: '/icons/icon-48.png',
11-
128: '/icons/icon-128.png',
9+
16: "/icons/icon-16.png",
10+
48: "/icons/icon-48.png",
11+
128: "/icons/icon-128.png",
1212
},
13-
name: 'Gitcasso',
14-
permissions: ['activeTab', 'tabs'],
15-
version: '1.0.0',
13+
name: "Gitcasso",
14+
permissions: ["activeTab", "tabs"],
15+
version: "1.0.0",
1616
},
17-
modules: ['@wxt-dev/webextension-polyfill'],
18-
srcDir: 'src',
17+
modules: ["@wxt-dev/webextension-polyfill"],
18+
srcDir: "src",
1919
webExt: {
2020
disabled: true,
2121
},
22-
})
22+
});

0 commit comments

Comments
 (0)