Skip to content

Instantly share code, notes, and snippets.

@spudtrooper
Created April 24, 2011 18:21
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 spudtrooper/939764 to your computer and use it in GitHub Desktop.
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.
// ==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