|
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"; |
5 | 2 |
|
6 | 3 | export default defineContentScript({ |
7 | 4 | 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 | + }); |
18 | 17 | }, |
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