Files
Oliver Dunk 5bf419b385 Reorganize directory structure (#825)
* Remove docs folder.

This was a redirect from a GitHub pages site that does not appear
to be in use.

* Rename api folder to api-samples.

* Move examples to functional-samples folder.

* Move cookbook sample to functional-samples.

* Move tutorials to functional-samples folder.

* Move mv2 and apps folders to _archive.

* Rename tools folder to .repo.

* Move reference folder to functional-samples.

* Update README.

Update README with new relative links for reorg.

* Update README.md

Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>

---------

Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>
2023-02-03 10:58:04 -06:00

50 lines
2.0 KiB
JavaScript

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// To make sure we can uniquely identify each screenshot tab, add an id as a
// query param to the url that displays the screenshot.
// Note: It's OK that this is a global variable (and not in localStorage),
// because the event page will stay open as long as any screenshot tabs are
// open.
var id = 100;
// Listen for a click on the camera icon. On that click, take a screenshot.
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.captureVisibleTab(function(screenshotUrl) {
var viewTabUrl = chrome.extension.getURL('screenshot.html?id=' + id++)
var targetId = null;
chrome.tabs.onUpdated.addListener(function listener(tabId, changedProps) {
// We are waiting for the tab we opened to finish loading.
// Check that the tab's id matches the tab we opened,
// and that the tab is done loading.
if (tabId != targetId || changedProps.status != "complete")
return;
// Passing the above test means this is the event we were waiting for.
// There is nothing we need to do for future onUpdated events, so we
// use removeListner to stop getting called when onUpdated events fire.
chrome.tabs.onUpdated.removeListener(listener);
// Look through all views to find the window which will display
// the screenshot. The url of the tab which will display the
// screenshot includes a query parameter with a unique id, which
// ensures that exactly one view will have the matching URL.
var views = chrome.extension.getViews();
for (var i = 0; i < views.length; i++) {
var view = views[i];
if (view.location.href == viewTabUrl) {
view.setScreenshotUrl(screenshotUrl);
break;
}
}
});
chrome.tabs.create({url: viewTabUrl}, function(tab) {
targetId = tab.id;
});
});
});