Skip to content

Instantly share code, notes, and snippets.

@frosas
Created October 18, 2012 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frosas/3912457 to your computer and use it in GitHub Desktop.
Save frosas/3912457 to your computer and use it in GitHub Desktop.
Toggl Icon & Shortcuts
;(function() {
var onElementAttributesChange = function(element, callback) {
new WebKitMutationObserver(callback).observe(element, {attributes: true})
}
var Tracking = function() {
var el = document.getElementById('running-task-form')
return {
isRunning: function() { return el.style.display != 'none' },
onChange: function(callback) { onElementAttributesChange(el, callback) }
}
}
var Icon = function(tracking) {
var el = document.querySelector('link[rel~=icon]')
if (! el) {
el = document.createElement('link')
el.setAttribute('rel', 'icon')
el.setAttribute('type', 'image/png')
document.head.appendChild(el)
}
var update = function() {
el.setAttribute('href', tracking.isRunning() ?
'http://cdn.dustball.com/clock_stop.png' :
'http://cdn.dustball.com/clock_play.png')
}
tracking.onChange(update)
update()
}
new Icon(new Tracking)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment