Skip to content

Commit

Permalink
Merge branch 'master' of github.com:reedlabotz/SiteSquares
Browse files Browse the repository at this point in the history
  • Loading branch information
reedlabotz committed Apr 26, 2012
2 parents 39ffa1f + 2fbac5e commit 53f8f11
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
55 changes: 48 additions & 7 deletions chrome-extension/colors.js
Expand Up @@ -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]}
};
}

}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions chrome-extension/manifest.json
Expand Up @@ -10,6 +10,11 @@
"js": ["content.js"]
}
],
"browser_action": {
"default_title": "SiteSquares" // optional; shown in tooltip
//"default_popup": "popup.html" // optional

},
"permissions": [
"http://*/*",
"https://*/*",
Expand Down

0 comments on commit 53f8f11

Please sign in to comment.