Skip to content

Instantly share code, notes, and snippets.

@deenseth
Created December 23, 2011 16:23
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save deenseth/1514633 to your computer and use it in GitHub Desktop.
Save deenseth/1514633 to your computer and use it in GitHub Desktop.
Add Google Calendar Event Bookmarklet
javascript: var s;
/*Figure out the selected text*/
if ( window.getSelection ) {
s = window.getSelection();
} else if ( document.getSelection ) {
s = document.getSelection();
} else {
s = document.selection.createRange().text;
}
/*If there isn't any text selected, get user input*/
if ( s == '' ) {
s = prompt('QuickAdd');
}
var re = RegExp( '[AaPp][Mm]' );
if ( encodeURIComponent(s).match(re) ) {
} else {
var d = new Date();
var hr = d.getHours();
var min = d.getMinutes();
if (min < 10) {
min = "0" + min;
}
s = s + " " + hr + ":" + min; /*if there isn't an AM or PM in the text, add the default current time*/
}
void(
/*open a new window with this information in the Google Calendar event creation page.*/
window.open(
encodeURI('http://www.google.com/calendar/event?ctext='+s+'&action=TEMPLATE&pprop=HowCreated:QUICKADD'),
'addwindow',
'status=no,toolbar=no,width=520,height=470,resizable=yes'
)
);
@fedmich
Copy link

fedmich commented Feb 22, 2014

Hey man, your code works but it got a bit of issues. I got "null" if I cancel on the Quick Add prompt.

btw, you can use this page for generating draggable bookmarklet links.
http://pastetool.com/generators/bookmarklet/

@AdKiller
Copy link

Use it for work and it's a huge time saver. Thank you for sharing!

@AdKiller
Copy link

It seems Google has made it so that this bookmarklet does not work anymore while browsing mail.google.com, it works if you are browsing any other website.
Tried using Firefox v55.0.3, new profile, all default settings.

It would be highly appreciated if you could fix this useful bookmarklet @deenseth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment