Skip to content

Instantly share code, notes, and snippets.

@fsantini
Last active April 30, 2024 09:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsantini/532f722d7d682f476e61de2aeee62824 to your computer and use it in GitHub Desktop.
Save fsantini/532f722d7d682f476e61de2aeee62824 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ISMRM To Calendar
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add calendar download links to sessions. Currently for ISMRM 2024. For other ISMRMs, the time zone needs to be adjusted!!
// @author Francesco Santini <francesco.santini@gmail.com>
// @match https://submissions.mirasmart.com/ISMRM2024/Itinerary/ConferenceMatrixEventDetail.aspx*
// @icon https://www.google.com/s2/favicons?sz=64&domain=mirasmart.com
// @icon https://www.google.com/s2/favicons?domain=pathable.com
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant GM_log
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
function toVcalTime(day_description, time)
{
function pad2(num)
{
return String(num).padStart(2, '0');
}
var date = new Date(day_description + ' ' + time + ' UTC+8'); // Adjust to the ISMRM time zone
var out = String(date.getUTCFullYear()) + pad2(date.getUTCMonth()+1) + pad2(date.getUTCDate()) + 'T' + pad2(date.getUTCHours()) + pad2(date.getUTCMinutes()) + '00Z';
return out
}
function vCalString(title, place, time_start, time_end)
{
return `BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//ISMRM//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:francesco.santini@gmail.com\nDTSTAMP:${time_start}\nORGANIZER;CN=ISMRM:MAILTO:info@ismrm.org\nDTSTART:${time_start}\nDTEND:${time_end}\nLOCATION:${place}\nSUMMARY:${title}\nEND:VEVENT\nEND:VCALENDAR`;
}
function createICal(title, place, day_description, time_start, time_end)
{
return `data:text/calendar;charset=utf8,${escape(vCalString(title, place, toVcalTime(day_description, time_start), toVcalTime(day_description, time_end)))}`;
}
function createGoogle(title, place, day_description, time_start, time_end)
{
return `https://www.google.com/calendar/event?action=TEMPLATE&text=${escape(title)}&dates=${toVcalTime(day_description, time_start)}/${toVcalTime(day_description, time_end)}&details=${escape(title)}&location=${escape(place)}&trp=true&sprop=ismrm.org&sprop=name:`;
}
function createLinks(title, place, day_description, time_start, time_end)
{
return ` <a href="${createICal(title, place, day_description, time_start, time_end)}">Download ICal</a>/<a href="${createGoogle(title, place, day_description, time_start, time_end)}" target="_blank">Add to Google</a>`
}
var session_title = $('#ctl00_BodyContent_lblEventTitle').text();
var place = $('#ctl00_BodyContent_lblRoom').text();
var day_description = $('#ctl00_BodyContent_lblDay').text();
var session_time_start = $('#ctl00_BodyContent_lblEventStart').text();
var session_time_end = $('#ctl00_BodyContent_lblEventEnd').text();
$('#ctl00_BodyContent_lblEventTitle').after(createLinks(session_title, place, day_description, session_time_start, session_time_end));
//alert(toVcalTime(day_description, time_start));
$('#ctl00_BodyContent_tblPresentations .FieldLabel, #ctl00_BodyContent_tblPresentations .ViewHTMLLink').each(function(index) {
var talk_title = $(this).text();
var talk_start_time = $(this).closest('tr').children().first().text();
// find next tr with time
function findNextTime(baseTR)
{
var next = baseTR.next();
if (next.length == 0)
return session_time_end;
var child_text = next.children().first().text();
if (/[0-9][0-9]:[0-9][0-9]/.test(child_text))
return child_text;
return findNextTime(next); // skip this line because it doesn't contain time
}
var talk_end_time = findNextTime($(this).closest('tr'));
$(this).after(createLinks(talk_title, place, day_description, talk_start_time, talk_end_time));
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment