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 function injectContentScripts() {
6 chrome.windows.getAll({'populate': true}, function(windows) {
7 for (var i = 0; i < windows.length; i++) {
8 var tabs = windows[i].tabs;
9 for (var j = 0; j < tabs.length; j++) {
10 var url = tabs[j].url;
11 if (url.indexOf('chrome') == 0 || url.indexOf('about') == 0) {
14 chrome.tabs.insertCSS(
16 {file: 'highcontrast.css', allFrames: true});
17 chrome.tabs.executeScript(
19 {file: 'highcontrast.js', allFrames: true});
25 function updateTabs() {
27 'enabled': getEnabled()
29 chrome.windows.getAll({'populate': true}, function(windows) {
30 for (var i = 0; i < windows.length; i++) {
31 var tabs = windows[i].tabs;
32 for (var j = 0; j < tabs.length; j++) {
33 var url = tabs[j].url;
34 if (isDisallowedUrl(url)) {
38 'enabled': getEnabled(),
39 'scheme': getSiteScheme(siteFromUrl(url))
41 chrome.tabs.sendRequest(tabs[j].id, msg);
47 function toggleEnabled() {
48 setEnabled(!getEnabled());
52 function toggleSite(url) {
53 var site = siteFromUrl(url);
54 var scheme = getSiteScheme(site);
57 } else if (getDefaultScheme() > 0) {
58 scheme = getDefaultScheme();
60 scheme = DEFAULT_SCHEME;
62 setSiteScheme(site, scheme);
67 injectContentScripts();
70 chrome.extension.onRequest.addListener(
71 function(request, sender, sendResponse) {
72 if (request['toggle_global']) {
75 if (request['toggle_site']) {
76 toggleSite(sender.tab ? sender.tab.url : 'www.example.com');
78 if (request['init']) {
79 var scheme = getDefaultScheme();
81 scheme = getSiteScheme(siteFromUrl(sender.tab.url));
84 'enabled': getEnabled(),
91 document.addEventListener('storage', function(evt) {
95 if (navigator.appVersion.indexOf('Mac') != -1) {
96 chrome.browserAction.setTitle({'title': 'High Contrast (Cmd+Shift+F11)'});