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