Created
April 24, 2011 18:21
-
-
Save spudtrooper/939764 to your computer and use it in GitHub Desktop.
Puts your gmail inbox count to the front of the window, rather than towards the back.
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
// ==UserScript== | |
// @name Gmail Title | |
// @namespace http://jeffpalm.com/gmailtitle | |
// @description Makes the gmail title somewhat useful | |
// @include https://mail.google.com/mail/* | |
// ==/UserScript== | |
(function() { | |
var ignoreNextChange = false; | |
function changeTitle() { | |
if (ignoreNextChange) { | |
ignoreNextChange = false; | |
return; | |
} | |
var t = String(document.title); | |
// Gmail - Inbox (1700) - jeffpalm@gmail.com | |
var res = t.match(/([^\(]+)(\(\d+\))(.*)/); | |
if (res) { | |
ignoreNextChange = true; | |
var title = res[2].replace(/\D/g,"") + " - " + res[1] + res[3]; | |
document.title = title; | |
} | |
} | |
function main() { | |
var titleEl = document.getElementsByTagName("title")[0]; | |
var docEl = document.documentElement; | |
if (docEl && docEl.addEventListener) { | |
docEl.addEventListener("DOMSubtreeModified", function(evt) { | |
var t = evt.target; | |
if (t === titleEl || (t.parentNode && t.parentNode === titleEl)) { | |
changeTitle(); | |
} | |
}, false); | |
} else { | |
document.onpropertychange = function() { | |
if (window.event.propertyName == "title") { | |
changeTitle(); | |
} | |
}; | |
} | |
changeTitle(); | |
} | |
main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment