diff options
Diffstat (limited to 'source/github-helpers')
-rw-r--r-- | source/github-helpers/dom-formatters.tsx | 6 | ||||
-rw-r--r-- | source/github-helpers/get-current-git-ref.ts | 6 | ||||
-rw-r--r-- | source/github-helpers/get-tab-count.ts | 4 | ||||
-rw-r--r-- | source/github-helpers/get-user-avatar.ts | 4 | ||||
-rw-r--r-- | source/github-helpers/index.ts | 8 | ||||
-rw-r--r-- | source/github-helpers/load-details-menu.ts | 4 | ||||
-rw-r--r-- | source/github-helpers/pr-branches.ts | 6 | ||||
-rw-r--r-- | source/github-helpers/pr-ci-status.ts | 8 |
8 files changed, 23 insertions, 23 deletions
diff --git a/source/github-helpers/dom-formatters.tsx b/source/github-helpers/dom-formatters.tsx index d764498b..ca19d5f7 100644 --- a/source/github-helpers/dom-formatters.tsx +++ b/source/github-helpers/dom-formatters.tsx @@ -1,5 +1,5 @@ import React from 'dom-chef'; -import select from 'select-dom'; +import {$$, elementExists} from 'select-dom'; import zipTextNodes from 'zip-text-nodes'; import {applyToLink} from 'shorten-repo-url'; import linkifyURLsCore from 'linkify-urls'; @@ -68,8 +68,8 @@ export function linkifyURLs(element: Element): Element[] | void { return; } - if (select.exists(linkifiedURLSelector, element)) { - return select.all(linkifiedURLSelector, element); + if (elementExists(linkifiedURLSelector, element)) { + return $$(linkifiedURLSelector, element); } const linkified = linkifyURLsCore(element.textContent, { diff --git a/source/github-helpers/get-current-git-ref.ts b/source/github-helpers/get-current-git-ref.ts index b2d1d1c9..65b9feff 100644 --- a/source/github-helpers/get-current-git-ref.ts +++ b/source/github-helpers/get-current-git-ref.ts @@ -1,5 +1,5 @@ import {isRepoCommitList} from 'github-url-detection'; -import select from 'select-dom'; +import {$} from 'select-dom'; import {extractCurrentBranchFromBranchPicker} from './index.js'; import {branchSelector} from './selectors.js'; @@ -11,7 +11,7 @@ const titleWithGitRef = / at (?<branch>[.\w-/]+)( ยท [\w-]+\/[\w-]+)?$/i; export default function getCurrentGitRef(): string | undefined { // Note: This is not in the <head> so it's only available on AJAXed loads. // It appears on every Code page except `commits` on folders/files - const picker = select(branchSelector); + const picker = $(branchSelector); const refViaPicker = picker && extractCurrentBranchFromBranchPicker(picker); if (refViaPicker) { return refViaPicker; @@ -49,7 +49,7 @@ export function getGitRef(pathname: string, title: string): string | undefined { // In <head>, but not reliable https://github.com/refined-github/refined-github/assets/1402241/50357d94-505f-48dc-bd54-74e86b19d642 function getCurrentBranchFromFeed(): string | undefined { - const feedLink = isRepoCommitList() && select('link[type="application/atom+xml"]'); + const feedLink = isRepoCommitList() && $('link[type="application/atom+xml"]'); if (!feedLink) { // Do not throw errors, the element may be missing after AJAX navigation even if on the right page return; diff --git a/source/github-helpers/get-tab-count.ts b/source/github-helpers/get-tab-count.ts index c7658395..af7a18a4 100644 --- a/source/github-helpers/get-tab-count.ts +++ b/source/github-helpers/get-tab-count.ts @@ -1,8 +1,8 @@ -import select from 'select-dom'; +import {$} from 'select-dom'; import oneMutation from 'one-mutation'; export default async function getTabCount(tab: Element): Promise<number> { - const counter = select('.Counter, .num', tab); + const counter = $('.Counter, .num', tab); if (!counter) { // GitHub might have already dropped the counter, which means it's 0 return 0; diff --git a/source/github-helpers/get-user-avatar.ts b/source/github-helpers/get-user-avatar.ts index 510066e2..e61b2e81 100644 --- a/source/github-helpers/get-user-avatar.ts +++ b/source/github-helpers/get-user-avatar.ts @@ -1,11 +1,11 @@ -import select from 'select-dom'; +import {$} from 'select-dom'; import * as pageDetect from 'github-url-detection'; export default function getUserAvatar(username: string, size: number): string | void { const cleanName = username.replace('[bot]', ''); // Find image on page. Saves a request and a redirect + add support for bots - const existingAvatar = select(`img[alt="@${cleanName}"]`); + const existingAvatar = $(`img[alt="@${cleanName}"]`); if (existingAvatar) { return existingAvatar.src; } diff --git a/source/github-helpers/index.ts b/source/github-helpers/index.ts index b9e4e673..051d4b02 100644 --- a/source/github-helpers/index.ts +++ b/source/github-helpers/index.ts @@ -1,4 +1,4 @@ -import select from 'select-dom'; +import {$, elementExists} from 'select-dom'; import onetime from 'onetime'; import elementReady from 'element-ready'; import compareVersions from 'tiny-version-compare'; @@ -37,7 +37,7 @@ export function buildRepoURL<S extends string>(...pathParts: RequireAtLeastOne<A } export function getForkedRepo(): string | undefined { - return select('meta[name="octolytics-dimension-repository_parent_nwo"]')?.content; + return $('meta[name="octolytics-dimension-repository_parent_nwo"]')?.content; } export function parseTag(tag: string): {version: string; namespace: string} { @@ -92,7 +92,7 @@ export const isPermalink = mem(async () => { } // Awaiting only the branch selector means it resolves early even if the icon tag doesn't exist, whereas awaiting the icon tag would wait for the DOM ready event before resolving. - return select.exists( + return elementExists( '.octicon-tag', // Tags have an icon await elementReady(branchSelector), ); @@ -118,7 +118,7 @@ export async function isArchivedRepoAsync(): Promise<boolean> { return pageDetect.isArchivedRepo(); } -export const userCanLikelyMergePR = (): boolean => select.exists('.discussion-sidebar-item .octicon-lock'); +export const userCanLikelyMergePR = (): boolean => elementExists('.discussion-sidebar-item .octicon-lock'); export const cacheByRepo = (): string => getRepo()!.nameWithOwner; diff --git a/source/github-helpers/load-details-menu.ts b/source/github-helpers/load-details-menu.ts index f3db3d42..13158676 100644 --- a/source/github-helpers/load-details-menu.ts +++ b/source/github-helpers/load-details-menu.ts @@ -1,8 +1,8 @@ -import select from 'select-dom'; +import {$} from 'select-dom'; import oneEvent from 'one-event'; export default async function loadDetailsMenu(detailsMenu: HTMLElement): Promise<void> { - const fragment = select('.js-comment-header-actions-deferred-include-fragment', detailsMenu); + const fragment = $('.js-comment-header-actions-deferred-include-fragment', detailsMenu); if (!fragment) { return; } diff --git a/source/github-helpers/pr-branches.ts b/source/github-helpers/pr-branches.ts index a2105bc8..38747679 100644 --- a/source/github-helpers/pr-branches.ts +++ b/source/github-helpers/pr-branches.ts @@ -1,4 +1,4 @@ -import select from 'select-dom'; +import {$} from 'select-dom'; export type PrReference = { /** @example fregante/mem:main */ @@ -59,10 +59,10 @@ function parseReference(referenceElement: HTMLElement): PrReference { export function getBranches(): {base: PrReference; head: PrReference} { return { get base() { - return parseReference(select('.base-ref')!); + return parseReference($('.base-ref')!); }, get head() { - return parseReference(select('.head-ref')!); + return parseReference($('.head-ref')!); }, }; } diff --git a/source/github-helpers/pr-ci-status.ts b/source/github-helpers/pr-ci-status.ts index d1c4a970..31e074fc 100644 --- a/source/github-helpers/pr-ci-status.ts +++ b/source/github-helpers/pr-ci-status.ts @@ -1,4 +1,4 @@ -import select from 'select-dom'; +import {$, lastElement} from 'select-dom'; import api from './api.js'; import {prCommit, prCommitStatusIcon} from './selectors.js'; @@ -9,13 +9,13 @@ export const PENDING = Symbol('Pending'); export type CommitStatus = false | typeof SUCCESS | typeof FAILURE | typeof PENDING; export function getLastCommitReference(): string { - return select.last(`${prCommit} code`)!.textContent; + return lastElement(`${prCommit} code`)!.textContent; } export function getLastCommitStatus(): CommitStatus { // Select the last commit first, THEN pick the icon, otherwise it might pick non-last commit while the CI is starting up - const lastCommit = select.last(prCommit)!; - const lastCommitStatusIcon = select(prCommitStatusIcon, lastCommit); + const lastCommit = lastElement(prCommit)!; + const lastCommitStatusIcon = $(prCommitStatusIcon, lastCommit); // Some commits don't have a CI status icon at all if (lastCommitStatusIcon) { |