1 /* Copyright (c) 2014 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. */
5 var ariaDescribedAt
= '';
9 * This is called when the extension is first loaded, so that it can be
10 * immediately used in all already-open tabs. It's not needed for any
11 * new tabs that open after that, the content script will be automatically
12 * injected into any new tab.
14 chrome
.windows
.getAll({'populate': true}, function(windows
) {
15 for (var i
= 0; i
< windows
.length
; i
++) {
16 var tabs
= windows
[i
].tabs
;
17 for (var j
= 0; j
< tabs
.length
; j
++) {
19 chrome
.tabs
.insertCSS(
23 chrome
.runtime
.lastError
;
28 chrome
.tabs
.executeScript(
30 {file
: 'lastRightClick.js'},
32 chrome
.runtime
.lastError
;
41 * Add context menu item when the extension is installed.
43 chrome
.contextMenus
.create({
44 "title": chrome
.i18n
.getMessage('longdesc_context_menu_item'),
47 "onclick": contextMenuClicked
,
52 * Add listener for messages from content script.
53 * Enable/disable the context menu item.
55 chrome
.runtime
.onMessage
.addListener(
56 function (request
, sender
, sendResponse
) {
57 if (request
.enabled
) {
58 ariaDescribedAt
= request
.ariaDescribedAt
;
59 longDesc
= request
.longDesc
;
61 chrome
.contextMenus
.update('moreInfo', {
62 "enabled": request
.enabled
67 * Event handler for when a context menu item is clicked.
68 * aria-describedat is given a higher priority.
69 * No need to strip the URL of leading/trailing white space
70 * because Chrome takes care of this.
75 function contextMenuClicked(info
, tab
) {
76 if (ariaDescribedAt
!== '') {
77 chrome
.tabs
.create({url
: ariaDescribedAt
});
78 } else if (longDesc
!== '') {
79 chrome
.tabs
.create({url
: longDesc
});