Skip to content

Instantly share code, notes, and snippets.

@vladholubiev
Created July 13, 2014 15:31
Show Gist options
  • Save vladholubiev/856012009a88b6325cbf to your computer and use it in GitHub Desktop.
Save vladholubiev/856012009a88b6325cbf to your computer and use it in GitHub Desktop.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
if (changeInfo.status == "complete") {
chrome.tabs.get(tabId, function(tab) {
window.setInterval(function() {
setPageActionIcon(tab);
}, 1000);
function setPageActionIcon(tab) {
var canvas = document.createElement('canvas');
var img = document.createElement('img');
img.onload = function() {
// Draw the background image
var context = canvas.getContext('2d');
context.drawImage(img, 0, 2);
// Draw the badge
var grd = context.createLinearGradient(0, 10, 0, 19);
grd.addColorStop(0, 'rgb(255, 100, 100)');
grd.addColorStop(1, 'rgb(150, 50, 50)');
context.fillStyle = grd;
context.fillRect(0, 9, 19, 10);
context.strokeStyle = 'rgb(255, 255, 255)';
context.strokeRect(0, 10, 1, 1);
context.strokeRect(0, 19, 1, 1);
context.strokeRect(19, 10, 1, 1);
context.strokeRect(19, 19, 1, 1);
// Draw some text
context.fillStyle = "white";
context.font = "bold 10px Sans-Serif";
context.fillText(edits, 2, 17, 17);
chrome.pageAction.setIcon({
imageData: context.getImageData(0, 0, 19, 19),
tabId: tab.id
});
};
img.src = "icon16.png";
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment