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.
9 function setRadio(name, value) {
10 var radios = document.querySelectorAll('input[name="' + name + '"]');
11 for (var i = 0; i < radios.length; i++) {
12 radios[i].checked = (radios[i].value == value);
13 radios[i].disabled = !getEnabled();
18 document.body.className = getEnabled() ? '' : 'disabled';
21 $('title').innerText = chrome.i18n.getMessage('highcontrast_enabled');
22 $('toggle').innerHTML =
23 '<b>' + chrome.i18n.getMessage('highcontrast_disable') + '</b><br>' +
24 '<span class="kb">(' + key1 + ')</span>';
25 $('subcontrols').style.display = 'block';
27 $('title').innerText = chrome.i18n.getMessage('highcontrast_disabled');
28 $('toggle').innerHTML =
29 '<b>' + chrome.i18n.getMessage('highcontrast_enable') + '</b><br>' +
30 '<span class="kb">(' + key1 + ')</span>';
31 $('subcontrols').style.display = 'none';
34 setRadio('keyaction', getKeyAction());
36 setRadio('scheme', getSiteScheme(site));
37 $('make_default').disabled = (getSiteScheme(site) == getDefaultScheme());
39 setRadio('scheme', getDefaultScheme());
42 document.documentElement.setAttribute(
44 site ? 'a' + getSiteScheme(site) : 'a' + getDefaultScheme());
46 document.documentElement.setAttribute('hc', 'a0');
48 chrome.extension.getBackgroundPage().updateTabs();
52 setEnabled(!getEnabled());
61 function onRadioChange(name, value) {
71 setSiteScheme(site, value);
73 setDefaultScheme(value);
80 function onMakeDefault() {
81 setDefaultScheme(getSiteScheme(site));
85 function addRadioListeners(name) {
86 var radios = document.querySelectorAll('input[name="' + name + '"]');
87 for (var i = 0; i < radios.length; i++) {
88 radios[i].addEventListener('change', function(evt) {
89 onRadioChange(evt.target.name, evt.target.value);
91 radios[i].addEventListener('click', function(evt) {
92 onRadioChange(evt.target.name, evt.target.value);
98 var i18nElements = document.querySelectorAll('*[i18n-content]');
99 for (var i = 0; i < i18nElements.length; i++) {
100 var elem = i18nElements[i];
101 var msg = elem.getAttribute('i18n-content');
102 elem.innerHTML = chrome.i18n.getMessage(msg);
105 addRadioListeners('keyaction');
106 addRadioListeners('apply');
107 addRadioListeners('scheme');
108 $('toggle').addEventListener('click', onToggle, false);
109 $('make_default').addEventListener('click', onMakeDefault, false);
110 $('forget').addEventListener('click', onForget, false);
111 if (navigator.appVersion.indexOf('Mac') != -1) {
112 key1 = '⌘+Shift+F11';
113 key2 = '⌘+Shift+F12';
119 chrome.windows.getLastFocused({'populate': true}, function(window) {
120 for (var i = 0; i < window.tabs.length; i++) {
121 var tab = window.tabs[i];
123 if (isDisallowedUrl(tab.url)) {
124 $('scheme_title').innerText =
125 chrome.i18n.getMessage('highcontrast_default');
126 $('make_default').style.display = 'none';
128 site = siteFromUrl(tab.url);
129 $('scheme_title').innerHTML =
130 chrome.i18n.getMessage('highcontrast_',
131 '<b>' + site + '</b>:<br>' +
132 '<span class="kb">(' + key2 + ')</span>');
133 $('make_default').style.display = 'block';
139 site = 'unknown site';
144 window.addEventListener('load', init, false);