Skip to content

Instantly share code, notes, and snippets.

@danschumann
Last active August 29, 2015 14:16
Show Gist options
  • Save danschumann/36bd25dcafb983ecd2bd to your computer and use it in GitHub Desktop.
Save danschumann/36bd25dcafb983ecd2bd to your computer and use it in GitHub Desktop.
Tampermonkey Script

Google Calender Easy Add Appointments

This script is made for tamper monkey. it creates an additional button next to create that pops up a window with 3 select boxes.

Currently it is set up so my trainer can pick this week|next week, day of week, 4:45pm|4:30pm. The main reason for this is because entering 4:45pm takes too many clicks.

TO use:

  • In tampermonkey, include https://www.google.com/calendar/render* for the page
  • Paste the script
// ==UserScript==
// @name Add DS scheduling to google calendar
// @version 0.1
// @author DS
// @match https://www.google.com/calendar/render*
// ==/UserScript==
// Load the script
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
script.type = 'text/javascript';
setTimeout(function(){
document.getElementsByTagName("head")[0].appendChild(script);
}, 500);
// Poll for jQuery to come into existance
//
var prev$;
var whenReady = function(callback) {
if (typeof jQuery !== 'undefined') {
var j = jQuery.noConflict();
if (prev$) $ = prev$;
jQuery(document).ready(callback);
} else {
if ('undefined' != typeof $) prev$ = $;
window.setTimeout(function() { whenReady(callback); }, 10);
}
};
whenReady(function($) {
var $name = $('<input class="textbox-fill-input to-disable" style="margin: 5px" placeholder="DS ( is the best in the business )" />');
var selectHTML = '<select class="textbox-fill-input to-disable" style="margin: 5px">';
var $timeSelect = $(selectHTML);
timeArray = []
for(var t = 5; t < 22; t++ ){
$.each(['00', '15', '30', '45'], function(n, mm) {
timeArray.push(((t%12)||12) + ':' + mm + (t<12?'am':'pm'));
});
}
$timeSelect.append.apply($timeSelect,
$.map(timeArray, function(time){
return $('<option' + (time=='4:45pm'?' selected ':'') + '>').val(time).html(time);
})
);
var $weekSelect = $(selectHTML);
$weekSelect.append.apply($weekSelect,
$.map(['Next', 'This'], function(week){
return $('<option>').val(week).html(week + ' Week');
})
);
var $daySelect = $(selectHTML);
$daySelect.append.apply($daySelect,
$.map(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], function(day){
return $('<option>').val(day).html(day);
})
);
var $button;
//.addClass('goog-imageless-button-collapse-right')
var $originalDD = $('#sidebar > div > div.goog-inline-block.goog-imageless-button.goog-imageless-button-collapse-left.qnb-qab');
var downed = 0
$('#sidebar').after($('<div class="qnb-container">').append(
$button = $('<div ' +
'class="goog-inline-block goog-imageless-button qnb-qab DS-BEST-BUTTON" ' +
'role="button" tabindex="0" data-tooltip="Do you even lift, bro?" ' +
'aria-label="Quick add" style="-webkit-user-select: none;"' +
'>' +
'<div class="goog-inline-block goog-imageless-button-outer-box">' +
'<div class="goog-inline-block goog-imageless-button-inner-box">' +
'<div class="goog-imageless-button-pos">' +
'<div class="goog-imageless-button-top-shadow">' +
'&nbsp;' +
'</div>' +
'<div class="goog-imageless-button-content">' +
'Train ' + $originalDD.find('.goog-imageless-button-content').html() +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>').click(function(){
if ((new Date).getTime() - downed < 300) return;
$submit = $('<div class="goog-inline-block goog-imageless-button" role="button" tabindex="0" style="-webkit-user-select: none;"><div class="goog-inline-block goog-imageless-button-outer-box"><div class="goog-inline-block goog-imageless-button-inner-box"><div class="goog-imageless-button-pos"><div class="goog-imageless-button-top-shadow">&nbsp;</div><div class="goog-imageless-button-content">DO IT!</div></div></div></div></div>').css('float', 'right')
var w = 300, h = 102;
var $modal = $('<div class="ds-best-popup qab-container gcal-popup DS-ADDON">').appendTo('body').css({
visibility: 'visible',
position: 'absolute',
zIndex: 9999,
width: w,
left: $button.offset().left,
top: $button.offset().top + $button.outerHeight() + 9,
background: 'white',
padding: 20,
}).append(
$('<div>').css({padding: 10}).html('Training Session'),
$name,
$weekSelect,
$daySelect,
$timeSelect,
$('<div>').css('padding',20).append($submit)
);
$name.focus()
var s = '.ds-bestbiz';
var clear = function(){
$modal.remove();
$([$weekSelect, $daySelect]).each(function(n,$el){
$el.val($el.find('option:first').val());
});
$timeSelect.val('4:45pm');
$name.val('');
$(window).off(s);
downed = (new Date).getTime();
};
$(window).on('mousedown' + s, function(e){
if ( !$(e.target).hasClass('DS-ADDON') && !$(e.target).parents('.DS-ADDON')[0] ) {
clear();
}
});
$submit.click( function(){
$originalDD.click();
$(':focus').val($name.val() + ' ' + $weekSelect.val() + ' ' + $daySelect.val() + ' at ' + $timeSelect.val());
$(':focus').next('div:first').click();
clear()
});
})
));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment