-
Notifications
You must be signed in to change notification settings - Fork 3
/
background.js
44 lines (39 loc) · 1.31 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Five varieties of code review URLs:
// 1) http://codereview.chromium.org/###/
// 2) http://chromiumcodereview.appspot.com/###/
// 3) http://chromereviews.googleplex.com/###/
// 4) http://webrtc-codereview.appspot.com/###/
// 5) http://review.webrtc.org/###/
var regexps = [
/^https?:\/\/codereview\.chromium\.org\/[0-9]+\/?$/,
/^https?:\/\/chromiumcodereview\.appspot\.com\/[0-9]+\/?$/,
/^https?:\/\/chromereviews\.googleplex\.com\/[0-9]+\/?$/,
/^https?:\/\/webrtc-codereview\.appspot\.com\/[0-9]+\/?$/,
/^https?:\/\/review\.webrtc\.org\/[0-9]+\/?$/
];
function isRietveldUrl(tabId, changeInfo, tab) {
for (var i = 0; i < regexps.length; ++i) {
if (regexps[i].test(tab.url)) {
chrome.pageAction.show(tabId);
return;
}
}
}
// Injects script to grab the side-by-side diff URLs from the DOM.
function getDiffs(tab) {
chrome.tabs.executeScript(tab.id, { file:'inject.js' });
}
// Opens all |urls| next to the current tab.
function openDiffs(urls, sender) {
console.log(urls);
for (var i = 0; i < urls.length; ++i) {
chrome.tabs.create({
url: urls[i],
index: (sender.tab.index + 1 + i),
active: false
});
}
}
chrome.tabs.onUpdated.addListener(isRietveldUrl);
chrome.pageAction.onClicked.addListener(getDiffs);
chrome.extension.onMessage.addListener(openDiffs);