google_calendar_age_adder

By darrinholst Last update Jun 9, 2009 — Installed 1,808 times.

Archived Comments (locked)

in
Subscribe to Archived Comments 7 posts, 4 voices



Jesse Andrews Admin

The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008)

 
Henrique Abreu User

Thanks, problem solved.

 
darrinholst Script's Author

Google changed their html a bit, try installing again.

 
Henrique Abreu User

It's not working anymore! :(

 
Henrique Abreu User

It would also be good if it this script works with embedded calendars, like the one generated by GmailAgenda

 
darrinholst Script's Author

thanks for the update, I've added it in

Darrin

 
pixel User

it's great script!
but as my entries are usually relatively long
and sometime i use numbers at the end
i decided to make the event title little bit shorter
and instruct script more precisely to match birthdate
so i changed it a bit while old functioanlity remains untouched
here is my change
if user adds coded birthdate at the end it will show just an age
example:
Brian [bd:1974]

and we have 2008 so title will be replaced by:
Brian (34)

here is the script:

// ==UserScript==
// @name           google_calendar_age_adder
// @namespace      http://darrinholst.com
// @description    Adds the age to gcal events ending with " - 9999" where 9999 is the start year of the event.
// @description    Great for birthday and anniversary events.This just modifies the html,it doesn't touch the actual event.
// @description    New settings allows to display only the age without the year. Just add [bd:YYYY] at the end
// @include        http://www.google.com/calendar/*
// @include        https://www.google.com/calendar/*
// ==/UserScript==

(function() {
	var EVENT_CONTAINER = 'mainbody',
			  DATE_CONTAINER = 'dateunderlay',
			  EVENT_TAG = 'nobr';

	document.getElementById(EVENT_CONTAINER).addEventListener('DOMSubtreeModified', function() {
		var events = document.getElementById(EVENT_CONTAINER).getElementsByTagName(EVENT_TAG);
		var year = /^.*(\d{4})$/.exec(document.getElementById(DATE_CONTAINER).innerHTML)[1];

		for (var i = 0; i < events.length; i++) {
			var e = events[i].innerHTML;

			// match old settings like xxxxx - YYYY
			var oldMatch = /^.* - ((?:19|20)\d\d)$$/.exec(e);

			// match new settings like xxxxx [bd:YYYY]
			var newMatch = /(^.* )(\[bd:(?:19|20)\d\d\])$$/.exec(e);

			if (oldMatch) {
				// shows: xxxxx - YYYY (age)
				events[i].innerHTML = e + ' (' + (year - oldMatch[1]) + ')';
			}

			if (newMatch) {
				// shows: xxxxx (age)
				var birthyear = newMatch[2].substring(4, 8);
				events[i].innerHTML = newMatch[1] + ' (' + (year - birthyear) + ')';
			}
		}
	}, true);
})();

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel