Skip to content

Commit a107bd5

Browse files
committed
Inject GitHub styles with !important to match OEM.
1 parent 753f9d2 commit a107bd5

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,59 @@ export default defineContentScript({
66
return;
77
}
88

9-
const ghCommentBox = document.getElementById("new_comment_field") as
10-
| HTMLTextAreaElement
11-
| undefined;
9+
const ghCommentBox = document.getElementById(
10+
"new_comment_field"
11+
) as HTMLTextAreaElement | null;
1212
if (ghCommentBox) {
1313
const overtypeContainer = modifyGithubDOM(ghCommentBox);
1414
new OverType(overtypeContainer, {
1515
placeholder: "Add your comment here...",
1616
autoResize: true,
1717
minHeight: "102px",
18+
padding: "var(--base-size-8)",
1819
});
1920
}
2021
},
2122
matches: ["<all_urls>"],
2223
runAt: "document_end",
2324
});
2425

25-
function modifyGithubDOM(ghCommentBox: HTMLTextAreaElement) {
26+
function modifyGithubDOM(ghCommentBox: HTMLTextAreaElement): HTMLElement {
2627
ghCommentBox.classList.add("overtype-input");
2728
const previewDiv = document.createElement("div");
2829
previewDiv.classList.add("overtype-preview");
2930
ghCommentBox.insertAdjacentElement("afterend", previewDiv);
3031
const ghCommentWrapper = ghCommentBox.parentElement!.closest("div")!;
3132
ghCommentWrapper.classList.add("overtype-wrapper");
33+
injectGithubStyles({
34+
commentBox: ghCommentBox,
35+
commentWrapper: ghCommentWrapper,
36+
overtypePreviewDiv: previewDiv,
37+
});
3238
const ghCommentContainer = ghCommentWrapper.parentElement!.closest("div")!;
3339
ghCommentContainer.classList.add("overtype-container");
3440
return ghCommentContainer.parentElement!.closest("div")!;
3541
}
42+
43+
interface GithubDOM {
44+
commentBox: HTMLTextAreaElement;
45+
commentWrapper: HTMLDivElement;
46+
overtypePreviewDiv: HTMLDivElement;
47+
}
48+
function injectGithubStyles({
49+
commentBox,
50+
commentWrapper,
51+
overtypePreviewDiv,
52+
}: GithubDOM) {
53+
commentBox.placeholder = "Add your comment here...";
54+
commentBox.style.fontFamily = "inherit !important";
55+
commentBox.style.fontSize = "var(--text-body-size-medium) !important";
56+
overtypePreviewDiv.style.fontFamily = "inherit !important";
57+
overtypePreviewDiv.style.fontSize = "var(--text-body-size-medium) !important";
58+
commentWrapper.style.margin = "var(--base-size-8) !important";
59+
commentWrapper.style.border =
60+
"var(--borderWidth-thin) solid var(--borderColor-default, var(--color-border-default)) !important";
61+
commentWrapper.style.borderRadius = "var(--borderRadius-medium) !important";
62+
commentWrapper.style.width =
63+
"calc(100% - var(--stack-padding-condensed, 8px) * 2) !important";
64+
}

browser-extension/src/overtype/overtype.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface OverTypeOptions {
2-
fontSize?: number;
2+
fontSize?: string;
33
lineHeight?: number;
44
fontFamily?: string;
55
theme?: string | ThemeObject;
@@ -9,6 +9,7 @@ interface OverTypeOptions {
99
autoResize?: boolean;
1010
minHeight?: string;
1111
maxHeight?: string;
12+
padding?: string;
1213
toolbar?: boolean;
1314
onChange?: (value: string) => void;
1415
onKeydown?: (event: KeyboardEvent) => void;
@@ -28,7 +29,7 @@ class OverType {
2829
setValue(value: string): void;
2930
getRenderedHTML(processContent?: boolean): string;
3031
getPreviewHTML(): string;
31-
setTheme(theme: string | ThemeObject): void;
32+
static setTheme(theme: string | ThemeObject): void;
3233
showStats(show: boolean): void;
3334
showPlainTextarea(show: boolean): void;
3435
showPreviewMode(show: boolean): void;

0 commit comments

Comments
 (0)