davidfou / conventionalcomments-web-extension

GNU General Public License v3.0
13 stars 5 forks source link

Fix GHES by selecting the comment form action bar #23

Closed colindean closed 1 week ago

colindean commented 1 week ago

…directly instead of finding the parent of the slash-command-toolbar-button — which doesn't exist on GHES, apparently. That parent would simply be the action-bar element!

This should fix GitHub Enterprise usage of the extension on GHES 3.13+.

colindean commented 1 week ago

Just in case my cleanup broke something, here's the patch from immediately after working session before that cleanup:

diff --git a/src/contentScript/commentEditorExtractors/githubCommentEditorExtractorV2.ts b/src/contentScript/commentEditorExtractors/githubCommentEditorExtractorV2.ts
index e92580c..85a76a5 100644
--- a/src/contentScript/commentEditorExtractors/githubCommentEditorExtractorV2.ts
+++ b/src/contentScript/commentEditorExtractors/githubCommentEditorExtractorV2.ts
@@ -45,16 +45,17 @@ const githubCommentEditorExtractor: CommentEditorExtractor = (
         if (mainEl === null) {
           return;
         }
-        const buttonAnchorEl = mainEl.querySelector(
-          "markdown-toolbar slash-command-toolbar-button"
-        );
+        // const buttonAnchorEl = mainEl.querySelector(
+        //  "markdown-toolbar slash-command-toolbar-button"
+        // );
         const editorAnchorEl = mainEl.querySelector("file-attachment");
-        if (buttonAnchorEl === null || editorAnchorEl === null) {
+        if (editorAnchorEl === null ) {
           return;
         }

-        const buttonTargetEl = buttonAnchorEl.parentElement;
+        // const buttonTargetEl = buttonAnchorEl.parentElement;
         const editorTargetEl = editorAnchorEl.parentElement;
+        const buttonTargetEl = mainEl.querySelector("action-bar .ActionBar-item-container");
         if (buttonTargetEl === null || editorTargetEl === null) {
           return;
         }
@@ -66,12 +67,12 @@ const githubCommentEditorExtractor: CommentEditorExtractor = (
           isMainComment: textarea.closest(".review-thread-reply") === null,
           textarea,
           buttonParams: {
-            target: buttonTargetEl,
-            anchor: buttonAnchorEl,
+            target: buttonTargetEl
+            // anchor: buttonAnchorEl,
           },
           editorParams: {
             target: editorTargetEl,
-            anchor: editorAnchorEl,
+            anchor: editorAnchorEl
           },
           productType: "github-v2",
         });
davidfou commented 1 week ago

Fixes #21