]>
git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blob - javascript/options.js
1 // Copyright 2011 Google Inc. All Rights Reserved.
4 * @fileoverview Script for the options page.
5 * @author arunjit@google.com (Arunjit Singh)
8 window
.addEventListener('load', init
, false);
11 * Initializes the i18n strings.
12 * Loads values from localStorage and applies them to the elements
16 CONSTANTS
.TIMES
.forEach(function(time
) {
17 var selector
= 'input[name=time][value="{t}"], .opt-label#opt-{t}'
19 var elements
= $(selector
);
20 time
= getUnitsForTime(time
);
21 var message
= (time
.time
=== -1) ?
22 chrome
.i18n
.getMessage('optionsTimeAll') :
23 chrome
.i18n
.getMessage('optionsTime',
24 [time
.time
, time
.units
]);
25 elements
[0].title
= message
;
26 elements
[1].innerText
= message
;
29 $('[i18n-content]').forEach(function(ele
) {
30 ele
.innerText
= chrome
.i18n
.getMessage(ele
.getAttribute('i18n-content'));
33 // Bind all the callbacks
34 $('input[type=radio]').forEach(function(e
) {
37 $('input[type=checkbox]').forEach(function(e
) {
41 // Load or set localStorage data
43 'timeStart', 'time', 'prompt', 'cookies', 'downloads', 'autoclear', 'notify',
45 chrome
.storage
.sync
.get(settings
, function(s
) {
46 var timeStart
= s
.timeStart
|| CONSTANTS
.YES
;
47 var time
= ~~(s
.time
) || (s
.time
= CONSTANTS
.DEFAULT_TIME
);
48 var showPrompt
= s
.prompt
|| (s
.prompt
= CONSTANTS
.YES
);
49 var clearCookies
= s
.cookies
|| CONSTANTS
.NO
;
50 var clearDownloads
= s
.downloads
|| CONSTANTS
.NO
;
51 var autoClear
= s
.autoclear
|| CONSTANTS
.NO
;
52 var notify
= s
.notify
|| CONSTANTS
.YES
;
54 $('input[name=timeStart][value="' + timeStart
+ '"]')[0].checked
= true;
55 $('input[name=time][value="' + time
+ '"]')[0].checked
= true;
56 $('input[name=prompt]')[0].checked
= (showPrompt
=== CONSTANTS
.YES
);
57 $('input[name=cookies]')[0].checked
= (clearCookies
=== CONSTANTS
.YES
);
58 $('input[name=downloads]')[0].checked
= (clearDownloads
=== CONSTANTS
.YES
);
59 $('input[name=autoclear]')[0].checked
= (autoClear
=== CONSTANTS
.YES
);
60 $('input[name=notify]')[0].checked
= (notify
=== CONSTANTS
.YES
);
65 * Toggles the value in localStorage for the element selected
66 * @this {HTMLInputElement} The element (radio button) that was clicked.
70 setting
[this.name
] = this.value
;
71 chrome
.storage
.sync
.set(setting
);
76 * Sets the {@code localStorage.prompt} property when selected
77 * @this {HTMLInputElement} The element (checkbox) that was clicked.
81 setting
[this.name
] = this.checked
? CONSTANTS
.YES
: CONSTANTS
.NO
;
82 chrome
.storage
.sync
.set(setting
);
86 // For rapid changes/saves
89 * Updates the UI to indicate save completed
91 function optionSaved() {
92 var element
= $('#optionsSaved')[0];
93 element
.classList
.add('show');
94 clearTimeout(isSaving
);
95 isSaving
= setTimeout(function() {
96 element
.classList
.remove('show');