Skip to content

Commit 9ef3a37

Browse files
authored
Restore isOrganizationRepo (#176)
1 parent aef4af0 commit 9ef3a37

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import reservedNames from 'github-reserved-names/reserved-names.json';
22
import {addTests} from './collector.js';
33

4-
const $ = (selector: string) => document.querySelector(selector);
4+
const $ = <E extends Element>(selector: string) => document.querySelector<E>(selector);
55
const exists = (selector: string) => Boolean($(selector));
66

77
const combinedTestOnly = ['combinedTestOnly']; // To be used only to skip tests of combined functions, i.e. isPageA() || isPageB()
@@ -183,7 +183,7 @@ addTests('isNotifications', [
183183

184184
export const isOrganizationProfile = (): boolean => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
185185

186-
export const isOrganizationRepo = (): boolean => Boolean(document.querySelector<HTMLElement>('[data-owner-scoped-search-url]')?.dataset['ownerScopedSearchUrl']!.startsWith('/org'));
186+
export const isOrganizationRepo = (): boolean => exists('.AppHeader-context-full [data-hovercard-type="organization"]');
187187

188188
export const isTeamDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => Boolean(getOrg(url)?.path.startsWith('teams'));
189189
addTests('isTeamDiscussion', [
@@ -725,7 +725,7 @@ addTests('isNewRepoTemplate', [
725725
]);
726726

727727
/** Get the logged-in user’s username */
728-
const getUsername = (): string | undefined => document.querySelector('meta[name="user-login"]')?.getAttribute('content')!;
728+
const getUsername = (): string | undefined => $('meta[name="user-login"]')?.getAttribute('content')!;
729729

730730
/** Drop all duplicate slashes */
731731
const getCleanPathname = (url: URL | HTMLAnchorElement | Location = location): string => url.pathname.replace(/\/+/g, '/').slice(1, url.pathname.endsWith('/') ? -1 : undefined);
@@ -767,7 +767,7 @@ const getRepo = (url?: URL | HTMLAnchorElement | Location | string): RepositoryI
767767
if (!url) {
768768
// We use `canonical` here to use the correct capitalization
769769
// `rel=canonical` doesn't appear on every page
770-
const canonical = document.querySelector<HTMLMetaElement>('[property="og:url"]');
770+
const canonical = $<HTMLMetaElement>('[property="og:url"]');
771771
if (canonical) {
772772
const canonicalUrl = new URL(canonical.content, location.origin);
773773
// Sometimes GitHub sets the canonical to an incomplete URL, so it can't be used

0 commit comments

Comments
 (0)