From 541231bb41ffda832ac14382d1e41bb8ca25bf54 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Mon, 24 Oct 2016 21:25:28 +0300 Subject: [PATCH] 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: ///compare/ - 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. --- extension/content.js | 2 +- extension/page-detect.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/extension/content.js b/extension/content.js index 8f6311c..db431c4 100644 --- a/extension/content.js +++ b/extension/content.js @@ -383,7 +383,7 @@ document.addEventListener('DOMContentLoaded', () => { addPatchDiffLinks(); } - if (pageDetect.isCommit() || pageDetect.isPR() || pageDetect.isPRFiles()) { + if (pageDetect.hasDiff()) { removeDiffSigns(); } diff --git a/extension/page-detect.js b/extension/page-detect.js index 99e8c9e..cd412cb 100644 --- a/extension/page-detect.js +++ b/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,