diff --git a/github.com.js b/github.com.js index f3c1d0b..4243705 100644 --- a/github.com.js +++ b/github.com.js @@ -7,11 +7,16 @@ var repositoryName; var repositoryAuthor; var autoCollapseExpressions; +function onFilesPage() { + return window.location.href.indexOf('files') !== -1; +} + function htmlIsInjected() { return $('.pretty-pull-requests-inserted').length > 0; } function injectHtml() { + if (!onFilesPage()) return; $('' + '' + '' + @@ -141,7 +146,8 @@ function initDiffs() { autoCollapse(); } -function clickTitle() { +function clickTitle(e) { + e.preventDefault(); // Prevent focusing on the file name var path = $(this).attr('title'); var id = getId(path); @@ -163,23 +169,28 @@ function autoCollapse() { } chrome.storage.sync.get({url: '', saveCollapsedDiffs: true, tabSwitchingEnabled: false, autoCollapseExpressions: []}, function(items) { - if (items.url == window.location.origin || + if (items.url === window.location.origin || "https://github.com" === window.location.origin) { autoCollapseExpressions = items.autoCollapseExpressions; + var interval = null; var injectHtmlIfNecessary = function () { if (!htmlIsInjected()) { - collectUniquePageInfo(); - injectHtml(); - initDiffs(); - $body.on('click', '.file-info .link-gray-dark', clickTitle); - $body.on('click', '.bottom-collapse', clickCollapse); - $body.on('click', '.js-collapse-additions', collapseAdditions); - $body.on('click', '.js-collapse-deletions', collapseDeletions); + if (onFilesPage()) { + collectUniquePageInfo(); + injectHtml(); + initDiffs(); + $body.on('click', '.file-info .link-gray-dark', clickTitle); + $body.on('click', '.bottom-collapse', clickCollapse); + $body.on('click', '.js-collapse-additions', collapseAdditions); + $body.on('click', '.js-collapse-deletions', collapseDeletions); + } + } else { + clearInterval(interval); } - setTimeout(injectHtmlIfNecessary, 1000); }; + interval = setInterval(injectHtmlIfNecessary, 1000); var $body = $('body'); useLocalStorage = items.saveCollapsedDiffs; diff --git a/manifest.json b/manifest.json index 0dc9faa..e37d7ea 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Pretty Pull Requests (Github)", "description": "This extension applies various tweaks to the github pull-request code review pages.", - "version": "2.10.3", + "version": "2.11.0", "icons": { "32": "ppr-logo/32x32.png", "64": "ppr-logo/64x64.png", @@ -19,16 +19,7 @@ "content_scripts": [ { - "matches": ["https://github.com/*/pull/*/files", - "https://github.com/*/commit*", - "https://github.com/*/pulls*", - "https://github.com/*/compare*", - "https://github.com/*/*/pulls*", - "https://github.com/*/*/pull/*", - "https://github.com/*/*/pull/*/files", - "https://github.com/*/*/commit*", - "https://github.com/*/*/compare*" - ], + "matches": ["https://github.com/*"], "js": ["jquery-1.9.1.min.js", "github.com.js"], "css": ["pullrequest.css"] }