diff --git a/manifest.json b/manifest.json index 288819c..0f0798a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Auto Highlight", - "version": "1.3.1", + "version": "1.4.0", "description": "*Auto Highlight* automatically highlights the important content on article pages.", "content_scripts": [ { "js": [ "src/ping.js" ], diff --git a/src/content.js b/src/content.js index 5a3dbe7..da78b63 100644 --- a/src/content.js +++ b/src/content.js @@ -17,11 +17,6 @@ chrome.runtime.sendMessage({message: "getOptions"}, function(response) { OPTIONS = response; }); -var COLOR_MAP = null; -chrome.runtime.sendMessage({message: "getSharedGlobals"}, function(response) { - COLOR_MAP = response['COLOR_MAP']; -}); - /*********************************** * Node Highlighting Functionality ***********************************/ @@ -1135,24 +1130,16 @@ var getHighlightState = function(callback) { }; // useful for debugging sentence boundary detection -// cycles in initialized on the first call to getNextColor. -// It's not initialized sooner since COLOR_MAP may not be set yet. -var cycles = []; var cycleCurColor = 0; var getNextColor = function() { - if (cycles.length === 0) { - Object.keys(COLOR_MAP).forEach(function(key) { - color_properties = COLOR_MAP[key]; - var highlightColor = color_properties[1]; - var textColor = color_properties[2]; - var linkColor = color_properties[3]; - var colorSpec = new ColorSpec(highlightColor, textColor, linkColor); - cycles.push(colorSpec); - }); - } - color = cycles[cycleCurColor]; - cycleCurColor = (cycleCurColor+1) % cycles.length; - return color; + var yellow = "#FFFF00"; + var pale_green = "#98FB98"; + var black = "#000000"; + var red = "#FF0000"; + var highlightColor = cycleCurColor === 0 ? yellow : pale_green; + var colorSpec = new ColorSpec(highlightColor, black, red); + cycleCurColor = (cycleCurColor+1) % 2; + return colorSpec; }; // hacky way to trim spaces if we're not highlighting the preceding @@ -1230,13 +1217,8 @@ var highlight = function(highlightState) { removeHighlight(); var scoredCandsToHighlight = cth(highlightState); trimSpaces(scoredCandsToHighlight); - - var color_id = OPTIONS.color; - var color_properties = COLOR_MAP[color_id]; - var highlightColor = color_properties[1]; - var textColor = color_properties[2]; - var linkColor = color_properties[3]; - var colorSpec = new ColorSpec(highlightColor, textColor, linkColor); + var colorSpec = new ColorSpec( + OPTIONS["highlight_color"], OPTIONS["text_color"], OPTIONS["link_color"]); // have to loop backwards since splitting text nodes for (var j = scoredCandsToHighlight.length-1; j >= 0; j--) { var candidate = scoredCandsToHighlight[j].candidate; diff --git a/src/eventPage.js b/src/eventPage.js index a51a7d9..c97fdbb 100644 --- a/src/eventPage.js +++ b/src/eventPage.js @@ -4,9 +4,6 @@ // * Utilities and Options // ***************************** -// TODO: can some of this utility functionality, particularly -// the code/data shared with content.js, be moved to utils.js? - var getVersion = function() { var version = chrome.runtime.getManifest().version; return version; @@ -20,23 +17,18 @@ var getOptions = function() { return opts; }; -// Maps color ID to a list of properties -// (name, background/highlight color, text color, link color) -var COLOR_MAP = { - 'yellow': ['Yellow', 'yellow', 'black', 'red'], - 'blue': ['Blue', 'skyblue', 'black', 'red'], - 'orange': ['Orange', 'sandybrown', 'black', 'red'], - 'green': ['Green', 'palegreen', 'black', 'red'], - 'pink': ['Pink', 'lightpink', 'black', 'red'] -}; - var defaultOptions = function() { var options = Object.create(null); - options['color'] = 'yellow'; + var yellow = "#FFFF00"; + var black = "#000000"; + var red = "#FF0000"; + options['highlight_color'] = yellow; + options['text_color'] = black; + options['link_color'] = red; return options; }; -// Set missing options using defaults +// Validate options (function() { var opts = getOptions(); if (!opts) { @@ -44,12 +36,24 @@ var defaultOptions = function() { } var defaults = defaultOptions(); + + // Set missing options using defaults. + + var default_keys = Object.keys(defaults); + for (var i = 0; i < default_keys.length; i++) { + var default_key = default_keys[i]; + if (!(default_key in opts)) { + opts[default_key] = defaults[default_key]; + } + } - var keys = Object.keys(defaults); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - if (!(key in opts)) { - opts[key] = defaults[key]; + // Remove unknown options (these may have been set + // by previous versions of the extension). + var opt_keys = Object.keys(opts); + for (var i = 0; i < opt_keys.length; i++) { + var opt_key = opt_keys[i]; + if (!(opt_key in defaults)) { + delete opts[opt_key]; } } @@ -148,11 +152,6 @@ chrome.runtime.onMessage.addListener(function(request, sender, response) { response(getOptions()); } else if (message === 'ping') { ping.add(tabId); - } else if (message === 'getSharedGlobals') { - sharedGlobals = { - 'COLOR_MAP': COLOR_MAP - }; - response(sharedGlobals); } // NOTE: if you're going to call response asynchronously, // be sure to return true from this function. diff --git a/src/options.html b/src/options.html index 882f7c7..280f49d 100644 --- a/src/options.html +++ b/src/options.html @@ -9,35 +9,12 @@ margin-right: auto; } -body { - margin-top: 20px; +p { + font-size: 16px; } -a.tooltip { - outline: none; - border-bottom: 1px dotted; -} -a.tooltip:hover { text-decoration: none; } -a.tooltip span { - z-index: 10; - display: none; - padding: 14px 20px; - margin-top: -30px; - margin-left: 14px; - width: auto; - max-width: 300px; - line-height: 16px; -} -a.tooltip:hover span { - display: inline; - position: absolute; - color: #111; - border: 1px solid #DCA; - background:#fffAF0; -} -a.tooltip span { - border-radius:4px; - box-shadow: 5px 5px 8px #CCC; +body { + margin-top: 20px; } @@ -48,11 +25,24 @@
+ | + |
+ | + |
+ | + |
+Example text. +Example link. +