|
1 | 1 | import reservedNames from 'github-reserved-names/reserved-names.json';
|
2 | 2 | import {addTests} from './collector.js';
|
3 | 3 |
|
4 |
| -const $ = (selector: string) => document.querySelector(selector); |
| 4 | +const $ = <E extends Element>(selector: string) => document.querySelector<E>(selector); |
5 | 5 | const exists = (selector: string) => Boolean($(selector));
|
6 | 6 |
|
7 | 7 | const combinedTestOnly = ['combinedTestOnly']; // To be used only to skip tests of combined functions, i.e. isPageA() || isPageB()
|
@@ -183,7 +183,7 @@ addTests('isNotifications', [
|
183 | 183 |
|
184 | 184 | export const isOrganizationProfile = (): boolean => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
|
185 | 185 |
|
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"]'); |
187 | 187 |
|
188 | 188 | export const isTeamDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => Boolean(getOrg(url)?.path.startsWith('teams'));
|
189 | 189 | addTests('isTeamDiscussion', [
|
@@ -725,7 +725,7 @@ addTests('isNewRepoTemplate', [
|
725 | 725 | ]);
|
726 | 726 |
|
727 | 727 | /** 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')!; |
729 | 729 |
|
730 | 730 | /** Drop all duplicate slashes */
|
731 | 731 | 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
|
767 | 767 | if (!url) {
|
768 | 768 | // We use `canonical` here to use the correct capitalization
|
769 | 769 | // `rel=canonical` doesn't appear on every page
|
770 |
| - const canonical = document.querySelector<HTMLMetaElement>('[property="og:url"]'); |
| 770 | + const canonical = $<HTMLMetaElement>('[property="og:url"]'); |
771 | 771 | if (canonical) {
|
772 | 772 | const canonicalUrl = new URL(canonical.content, location.origin);
|
773 | 773 | // Sometimes GitHub sets the canonical to an incomplete URL, so it can't be used
|
|
0 commit comments