Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: ui/accessibility/extensions/colorenhancer/src/common.js

Issue 984833004: Add color enhancer as a chromium accessibility extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update to 1.1.2 Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
kevers 2015/03/09 13:56:59 Please drop (c) here and in other headers. Also,
Peter Wen 2015/03/09 21:35:56 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5
6 // ======= Utils =======
7
8 function $(id) {
9 return document.getElementById(id);
10 }
11
12
13 function siteFromUrl(url) {
14 var a = document.createElement("a");
15 a.href = url;
16 return a.hostname;
17 }
18
19
20 function isDisallowedUrl(url) {
21 return url.indexOf("chrome") == 0 || url.indexOf("about") == 0;
22 }
23
24
25 // ======= Delta setting =======
26
27 var DEFAULT_DELTA = 1.0;
28 var LOCAL_STORAGE_TAG_DELTA = "cvd_delta";
29 var LOCAL_STORAGE_TAG_SITE_DELTA = "cvd_deltas";
30
31
32 function validDelta(delta) {
33 return delta >= 0 && delta <= 1;
34 }
35
36
37 function getDefaultDelta() {
38 var delta = localStorage[LOCAL_STORAGE_TAG_DELTA];
39 if (validDelta(delta)) {
40 return delta;
41 }
42 delta = DEFAULT_DELTA;
43 localStorage[LOCAL_STORAGE_TAG_DELTA] = delta;
44 return delta;
45 }
46
47
48 function setDefaultDelta(delta) {
49 if (!validDelta(delta)) {
50 delta = DEFAULT_DELTA;
51 }
52 localStorage[LOCAL_STORAGE_TAG_DELTA] = delta;
53 }
54
55
56 function getSiteDelta(site) {
57 var delta = getDefaultDelta();
58 try {
59 var siteDeltas = JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_DELTA]);
60 delta = siteDeltas[site];
61 if (!validDelta(delta)) {
62 delta = getDefaultDelta();
63 }
64 } catch (e) {
65 delta = getDefaultDelta();
66 }
67 return delta;
68 }
69
70
71 function setSiteDelta(site, delta) {
72 if (!validDelta(delta)) {
73 delta = getDefaultDelta();
74 }
75 var siteDeltas = {};
76 try {
77 siteDeltas = JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_DELTA]);
78 } catch (e) {
79 siteDeltas = {};
80 }
81 siteDeltas[site] = delta;
82 localStorage[LOCAL_STORAGE_TAG_SITE_DELTA] = JSON.stringify(siteDeltas);
83 }
84
85
86 function resetSiteDeltas() {
87 var siteDeltas = {};
88 localStorage[LOCAL_STORAGE_TAG_SITE_DELTA] = JSON.stringify(siteDeltas);
89 }
90
91
92 // ======= Severity setting =======
93
94 var DEFAULT_SEVERITY = 1.0;
95 var LOCAL_STORAGE_TAG_SEVERITY = "cvd_severity";
96 var LOCAL_STORAGE_TAG_SITE_SEVERITY = "cvd_severities";
97
98
99 function validSeverity(severity) {
100 return severity >= 0 && severity <= 1;
101 }
102
103
104 function getDefaultSeverity() {
105 var severity = localStorage[LOCAL_STORAGE_TAG_SEVERITY];
106 if (validSeverity(severity)) {
107 return severity;
108 }
109 severity = DEFAULT_SEVERITY;
110 localStorage[LOCAL_STORAGE_TAG_SEVERITY] = severity;
111 return severity;
112 }
113
114
115 function setDefaultSeverity(severity) {
116 if (!validSeverity(severity)) {
117 severity = DEFAULT_SEVERITY;
118 }
119 localStorage[LOCAL_STORAGE_TAG_SEVERITY] = severity;
120 }
121
122
123 // TODO(mustaq): Remove site-specific severity setting.
124 function getSiteSeverity(site) {
125 var severity = getDefaultSeverity();
126 try {
127 var siteSeverities =
128 JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY]);
129 severity = siteSeverities[site];
130 if (!validSeverity(severity)) {
131 severity = getDefaultSeverity();
132 }
133 } catch (e) {
134 severity = getDefaultSeverity();
135 }
136 return severity;
137 }
138
139
140 function setSiteSeverity(site, severity) {
141 if (!validSeverity(severity)) {
142 severity = getDefaultSeverity();
143 }
144 var siteSeverities = {};
145 try {
146 siteSeverities = JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY]);
147 } catch (e) {
148 siteSeverities = {};
149 }
150 siteSeverities[site] = severity;
151 localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY] =
152 JSON.stringify(siteSeverities);
153 }
154
155
156 function resetSiteSeverities() {
157 var siteSeverities = {};
158 localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY] =
159 JSON.stringify(siteSeverities);
160 }
161
162
163 // ======= Type setting =======
164
165 var DEFAULT_TYPE = "type_a";
166 var LOCAL_STORAGE_TAG_TYPE = "cvd_type";
167
168
169 function validType(type) {
170 return type === "type_a" || type === "type_b" || type === "type_c";
171 }
172
173
174 function getDefaultType() {
175 var type = localStorage[LOCAL_STORAGE_TAG_TYPE];
176 if (validType(type)) {
177 return type;
178 }
179 type = DEFAULT_TYPE;
180 localStorage[LOCAL_STORAGE_TAG_TYPE] = type;
181 return type;
182 }
183
184
185 function setDefaultType(type) {
186 if (!validType(type)) {
187 type = DEFAULT_TYPE;
188 }
189 localStorage[LOCAL_STORAGE_TAG_TYPE] = type;
190 }
191
192
193 // ======= Simulate setting =======
194
195 var DEFAULT_SIMULATE = false;
196 var LOCAL_STORAGE_TAG_SIMULATE = "cvd_simulate";
197
198
199 function validSimulate(simulate) {
200 return simulate == true || simulate == false;
201 }
202
203
204 function getDefaultSimulate() {
205 var simulate = localStorage[LOCAL_STORAGE_TAG_SIMULATE];
206
207 //Make it a boolean if possible
208 if (simulate === "true") {
209 simulate = true;
210 } else if (simulate === "false") {
211 simulate = false;
212 } else {
213 simulate = "undef";
214 }
215
216 if (validSimulate(simulate)) {
217 return simulate;
218 }
219 simulate = DEFAULT_SIMULATE;
220 localStorage[LOCAL_STORAGE_TAG_SIMULATE] = simulate;
221 return simulate;
222 }
223
224
225 function setDefaultSimulate(simulate) {
226 if (!validSimulate(simulate)) {
227 simulate = DEFAULT_SIMULATE;
228 }
229 localStorage[LOCAL_STORAGE_TAG_SIMULATE] = simulate;
230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698