Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ distribution
dist
.cache
.parcel-cache
.vscode/
32 changes: 32 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import reservedNames from 'github-reserved-names/reserved-names.json' with {type: 'json'};
import {addTests} from './collector.js';

const $ = <E extends Element>(selector: string) => document.querySelector<E>(selector);

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStarsList NO https://github.com/stars/lstn/lists/test

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ isOwnStarsList index.ts:845:96 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStarsList NO https://github.com/stars/lstn/topics

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ isOwnStarsList index.ts:845:96 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStarsList NO https://github.com/stars/lstn/repositories

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ isOwnStarsList index.ts:845:96 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStarsList NO https://github.com/stars/lstn

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ isOwnStarsList index.ts:845:96 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStarsList NO https://github.com/stars

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ isOwnStarsList index.ts:845:96 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStars NO https://github.com/stars/lstn/lists/test

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStars NO https://github.com/stars/lstn/topics

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStars NO https://github.com/stars/lstn/repositories

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStars NO https://github.com/stars/lstn

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ index.test.ts:59:6

Check failure on line 4 in index.ts

View workflow job for this annotation

GitHub Actions / Test

index.test.ts > isOwnStars NO https://github.com/stars

TypeError: document.querySelector is not a function ❯ $ index.ts:4:61 ❯ getLoggedInUser index.ts:867:51 ❯ isOwnStars index.ts:835:27 ❯ index.test.ts:59:6
const exists = (selector: string) => Boolean($(selector));

const combinedTestOnly = ['combinedTestOnly']; // To be used only to skip tests of combined functions, i.e. isPageA() || isPageB()
Expand Down Expand Up @@ -812,6 +812,38 @@
'https://github.com/refined-github/github-url-detection/actions/workflows/esm-lint.yml',
]);

const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => {
const patharr = getCleanPathname(url).split('/');
const [stars, , subpath] = patharr; // Only get the elements we're only to check from destructuring to avoid compile error
return Boolean(stars === 'stars'
&& ([1, 2, 4].includes(patharr.length)
|| (subpath === 'lists' && patharr.length !== 3)
|| (subpath && ['repositories', 'topics'].includes(subpath) && patharr.length === 3)),
);
};

TEST: addTests('isStars', [
'https://github.com/stars',
'https://github.com/stars/lstn',
'https://github.com/stars/lstn/repositories',
'https://github.com/stars/lstn/topics',
'https://github.com/stars/lstn/lists/test',
]);

export const isOwnStars = (url: URL | HTMLAnchorElement | Location = location): boolean =>
isStars(url)
&& [['stars'], ['stars', getLoggedInUser()]].some(
(needle => pathArray => pathArray.length === needle.length
&& pathArray.every((v, i) => v === needle[i]))(getCleanPathname(url).split('/').slice(0, 2)),
);

export const isStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isStars(url) && getCleanPathname(url).split('/')[2] === 'lists';
TEST: addTests('isStarsList', [
'https://github.com/stars/lstn/lists/test',
]);

export const isOwnStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isOwnStars(url) && getCleanPathname(url).split('/')[2] === 'lists';

export const isUserTheOrganizationOwner = (): boolean => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');

export const canUserAdminRepo = (): boolean => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
Expand Down