Skip to content
Merged
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
3 changes: 3 additions & 0 deletions source/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ window.select = select;

async function init() {
await safeElementReady('body');
if (pageDetect.is404() || pageDetect.is500()) {
return;
}
if (document.body.classList.contains('logged-out')) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion source/libs/page-detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const getOwnerAndRepo = () => {
return {ownerName, repoName};
};

export const is404 = () => document.title.startsWith('Page not found');
export const is404 = () => document.title === 'Page not found · GitHub';

export const is500 = () => document.title === 'Server Error · GitHub';

export const isBlame = () => /^blame\//.test(getRepoPath());

Expand Down
19 changes: 18 additions & 1 deletion test/page-detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,31 @@ test('getOwnerAndRepo', t => {
});

test('is404', t => {
document.title = 'Page not found GitHub';
document.title = 'Page not found · GitHub';
t.true(pageDetect.is404());

document.title = 'examples/404: Page not found examples';
t.false(pageDetect.is404());

document.title = 'Dashboard';
t.false(pageDetect.is404());

document.title = 'Page not found · Issue #266 · sintaxi/surge · GitHub';
t.false(pageDetect.is404());
});

test('is500', t => {
document.title = 'Server Error · GitHub';
t.true(pageDetect.is500());

document.title = 'examples/500: Server Error examples';
t.false(pageDetect.is500());

document.title = 'Dashboard';
t.false(pageDetect.is500());

document.title = 'Server Error · Issue #266 · sintaxi/surge · GitHub';
t.false(pageDetect.is500());
});

test('isBlame', urlMatcherMacro, pageDetect.isBlame, [
Expand Down