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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/accessibility/extensions/colorenhancer/src/common.js
diff --git a/ui/accessibility/extensions/colorenhancer/src/common.js b/ui/accessibility/extensions/colorenhancer/src/common.js
new file mode 100644
index 0000000000000000000000000000000000000000..ed8a2972b94c7a50471dcf92308c8f54b612888e
--- /dev/null
+++ b/ui/accessibility/extensions/colorenhancer/src/common.js
@@ -0,0 +1,230 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+// ======= Utils =======
+
+function $(id) {
+ return document.getElementById(id);
+}
+
+
+function siteFromUrl(url) {
+ var a = document.createElement("a");
+ a.href = url;
+ return a.hostname;
+}
+
+
+function isDisallowedUrl(url) {
+ return url.indexOf("chrome") == 0 || url.indexOf("about") == 0;
+}
+
+
+// ======= Delta setting =======
+
+var DEFAULT_DELTA = 1.0;
+var LOCAL_STORAGE_TAG_DELTA = "cvd_delta";
+var LOCAL_STORAGE_TAG_SITE_DELTA = "cvd_deltas";
+
+
+function validDelta(delta) {
+ return delta >= 0 && delta <= 1;
+}
+
+
+function getDefaultDelta() {
+ var delta = localStorage[LOCAL_STORAGE_TAG_DELTA];
+ if (validDelta(delta)) {
+ return delta;
+ }
+ delta = DEFAULT_DELTA;
+ localStorage[LOCAL_STORAGE_TAG_DELTA] = delta;
+ return delta;
+}
+
+
+function setDefaultDelta(delta) {
+ if (!validDelta(delta)) {
+ delta = DEFAULT_DELTA;
+ }
+ localStorage[LOCAL_STORAGE_TAG_DELTA] = delta;
+}
+
+
+function getSiteDelta(site) {
+ var delta = getDefaultDelta();
+ try {
+ var siteDeltas = JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_DELTA]);
+ delta = siteDeltas[site];
+ if (!validDelta(delta)) {
+ delta = getDefaultDelta();
+ }
+ } catch (e) {
+ delta = getDefaultDelta();
+ }
+ return delta;
+}
+
+
+function setSiteDelta(site, delta) {
+ if (!validDelta(delta)) {
+ delta = getDefaultDelta();
+ }
+ var siteDeltas = {};
+ try {
+ siteDeltas = JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_DELTA]);
+ } catch (e) {
+ siteDeltas = {};
+ }
+ siteDeltas[site] = delta;
+ localStorage[LOCAL_STORAGE_TAG_SITE_DELTA] = JSON.stringify(siteDeltas);
+}
+
+
+function resetSiteDeltas() {
+ var siteDeltas = {};
+ localStorage[LOCAL_STORAGE_TAG_SITE_DELTA] = JSON.stringify(siteDeltas);
+}
+
+
+// ======= Severity setting =======
+
+var DEFAULT_SEVERITY = 1.0;
+var LOCAL_STORAGE_TAG_SEVERITY = "cvd_severity";
+var LOCAL_STORAGE_TAG_SITE_SEVERITY = "cvd_severities";
+
+
+function validSeverity(severity) {
+ return severity >= 0 && severity <= 1;
+}
+
+
+function getDefaultSeverity() {
+ var severity = localStorage[LOCAL_STORAGE_TAG_SEVERITY];
+ if (validSeverity(severity)) {
+ return severity;
+ }
+ severity = DEFAULT_SEVERITY;
+ localStorage[LOCAL_STORAGE_TAG_SEVERITY] = severity;
+ return severity;
+}
+
+
+function setDefaultSeverity(severity) {
+ if (!validSeverity(severity)) {
+ severity = DEFAULT_SEVERITY;
+ }
+ localStorage[LOCAL_STORAGE_TAG_SEVERITY] = severity;
+}
+
+
+// TODO(mustaq): Remove site-specific severity setting.
+function getSiteSeverity(site) {
+ var severity = getDefaultSeverity();
+ try {
+ var siteSeverities =
+ JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY]);
+ severity = siteSeverities[site];
+ if (!validSeverity(severity)) {
+ severity = getDefaultSeverity();
+ }
+ } catch (e) {
+ severity = getDefaultSeverity();
+ }
+ return severity;
+}
+
+
+function setSiteSeverity(site, severity) {
+ if (!validSeverity(severity)) {
+ severity = getDefaultSeverity();
+ }
+ var siteSeverities = {};
+ try {
+ siteSeverities = JSON.parse(localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY]);
+ } catch (e) {
+ siteSeverities = {};
+ }
+ siteSeverities[site] = severity;
+ localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY] =
+ JSON.stringify(siteSeverities);
+}
+
+
+function resetSiteSeverities() {
+ var siteSeverities = {};
+ localStorage[LOCAL_STORAGE_TAG_SITE_SEVERITY] =
+ JSON.stringify(siteSeverities);
+}
+
+
+// ======= Type setting =======
+
+var DEFAULT_TYPE = "type_a";
+var LOCAL_STORAGE_TAG_TYPE = "cvd_type";
+
+
+function validType(type) {
+ return type === "type_a" || type === "type_b" || type === "type_c";
+}
+
+
+function getDefaultType() {
+ var type = localStorage[LOCAL_STORAGE_TAG_TYPE];
+ if (validType(type)) {
+ return type;
+ }
+ type = DEFAULT_TYPE;
+ localStorage[LOCAL_STORAGE_TAG_TYPE] = type;
+ return type;
+}
+
+
+function setDefaultType(type) {
+ if (!validType(type)) {
+ type = DEFAULT_TYPE;
+ }
+ localStorage[LOCAL_STORAGE_TAG_TYPE] = type;
+}
+
+
+// ======= Simulate setting =======
+
+var DEFAULT_SIMULATE = false;
+var LOCAL_STORAGE_TAG_SIMULATE = "cvd_simulate";
+
+
+function validSimulate(simulate) {
+ return simulate == true || simulate == false;
+}
+
+
+function getDefaultSimulate() {
+ var simulate = localStorage[LOCAL_STORAGE_TAG_SIMULATE];
+
+ //Make it a boolean if possible
+ if (simulate === "true") {
+ simulate = true;
+ } else if (simulate === "false") {
+ simulate = false;
+ } else {
+ simulate = "undef";
+ }
+
+ if (validSimulate(simulate)) {
+ return simulate;
+ }
+ simulate = DEFAULT_SIMULATE;
+ localStorage[LOCAL_STORAGE_TAG_SIMULATE] = simulate;
+ return simulate;
+}
+
+
+function setDefaultSimulate(simulate) {
+ if (!validSimulate(simulate)) {
+ simulate = DEFAULT_SIMULATE;
+ }
+ localStorage[LOCAL_STORAGE_TAG_SIMULATE] = simulate;
+}

Powered by Google App Engine
This is Rietveld 408576698