OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
1 // To make sure we can uniquely identify each screenshot tab, add an id as a | 5 // To make sure we can uniquely identify each screenshot tab, add an id as a |
2 // query param to the url that displays the screenshot. | 6 // query param to the url that displays the screenshot. |
3 var id = 100; | 7 var id = 100; |
4 | 8 |
5 function takeScreenshot() { | 9 function takeScreenshot() { |
6 chrome.tabs.captureVisibleTab(null, function(img) { | 10 chrome.tabs.captureVisibleTab(null, function(img) { |
7 var screenshotUrl = img; | 11 var screenshotUrl = img; |
8 var viewTabUrl = [chrome.extension.getURL('screenshot.html'), | 12 var viewTabUrl = [chrome.extension.getURL('screenshot.html'), |
9 '?id=', id++].join(''); | 13 '?id=', id++].join(''); |
10 | 14 |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 41 } |
38 }; | 42 }; |
39 chrome.tabs.onUpdated.addListener(addSnapshotImageToTab); | 43 chrome.tabs.onUpdated.addListener(addSnapshotImageToTab); |
40 | 44 |
41 }); | 45 }); |
42 }); | 46 }); |
43 } | 47 } |
44 | 48 |
45 // Listen for a click on the camera icon. On that click, take a screenshot. | 49 // Listen for a click on the camera icon. On that click, take a screenshot. |
46 chrome.browserAction.onClicked.addListener(function(tab) { | 50 chrome.browserAction.onClicked.addListener(function(tab) { |
47 takeScreenshot(); | 51 if (tab.url.match(/code.google.com/)) { |
| 52 takeScreenshot(); |
| 53 } else { |
| 54 alert('This sample can only take screenshots of code.google.com pages'); |
| 55 } |
48 }); | 56 }); |
OLD | NEW |