|
1 | | -import hljs from 'highlight.js' |
2 | | -import OverType from 'overtype' |
| 1 | +import hljs from "highlight.js"; |
| 2 | +import OverType from "overtype"; |
3 | 3 |
|
4 | 4 | export function githubPrNewCommentContentScript() { |
5 | | - if (window.location.hostname !== 'github.com') { |
6 | | - return |
| 5 | + if (window.location.hostname !== "github.com") { |
| 6 | + return; |
7 | 7 | } |
8 | | - OverType.setCodeHighlighter(hljsHighlighter) |
9 | | - const ghCommentBox = document.getElementById('new_comment_field') as HTMLTextAreaElement | null |
| 8 | + OverType.setCodeHighlighter(hljsHighlighter); |
| 9 | + const ghCommentBox = document.getElementById( |
| 10 | + "new_comment_field", |
| 11 | + ) as HTMLTextAreaElement | null; |
10 | 12 | if (ghCommentBox) { |
11 | | - const overtypeContainer = modifyDOM(ghCommentBox) |
| 13 | + const overtypeContainer = modifyDOM(ghCommentBox); |
12 | 14 | new OverType(overtypeContainer, { |
13 | 15 | autoResize: true, |
14 | | - minHeight: '102px', |
15 | | - padding: 'var(--base-size-8)', |
16 | | - placeholder: 'Add your comment here...', |
17 | | - }) |
| 16 | + minHeight: "102px", |
| 17 | + padding: "var(--base-size-8)", |
| 18 | + placeholder: "Add your comment here...", |
| 19 | + }); |
18 | 20 | } |
19 | 21 | } |
20 | 22 |
|
21 | 23 | function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement { |
22 | | - overtypeInput.classList.add('overtype-input') |
23 | | - const overtypePreview = document.createElement('div') |
24 | | - overtypePreview.classList.add('overtype-preview') |
25 | | - overtypeInput.insertAdjacentElement('afterend', overtypePreview) |
26 | | - const overtypeWrapper = overtypeInput.parentElement!.closest('div')! |
27 | | - overtypeWrapper.classList.add('overtype-wrapper') |
28 | | - overtypeInput.placeholder = 'Add your comment here...' |
29 | | - const overtypeContainer = overtypeWrapper.parentElement!.closest('div')! |
30 | | - overtypeContainer.classList.add('overtype-container') |
31 | | - return overtypeContainer.parentElement!.closest('div')! |
| 24 | + overtypeInput.classList.add("overtype-input"); |
| 25 | + const overtypePreview = document.createElement("div"); |
| 26 | + overtypePreview.classList.add("overtype-preview"); |
| 27 | + overtypeInput.insertAdjacentElement("afterend", overtypePreview); |
| 28 | + const overtypeWrapper = overtypeInput.parentElement!.closest("div")!; |
| 29 | + overtypeWrapper.classList.add("overtype-wrapper"); |
| 30 | + overtypeInput.placeholder = "Add your comment here..."; |
| 31 | + const overtypeContainer = overtypeWrapper.parentElement!.closest("div")!; |
| 32 | + overtypeContainer.classList.add("overtype-container"); |
| 33 | + return overtypeContainer.parentElement!.closest("div")!; |
32 | 34 | } |
33 | 35 |
|
34 | 36 | function hljsHighlighter(code: string, language?: string) { |
35 | 37 | try { |
36 | 38 | if (language && hljs.getLanguage(language)) { |
37 | | - const result = hljs.highlight(code, { language }) |
38 | | - return result.value |
| 39 | + const result = hljs.highlight(code, { language }); |
| 40 | + return result.value; |
39 | 41 | } else { |
40 | | - const result = hljs.highlightAuto(code) |
41 | | - return result.value |
| 42 | + const result = hljs.highlightAuto(code); |
| 43 | + return result.value; |
42 | 44 | } |
43 | 45 | } catch (error) { |
44 | | - console.warn('highlight.js highlighting failed:', error) |
45 | | - return code |
| 46 | + console.warn("highlight.js highlighting failed:", error); |
| 47 | + return code; |
46 | 48 | } |
47 | 49 | } |
0 commit comments