Skip to content

Commit 1a85c21

Browse files
author
ntwigg
committed
Harder than I thought lol...
1 parent 1e02cb6 commit 1a85c21

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

browser-extension/package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser-extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"author": "DiffPlug",
33
"dependencies": {
44
"@wxt-dev/webextension-polyfill": "^1.0.0",
5+
"overtype": "^1.2.3",
56
"webextension-polyfill": "^0.12.0"
67
},
78
"description": "Syntax highlighting and autosave for comments on GitHub (and other other markdown-friendly places).",

browser-extension/src/entrypoints/content.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { CONFIG } from './content/config'
22
import { logger } from './content/logger'
33
import { injectStyles } from './content/styles'
4+
import OverType from 'overtype'
45

56
export default defineContentScript({
67
main() {
78
const textAreasOnPageLoad = document.querySelectorAll<HTMLTextAreaElement>(`textarea`)
89
for (const textarea of textAreasOnPageLoad) {
9-
initializeMaybe(textarea)
10+
initializeTextArea(textarea)
1011
}
1112
const observer = new MutationObserver(handleMutations)
1213
observer.observe(document.body, {
@@ -25,19 +26,16 @@ function handleMutations(mutations: MutationRecord[]): void {
2526
if (node.nodeType === Node.ELEMENT_NODE) {
2627
const element = node as Element
2728
if (element.tagName === 'textarea') {
28-
initializeMaybe(element as HTMLTextAreaElement)
29+
initializeTextArea(element as HTMLTextAreaElement)
2930
}
3031
}
3132
}
3233
}
3334
}
3435

35-
function initializeMaybe(textarea: HTMLTextAreaElement) {
36-
if (!textarea.classList.contains(CONFIG.ADDED_OVERTYPE_CLASS)) {
37-
logger.debug('activating textarea {}', textarea)
38-
injectStyles()
39-
textarea.classList.add(CONFIG.ADDED_OVERTYPE_CLASS)
40-
} else {
41-
logger.debug('already activated textarea {}', textarea)
42-
}
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")
4341
}

0 commit comments

Comments
 (0)