Created
July 13, 2014 15:31
-
-
Save vladholubiev/856012009a88b6325cbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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