From 9306a5b20f1afe6a884a7920fc6fc020ddc24f93 Mon Sep 17 00:00:00 2001 From: Todd Riley Date: Fri, 5 Sep 2025 13:36:54 -0400 Subject: [PATCH 1/3] biome --- .../src/playgrounds/github-playground.ts | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/browser-extension/src/playgrounds/github-playground.ts b/browser-extension/src/playgrounds/github-playground.ts index dae988f..3b728ef 100644 --- a/browser-extension/src/playgrounds/github-playground.ts +++ b/browser-extension/src/playgrounds/github-playground.ts @@ -1,49 +1,47 @@ -import hljs from "highlight.js"; -import OverType from "../overtype/overtype"; +import hljs from 'highlight.js' +import OverType from '../overtype/overtype' export function githubPrNewCommentContentScript() { - if (window.location.hostname !== "github.com") { - return; - } - OverType.setCodeHighlighter(hljsHighlighter); - const ghCommentBox = document.getElementById( - "new_comment_field" - ) as HTMLTextAreaElement | null; - if (ghCommentBox) { - const overtypeContainer = modifyDOM(ghCommentBox); - new OverType(overtypeContainer, { - placeholder: "Add your comment here...", - autoResize: true, - minHeight: "102px", - padding: "var(--base-size-8)", - }); - } + if (window.location.hostname !== 'github.com') { + return + } + OverType.setCodeHighlighter(hljsHighlighter) + const ghCommentBox = document.getElementById('new_comment_field') as HTMLTextAreaElement | null + if (ghCommentBox) { + const overtypeContainer = modifyDOM(ghCommentBox) + new OverType(overtypeContainer, { + autoResize: true, + minHeight: '102px', + padding: 'var(--base-size-8)', + placeholder: 'Add your comment here...', + }) + } } function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement { - overtypeInput.classList.add("overtype-input"); - const overtypePreview = document.createElement("div"); - overtypePreview.classList.add("overtype-preview"); - overtypeInput.insertAdjacentElement("afterend", overtypePreview); - const overtypeWrapper = overtypeInput.parentElement!.closest("div")!; - overtypeWrapper.classList.add("overtype-wrapper"); - overtypeInput.placeholder = "Add your comment here..."; - const overtypeContainer = overtypeWrapper.parentElement!.closest("div")!; - overtypeContainer.classList.add("overtype-container"); - return overtypeContainer.parentElement!.closest("div")!; + overtypeInput.classList.add('overtype-input') + const overtypePreview = document.createElement('div') + overtypePreview.classList.add('overtype-preview') + overtypeInput.insertAdjacentElement('afterend', overtypePreview) + const overtypeWrapper = overtypeInput.parentElement!.closest('div')! + overtypeWrapper.classList.add('overtype-wrapper') + overtypeInput.placeholder = 'Add your comment here...' + const overtypeContainer = overtypeWrapper.parentElement!.closest('div')! + overtypeContainer.classList.add('overtype-container') + return overtypeContainer.parentElement!.closest('div')! } function hljsHighlighter(code: string, language: string) { try { if (language && hljs.getLanguage(language)) { - const result = hljs.highlight(code, { language }); - return result.value; + const result = hljs.highlight(code, { language }) + return result.value } else { - const result = hljs.highlightAuto(code); - return result.value; + const result = hljs.highlightAuto(code) + return result.value } } catch (error) { - console.warn("highlight.js highlighting failed:", error); - return code; + console.warn('highlight.js highlighting failed:', error) + return code } } From c1665e5c4bd4b913b53356f5ef46b2a3c2084d54 Mon Sep 17 00:00:00 2001 From: Todd Riley Date: Fri, 5 Sep 2025 13:48:14 -0400 Subject: [PATCH 2/3] Break up github.ts into a more organized folder/file structure. --- .../{github.ts => github/githubAddComment.ts} | 42 ++++--------------- .../lib/enhancers/github/githubHighlighter.ts | 16 +++++++ .../lib/enhancers/github/githubSpotTypes.ts | 11 +++++ browser-extension/src/lib/registries.ts | 2 +- 4 files changed, 36 insertions(+), 35 deletions(-) rename browser-extension/src/lib/enhancers/{github.ts => github/githubAddComment.ts} (73%) create mode 100644 browser-extension/src/lib/enhancers/github/githubHighlighter.ts create mode 100644 browser-extension/src/lib/enhancers/github/githubSpotTypes.ts diff --git a/browser-extension/src/lib/enhancers/github.ts b/browser-extension/src/lib/enhancers/github/githubAddComment.ts similarity index 73% rename from browser-extension/src/lib/enhancers/github.ts rename to browser-extension/src/lib/enhancers/github/githubAddComment.ts index 0c22980..d74352f 100644 --- a/browser-extension/src/lib/enhancers/github.ts +++ b/browser-extension/src/lib/enhancers/github/githubAddComment.ts @@ -1,23 +1,12 @@ -import hljs from 'highlight.js' -import { logger } from '../../lib/logger' -import OverType, { type OverTypeInstance } from '../../overtype/overtype' -import type { CommentEnhancer, CommentSpot } from '../enhancer' +import OverType, { type OverTypeInstance } from '../../../overtype/overtype' +import type { CommentEnhancer, CommentSpot } from '../../enhancer' +import { logger } from '../../logger' +import { githubHighlighter } from './githubHighlighter' +import { GITHUB_SPOT_TYPES } from './githubSpotTypes' -const GITHUB_SPOT_TYPES = [ - 'GH_PR_ADD_COMMENT', - /* TODO - 'GH_ISSUE_NEW', - 'GH_PR_NEW', - 'GH_ISSUE_ADD_COMMENT', - 'GH_ISSUE_EDIT_COMMENT', - 'GH_PR_EDIT_COMMENT', - 'GH_PR_CODE_COMMENT', - */ -] as const +type GitHubSpotType = (typeof GITHUB_SPOT_TYPES)[number] -export type GitHubSpotType = (typeof GITHUB_SPOT_TYPES)[number] - -export interface GitHubAddCommentSpot extends CommentSpot { +interface GitHubAddCommentSpot extends CommentSpot { type: GitHubSpotType // Override to narrow from string to specific union domain: string slug: string // owner/repo @@ -55,7 +44,7 @@ export class GitHubAddCommentEnhancer implements CommentEnhancer { textarea: HTMLTextAreaElement From a988f11557d3769d1d1b4d9188d315d3fc22105d Mon Sep 17 00:00:00 2001 From: Todd Riley Date: Fri, 5 Sep 2025 13:53:18 -0400 Subject: [PATCH 3/3] Rename GithubAddComment entities to GithubAddPRComment. --- ...thubAddComment.ts => githubPRAddComment.ts} | 18 ++++++++---------- .../lib/enhancers/github/githubSpotTypes.ts | 2 ++ browser-extension/src/lib/registries.ts | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) rename browser-extension/src/lib/enhancers/github/{githubAddComment.ts => githubPRAddComment.ts} (81%) diff --git a/browser-extension/src/lib/enhancers/github/githubAddComment.ts b/browser-extension/src/lib/enhancers/github/githubPRAddComment.ts similarity index 81% rename from browser-extension/src/lib/enhancers/github/githubAddComment.ts rename to browser-extension/src/lib/enhancers/github/githubPRAddComment.ts index d74352f..13aa81d 100644 --- a/browser-extension/src/lib/enhancers/github/githubAddComment.ts +++ b/browser-extension/src/lib/enhancers/github/githubPRAddComment.ts @@ -2,23 +2,21 @@ import OverType, { type OverTypeInstance } from '../../../overtype/overtype' import type { CommentEnhancer, CommentSpot } from '../../enhancer' import { logger } from '../../logger' import { githubHighlighter } from './githubHighlighter' -import { GITHUB_SPOT_TYPES } from './githubSpotTypes' +import { GITHUB_SPOT_TYPES, type GitHubSpotType } from './githubSpotTypes' -type GitHubSpotType = (typeof GITHUB_SPOT_TYPES)[number] - -interface GitHubAddCommentSpot extends CommentSpot { +interface GitHubPRAddCommentSpot extends CommentSpot { type: GitHubSpotType // Override to narrow from string to specific union domain: string slug: string // owner/repo number: number // issue/PR number, undefined for new issues and PRs } -export class GitHubAddCommentEnhancer implements CommentEnhancer { +export class GitHubPRAddCommentEnhancer implements CommentEnhancer { forSpotTypes(): string[] { return [...GITHUB_SPOT_TYPES] } - tryToEnhance(_textarea: HTMLTextAreaElement): GitHubAddCommentSpot | null { + tryToEnhance(_textarea: HTMLTextAreaElement): GitHubPRAddCommentSpot | null { // Only handle github.com domains TODO: identify GitHub Enterprise somehow if (window.location.hostname !== 'github.com') { return null @@ -47,7 +45,7 @@ export class GitHubAddCommentEnhancer implements CommentEnhancer { textarea: HTMLTextAreaElement @@ -15,7 +15,7 @@ export class EnhancerRegistry { constructor() { // Register all available handlers - this.register(new GitHubAddCommentEnhancer()) + this.register(new GitHubPRAddCommentEnhancer()) } private register(handler: CommentEnhancer): void {