Skip to content

Commit 861a9c8

Browse files
committed
Freely modify overtype styles.
1 parent de2a9fd commit 861a9c8

File tree

2 files changed

+23
-47
lines changed

2 files changed

+23
-47
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineContentScript({
1010
"new_comment_field"
1111
) as HTMLTextAreaElement | null;
1212
if (ghCommentBox) {
13-
const overtypeContainer = modifyGithubDOM(ghCommentBox);
13+
const overtypeContainer = modifyDOM(ghCommentBox);
1414
new OverType(overtypeContainer, {
1515
placeholder: "Add your comment here...",
1616
autoResize: true,
@@ -23,42 +23,15 @@ export default defineContentScript({
2323
runAt: "document_end",
2424
});
2525

26-
function modifyGithubDOM(ghCommentBox: HTMLTextAreaElement): HTMLElement {
27-
ghCommentBox.classList.add("overtype-input");
28-
const previewDiv = document.createElement("div");
29-
previewDiv.classList.add("overtype-preview");
30-
ghCommentBox.insertAdjacentElement("afterend", previewDiv);
31-
const ghCommentWrapper = ghCommentBox.parentElement!.closest("div")!;
32-
ghCommentWrapper.classList.add("overtype-wrapper");
33-
injectGithubStyles({
34-
commentBox: ghCommentBox,
35-
commentWrapper: ghCommentWrapper,
36-
overtypePreviewDiv: previewDiv,
37-
});
38-
const ghCommentContainer = ghCommentWrapper.parentElement!.closest("div")!;
39-
ghCommentContainer.classList.add("overtype-container");
40-
return ghCommentContainer.parentElement!.closest("div")!;
41-
}
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";
26+
function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement {
27+
overtypeInput.classList.add("overtype-input");
28+
const overtypePreview = document.createElement("div");
29+
overtypePreview.classList.add("overtype-preview");
30+
overtypeInput.insertAdjacentElement("afterend", overtypePreview);
31+
const overtypeWrapper = overtypeInput.parentElement!.closest("div")!;
32+
overtypeWrapper.classList.add("overtype-wrapper");
33+
overtypeInput.placeholder = "Add your comment here...";
34+
const overtypeContainer = overtypeWrapper.parentElement!.closest("div")!;
35+
overtypeContainer.classList.add("overtype-container");
36+
return overtypeContainer.parentElement!.closest("div")!;
6437
}

browser-extension/src/overtype/styles.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { themeToCSSVars } from "./themes.js";
1010
* @param {Object} options - Configuration options
1111
* @returns {string} Complete CSS string
1212
*/
13-
export function generateStyles(options = {}) {
14-
const {
13+
export function generateStyles(options = githubOptions) {
14+
let {
1515
fontSize = "14px",
1616
lineHeight = 1.6,
1717
/* System-first, guaranteed monospaced; avoids Android 'ui-monospace' pitfalls */
@@ -21,6 +21,9 @@ export function generateStyles(options = {}) {
2121
mobile = {},
2222
} = options;
2323

24+
fontFamily = "inherit !important"
25+
fontSize = "var(--text-body-size-medium) !important"
26+
2427
// Generate mobile overrides
2528
const mobileStyles =
2629
Object.keys(mobile).length > 0
@@ -48,9 +51,9 @@ export function generateStyles(options = {}) {
4851
/* Middle-ground CSS Reset - Prevent parent styles from leaking in */
4952
.overtype-container * {
5053
/* Box model - these commonly leak */
51-
margin: 0 !important;
54+
/* margin: 0 !important; */
5255
padding: 0 !important;
53-
border: 0 !important;
56+
/* border: 0 !important; */
5457
5558
/* Layout - these can break our layout */
5659
/* Don't reset position - it breaks dropdowns */
@@ -111,7 +114,7 @@ export function generateStyles(options = {}) {
111114
112115
.overtype-wrapper {
113116
position: relative !important; /* Override reset - needed for absolute children */
114-
width: 100% !important;
117+
/* width: 100% !important; */
115118
height: 100% !important; /* Take full height of grid cell */
116119
min-height: 60px !important; /* Minimum usable height */
117120
overflow: hidden !important;
@@ -265,7 +268,7 @@ export function generateStyles(options = {}) {
265268
266269
/* Markdown element styling - NO SIZE CHANGES */
267270
.overtype-wrapper .overtype-preview .header {
268-
font-weight: bold !important;
271+
font-weight: normal !important;
269272
}
270273
271274
/* Header colors */
@@ -284,7 +287,7 @@ export function generateStyles(options = {}) {
284287
.overtype-wrapper .overtype-preview h2,
285288
.overtype-wrapper .overtype-preview h3 {
286289
font-size: inherit !important;
287-
font-weight: bold !important;
290+
font-weight: normal !important;
288291
margin: 0 !important;
289292
padding: 0 !important;
290293
display: inline !important;
@@ -321,7 +324,7 @@ export function generateStyles(options = {}) {
321324
/* Bold text */
322325
.overtype-wrapper .overtype-preview strong {
323326
color: var(--strong, #ee964b) !important;
324-
font-weight: bold !important;
327+
font-weight: normal !important;
325328
}
326329
327330
/* Italic text */

0 commit comments

Comments
 (0)