Browse Source

Improve diff detection

This fixes some things on pages displaying diffs by improving the detection of diffs
and exposing a single method to check if the page has a diff.

- Compare pages now have a detection as well:
  Use pageDetect.isCompare() to detect: /<owner>/<repo>/compare/<revision-range>

- Exposed a new simple pageDetect.hasDiff() method to detect if there is a diff on a page.
  It combines commits, PR diffs, compare pages etc.

- Diff signs are now removed on compare pages as well.
master
Haralan Dobrev 8 years ago
committed by Haralan Dobrev
parent
commit
541231bb41
  1. 2
      extension/content.js
  2. 6
      extension/page-detect.js

2
extension/content.js

@ -383,7 +383,7 @@ document.addEventListener('DOMContentLoaded', () => {
addPatchDiffLinks();
}
if (pageDetect.isCommit() || pageDetect.isPR() || pageDetect.isPRFiles()) {
if (pageDetect.hasDiff()) {
removeDiffSigns();
}

6
extension/page-detect.js

@ -29,6 +29,10 @@ window.pageDetect = (() => {
const isCommit = () => isSingleCommit() || isPRCommit() || (isPRFiles() && $('.full-commit').length > 0);
const isCompare = () => isRepo() && /^\/compare\//.test(getRepoPath());
const hasDiff = () => isRepo() && (isSingleCommit() || isPRCommit() || isPRFiles() || isCompare() || (isPR() && $('.diff-table').length > 0));
const isReleases = () => isRepo() && /^\/(releases|tags)/.test(getRepoPath());
const isBlame = () => isRepo() && /^\/blame\//.test(getRepoPath());
@ -65,6 +69,8 @@ window.pageDetect = (() => {
isCommitList,
isSingleCommit,
isCommit,
isCompare,
hasDiff,
isReleases,
isBlame,
isNotifications,

Loading…
Cancel
Save