Last active
May 31, 2016 08:28
-
-
Save vitto/c2a88c81a8d770c15d5ed522d9a265c0 to your computer and use it in GitHub Desktop.
Google Calendar - add event duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js | |
//code.jquery.com/jquery-2.2.3.min.js | |
var events, checkEvents; | |
var roundHalf = function(num) { | |
return Math.round(num*2)/2; | |
} | |
var addDuration = function() { | |
$(".cbrd").each(function(){ | |
var interval, text, time; | |
text = $(this).find('.chip-caption') | |
.clone() | |
.children() | |
.remove() | |
.end() | |
.text(); | |
interval = text.split('–'); | |
interval[0] = $.trim(interval[0]); | |
if (interval.length === 2) { | |
interval[1] = $.trim(interval[1]); | |
var now = moment('2013-01-01T' + interval[0] + ':00.000'); | |
var end = moment('2013-01-01T' + interval[1] + ':00.000'); | |
var duration = moment.duration(end.diff(now)); | |
time = roundHalf(duration.asHours()); | |
} else { | |
time = 0.5; | |
} | |
$(this).find('.chip-caption').text(text + '(' + time + ')'); | |
$(this).addClass('cbrd--count-added'); | |
}); | |
}; | |
checkEvents = setInterval(function(){ | |
var jq = $ || false; | |
if (jq !== 'undefiend' && moment !== undefined) { | |
events = $('.cbrd').length; | |
filled = $('.cbrd--count-added').length; | |
if (events !== 0 && filled === 0) { | |
addDuration(); | |
} | |
} | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment