Skip to content

Commit 0a245f2

Browse files
committed
Modify the GH DOM a bit to match what OverType expects so that it uses the existing elements instead of creating new ones.
1 parent f2ce504 commit 0a245f2

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed
Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
1-
import { CONFIG } from './content/config'
2-
import { logger } from './content/logger'
3-
import { injectStyles } from './content/styles'
4-
import OverType from 'overtype'
1+
import OverType from "../overtype/overtype";
52

63
export default defineContentScript({
74
main() {
8-
const textAreasOnPageLoad = document.querySelectorAll<HTMLTextAreaElement>(`textarea`)
9-
for (const textarea of textAreasOnPageLoad) {
10-
initializeTextArea(textarea)
11-
}
12-
const observer = new MutationObserver(handleMutations)
13-
observer.observe(document.body, {
14-
childList: true,
15-
subtree: true,
16-
})
17-
logger.debug('Extension loaded')
5+
const ghCommentBox = document.getElementById("new_comment_field")!;
6+
ghCommentBox.classList.add("overtype-input");
7+
const previewDiv = document.createElement("div");
8+
previewDiv.classList.add("overtype-preview");
9+
ghCommentBox.insertAdjacentElement("afterend", previewDiv);
10+
const ghCommentWrapper = ghCommentBox.parentElement!.closest("div")!;
11+
ghCommentWrapper.classList.add("overtype-wrapper");
12+
const ghCommentContainer = ghCommentWrapper.parentElement!.closest("div")!;
13+
ghCommentContainer.classList.add("overtype-container");
14+
new OverType(ghCommentContainer.parentElement!.closest("div")!, {
15+
placeholder: "Add your comment here...",
16+
});
1817
},
19-
matches: ['<all_urls>'],
20-
runAt: 'document_end',
21-
})
22-
23-
function handleMutations(mutations: MutationRecord[]): void {
24-
for (const mutation of mutations) {
25-
for (const node of mutation.addedNodes) {
26-
if (node.nodeType === Node.ELEMENT_NODE) {
27-
const element = node as Element
28-
if (element.tagName === 'textarea') {
29-
initializeTextArea(element as HTMLTextAreaElement)
30-
}
31-
}
32-
}
33-
}
34-
}
35-
36-
function initializeTextArea(textarea: HTMLTextAreaElement) {
37-
logger.debug('activating textarea {}', textarea)
38-
const overtype = new OverType(textarea)[0]
39-
logger.debug('overtype initialized {}', overtype)
40-
overtype.setValue('Testing 1, 2, 3')
41-
}
18+
matches: ["<all_urls>"],
19+
runAt: "document_end",
20+
});

0 commit comments

Comments
 (0)