From 88e2668dbc0fbdd7c78af2747c1f022309289eea Mon Sep 17 00:00:00 2001
From: Federico Brigante <me@fregante.com>
Date: Tue, 5 Jul 2022 23:26:44 +0700
Subject: Add `has()` selector helper (#5518)

---
 source/features/one-click-pr-or-gist.tsx | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

(limited to 'source/features/one-click-pr-or-gist.tsx')

diff --git a/source/features/one-click-pr-or-gist.tsx b/source/features/one-click-pr-or-gist.tsx
index 9762a064..6d7cfd0a 100644
--- a/source/features/one-click-pr-or-gist.tsx
+++ b/source/features/one-click-pr-or-gist.tsx
@@ -4,17 +4,16 @@ import select from 'select-dom';
 import * as pageDetect from 'github-url-detection';
 
 import features from '.';
+import selectHas from '../helpers/select-has';
 
 function init(): void | false {
-	const draftPROption = select('.new-pr-form [name="draft"], #new_gist [name="gist[public]"]');
-	if (!draftPROption) {
+	const initialGroupedButtons = selectHas('.BtnGroup:has([name="draft"], [name="gist[public]"])');
+	if (!initialGroupedButtons) {
 		// 1. Free accounts can't open Draft PRs in private repos, so this element is missing
 		// 2. PRs can't be created from some comparison pages: Either base is a tag, not a branch; or there already exists a PR.
 		return false;
 	}
 
-	const initialGroupedButtons = draftPROption.closest('.BtnGroup')!;
-
 	for (const dropdownItem of select.all('.select-menu-item', initialGroupedButtons)) {
 		let title = select('.select-menu-item-heading', dropdownItem)!.textContent!.trim();
 		const description = select('.description', dropdownItem)!.textContent!.trim();
-- 
cgit v1.2.3

