Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:reedlabotz/SiteSquares

  • Loading branch information...
commit 53f8f11a4fae04868451f376f2cba22bc554df97 2 parents 39ffa1f + 2fbac5e
Reed La Botz authored
Showing with 53 additions and 7 deletions.
  1. +48 −7 chrome-extension/colors.js
  2. +5 −0 chrome-extension/manifest.json
55 chrome-extension/colors.js
View
@@ -39,11 +39,18 @@ function findColorOfIcon(image) {
//a = Math.floor(a/amount)*amount;
var weight = getWeight(r,g,b,a)
var str = toHex(r,g,b);
+ var hsv = rgbToHsv(r,g,b);
+ var key = hsv[0]/3; //
+ key = str;
//console.log("Str: "+str);
- if (colors[str]) {
- colors[str] = colors[str] + weight;
+ if (colors[key]) {
+ colors[key].count = colors[key].count + weight;
+ //colors[key].data.push({string:str, array:[r,g,b,a]});
} else {
- colors[str] = weight;
+ colors[key] = {
+ count:weight,
+ data:{string:str, array:[r,g,b,a]}
+ };
}
}
@@ -120,23 +127,57 @@ function getMaxColor(colors) {
for (key in colors) {
var element = colors[key];
//console.log("Color: "+key+" times: "+element);
- if (element > max) {
- max = element;
- argmax = key;
+ if (element.count > max) {
+ max = element.count;
+ argmax = element.data;
}
}
+ //found the most common color, now let's find the brightest component in it.
+ max = 0;
+ var brightest;
+ for (color in argmax) {
+ /// if (
+ }
//console.log(" Best color:" +argmax + " with "+max+" many");
return argmax;
}
function sendColor(color) {
- var url = "http://sitesquares.herokuapp.com/color/"+color;
+ var url = "http://sitesquares.herokuapp.com/color/"+color.string;
console.log("Sending to url: "+url);
+ console.log("color array: "+color.array[0]+","+color.array[1]+","+color.array[2]+","+color.array[3]);
$.get(url, function() {
console.log("Success");
});
+ setBrowserIcon(color);
+}
+
+function setBrowserIcon(color) {
+ var canvas = document.createElement("canvas");
+ var c = canvas.getContext("2d");
+ canvas.width = 19;
+ canvas.height = 19;
+ var r = color.array[0];
+ var g = color.array[1];
+ var b = color.array[2];
+ var a = color.array[3];
+ var pix = c.createImageData(canvas.width, canvas.height);
+ for (var i = 0, n = canvas.width*canvas.height*4; i < n; i += 4) {
+ pix.data[i ] = r; // red
+ pix.data[i+1] = g; // green
+ pix.data[i+2] = b; // blue
+ pix.data[i+3] = a;
+ }
+ chrome.browserAction.setIcon({imageData:pix});
+}
+function setPixel(imageData, x, y, r, g, b, a) {
+ index = (x + y * imageData.width) * 4;
+ imageData.data[index+0] = r;
+ imageData.data[index+1] = g;
+ imageData.data[index+2] = b;
+ imageData.data[index+3] = a;
}
var lastUrl;
5 chrome-extension/manifest.json
View
@@ -10,6 +10,11 @@
"js": ["content.js"]
}
],
+ "browser_action": {
+ "default_title": "SiteSquares" // optional; shown in tooltip
+ //"default_popup": "popup.html" // optional
+
+ },
"permissions": [
"http://*/*",
"https://*/*",
Please sign in to comment.
Something went wrong with that request. Please try again.