Created
April 14, 2016 20:56
-
-
Save tregusti/3d9cddef75980308c4a98877cea4ca4c to your computer and use it in GitHub Desktop.
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
(function() { | |
// Run this script in the console to add the foo cae event to the calendar. | |
'use strict'; | |
let url = document.location.href; | |
let title = document.querySelector('h1').textContent; | |
let timestamp = document.querySelector('.eventtime p').textContent.trim(); | |
let datematch = timestamp.match(/, (\w+) (\d+)/); | |
let from = new Date(); | |
from.setMonth('January Februari March April May June July August September October November December'.split(' ').indexOf(datematch[1])); | |
from.setDate(datematch[2]); | |
from.setHours(timestamp.match(/(\d+)\.\d+ -/)[1]); | |
from.setMinutes(timestamp.match(/\d+\.(\d+) -/)[1]); | |
from.setSeconds(0); | |
from.setMilliseconds(0); | |
let to = new Date(from); | |
to.setHours(timestamp.match(/- (\d+)\.\d+/)[1]); | |
to.setMinutes(timestamp.match(/- \d+\.(\d+)/)[1]); | |
let columns = Array.from(document.querySelectorAll('.column')); | |
let text = columns.map(element => element.querySelector(':scope > p').textContent).join(' ').replace(/\n/g, '\\n'); | |
let card = ` | |
BEGIN:VCALENDAR | |
VERSION:2.0 | |
BEGIN:VEVENT | |
DTSTART:${format(from)} | |
DTEND:${format(to)} | |
SUMMARY:${title} | |
DESCRIPTION:${text} | |
LOCATION:Foo Café | |
URL;VALUE=URI:${url} | |
END:VEVENT | |
END:VCALENDAR | |
`.trim(); | |
document.location = `data:text/calendar,${encodeURIComponent(card)}`; | |
function format(date) { | |
return date.toISOString().replace(/\.\d\d\dZ/, 'Z').replace(/[-:\.]/g, ''); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment