Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 Google Inc. 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 | |
| 5 // Initialize the page. | |
| 6 function init() { | |
| 7 // Load internationalized strings. | |
| 8 var all = document.getElementsByTagName('*'); | |
|
ojan
2016/09/15 19:07:15
ditto
Pam (message me for reviews)
2016/09/16 16:35:13
Done -- and moved into common.js.
| |
| 9 for (var i = 0; i < all.length; ++i) { | |
| 10 var i18n = all[i].getAttribute('i18n'); | |
| 11 if (i18n) | |
| 12 all[i].textContent = chrome.i18n.getMessage(i18n); | |
| 13 } | |
| 14 | |
| 15 var blacklist = document.getElementById('blacklist'); | |
| 16 var checkbox = document.getElementById('disableInApplets'); | |
| 17 var whitelist = document.getElementById('whitelist'); | |
| 18 | |
| 19 // Configure the textboxes, allowing 200 characters for JSON serialization | |
| 20 // and key length. | |
| 21 blacklist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; | |
| 22 whitelist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; | |
| 23 | |
| 24 // Set event handlers. | |
| 25 document.getElementById('done_button').onclick = function() { | |
| 26 chrome.storage.sync.set({ | |
| 27 // Split the lists into arrays at whitespace before saving. | |
| 28 blacklist: | |
| 29 document.getElementById('blacklist').value.split(/\s+/), | |
| 30 disableInApplets: document.getElementById('disableInApplets').checked, | |
| 31 whitelist: | |
| 32 document.getElementById('whitelist').value.split(/\s+/) | |
| 33 }, function() { | |
| 34 // One easy way to force an error for testing is to change "sync" to | |
| 35 // "managed" in the chrome.storage.sync.set() call above. | |
| 36 if (chrome.runtime.lastError) { | |
| 37 document.getElementById('error').textContent = | |
| 38 chrome.i18n.getMessage('errorSaving', | |
| 39 chrome.runtime.lastError.message); | |
| 40 } else { | |
| 41 window.close(); | |
| 42 } | |
| 43 }); | |
| 44 }; | |
| 45 | |
| 46 document.getElementById('cancel_button').onclick = function() { | |
| 47 window.close(); | |
| 48 }; | |
| 49 | |
| 50 document.getElementById('report_page').onclick = function() { | |
| 51 reportPage(); | |
| 52 }; | |
| 53 | |
| 54 // Load saved settings into the form fields. | |
| 55 chrome.storage.sync.get({ | |
| 56 blacklist: [], | |
| 57 disableInApplets: true, | |
| 58 whitelist: [] | |
| 59 }, function(items) { | |
| 60 blacklist.value = items.blacklist.join('\n'); | |
| 61 checkbox.checked = items.disableInApplets; | |
| 62 whitelist.value = items.whitelist.join('\n'); | |
| 63 }); | |
| 64 } | |
| 65 | |
| 66 window.addEventListener('load', init, false); | |
| OLD | NEW |