Skip to content

Commit 1c47d12

Browse files
authored
Add isFile404 (#183)
1 parent 78263b6 commit 1c47d12

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ addTests('isFileFinder', [
528528
'https://github.com/sindresorhus/refined-github/find/master',
529529
]);
530530

531+
/**
532+
* @example https://github.com/fregante/GhostText/tree/3cacd7df71b097dc525d99c7aa2f54d31b02fcc8/chrome/scripts/InputArea
533+
* @example https://github.com/refined-github/refined-github/blob/some-non-existent-ref/source/features/bugs-tab.tsx
534+
*/
535+
export const isRepoFile404 = (url: URL | HTMLAnchorElement | Location = location): boolean => (isSingleFile(url) || isRepoTree(url)) && document.title.startsWith('File not found');
536+
531537
export const isRepoForksList = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'network/members';
532538
addTests('isRepoForksList', [
533539
'https://github.com/sindresorhus/refined-github/network/members',

test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ test('isPRFile404', t => {
129129
t.false(pageDetect.isPRFile404());
130130
});
131131

132+
test('isRepoFile404', t => {
133+
document.title = 'File not found';
134+
location.href = 'https://github.com/fregante/GhostText/tree/3cacd7df71b097dc525d99c7aa2f54d31b02fcc8/chrome/scripts/InputArea';
135+
t.true(pageDetect.isRepoFile404());
136+
137+
document.title = 'File not found';
138+
location.href = 'https://github.com/refined-github/refined-github/blob/some-non-existent-ref/source/features/bugs-tab.tsx';
139+
t.true(pageDetect.isRepoFile404());
140+
});
141+
132142
const {getRepositoryInfo} = pageDetect.utils;
133143
test('getRepositoryInfo', t => {
134144
const inputTypes = [

0 commit comments

Comments
 (0)