Skip to content

Instantly share code, notes, and snippets.

@karmiphuc
Forked from deenseth/gist:1514633
Created January 4, 2014 09:58
Show Gist options
  • Save karmiphuc/8253695 to your computer and use it in GitHub Desktop.
Save karmiphuc/8253695 to your computer and use it in GitHub Desktop.
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'
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment