summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Florent <cheap.glitch@gmail.com> 2022-01-15 14:15:24 +0100
committerGravatar GitHub <noreply@github.com> 2022-01-15 14:15:24 +0100
commite722aa956243ff84d2058b538ae85d9ecf2ab76b (patch)
treee62845bff7c861084124033c6fa8a803fafb28d6
parent0742544410a67fd36a04ac7bbe329a074ad0c53b (diff)
downloadrefined-github-e722aa956243ff84d2058b538ae85d9ecf2ab76b.tar.gz
refined-github-e722aa956243ff84d2058b538ae85d9ecf2ab76b.tar.zst
refined-github-e722aa956243ff84d2058b538ae85d9ecf2ab76b.zip
Add `prevent-pr-merge-panel-opening` feature (#5296)
-rw-r--r--readme.md1
-rw-r--r--source/features/prevent-pr-merge-panel-opening.tsx33
-rw-r--r--source/refined-github.ts1
3 files changed, 35 insertions, 0 deletions
diff --git a/readme.md b/readme.md
index 3e39735b..28cd2465 100644
--- a/readme.md
+++ b/readme.md
@@ -409,6 +409,7 @@ Thanks for contributing! πŸ¦‹πŸ™Œ
- [](# "same-page-definition-jump") [Avoids re-loading the page when jumping to function definition in the current file.](https://user-images.githubusercontent.com/16872793/90833649-7a5e2f80-e316-11ea-827d-a4e3ac8ced69.png)
- [](# "convert-pr-to-draft-improvements") [Moves the "Convert PR to Draft" button to the mergeability box and adds visual feedback to its confirm button.](https://user-images.githubusercontent.com/1402241/95644892-885f3f80-0a7f-11eb-8428-8e0fb0c8dfa5.gif)
- [](# "clean-header-search-field") [Clears duplicate queries in the header search field.](https://user-images.githubusercontent.com/1402241/114177338-7c890300-9966-11eb-83a3-a711a76fae99.png)
+- [](# "prevent-pr-merge-panel-opening") Prevents the merge panel from automatically opening on every page load after it’s been opened once.
<!-- Refer to style guide above. Keep this message between sections. -->
diff --git a/source/features/prevent-pr-merge-panel-opening.tsx b/source/features/prevent-pr-merge-panel-opening.tsx
new file mode 100644
index 00000000..f78c04d8
--- /dev/null
+++ b/source/features/prevent-pr-merge-panel-opening.tsx
@@ -0,0 +1,33 @@
+import select from 'select-dom';
+import * as pageDetect from 'github-url-detection';
+
+import features from '.';
+
+async function sessionResumeHandler(): Promise<void> {
+ await Promise.resolve(); // The `session:resume` event fires a bit too early
+ const cancelMergeButton = select('.merge-branch-form .js-details-target');
+ if (cancelMergeButton) {
+ cancelMergeButton.click();
+ document.removeEventListener('session:resume', sessionResumeHandler);
+ }
+}
+
+function init(): void {
+ document.addEventListener('session:resume', sessionResumeHandler);
+}
+
+void features.add(import.meta.url, {
+ asLongAs: [
+ // The user is a maintainer, so they can probably merge the PR
+ () => select.exists('.discussion-sidebar-item .octicon-lock'),
+ ],
+ include: [
+ pageDetect.isPRConversation,
+ ],
+ exclude: [
+ () => select.exists('#partial-discussion-header [title="Status: Draft"]'),
+ ],
+ awaitDomReady: false,
+ deduplicate: 'has-rgh-inner',
+ init,
+});
diff --git a/source/refined-github.ts b/source/refined-github.ts
index 75b1699a..f500cfbe 100644
--- a/source/refined-github.ts
+++ b/source/refined-github.ts
@@ -211,3 +211,4 @@ import './features/clean-repo-tabs';
import './features/rgh-welcome-issue';
import './features/hide-repo-badges';
import './features/same-branch-author-commits';
+import './features/prevent-pr-merge-panel-opening';