Created
August 16, 2016 18:49
-
-
Save szmeku/c90716ddb8dc5edeb7c008ec7fe291c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 () { | |
function loadScript(url) { | |
return new Promise((resolve) => { | |
let script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.async = false; | |
script.src = url; | |
script.onload = () => { | |
resolve('loaded'); | |
}; | |
let firstScript = document.getElementsByTagName('script')[0]; | |
firstScript.parentNode.insertBefore(script, firstScript); | |
}); | |
} | |
Promise.all([ | |
loadScript('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js'), | |
loadScript('https://cdnjs.cloudflare.com/ajax/libs/ramda/0.22.1/ramda.min.js') | |
]).then(() => { | |
let _ = R; | |
let couchSurferName = document.querySelector('.cs-inbox-thread-header-user-info h1').textContent, | |
arriveDate = moment(document.querySelector('.couch-visit__details > p').textContent.split(' - ')[0]), | |
howManyDays = Number(document.querySelector('.couch-visits-nights').textContent.match(/\d+/gi)[0]), | |
leavingDate = _.clone(arriveDate).add(howManyDays, 'day'), | |
eventTitle = `CouchSurfing ${couchSurferName}`, | |
dates = _.map( | |
_.pipe( | |
(date) => date.year(moment().year()), | |
(date) => date.format('YYYYMMDD') | |
), [arriveDate, leavingDate]).join('/'); | |
let eventParams = { | |
action: 'TEMPLATE', | |
text: eventTitle, | |
dates: dates, | |
sprop: 'name:Name&sprop=website:EventWebite', | |
sf: 'true', | |
output: 'xml' | |
}, | |
objectAsURI = (obj) => { | |
return _.pipe( | |
_.map(_.join('=')), | |
_.join('&') | |
) | |
(_.zip(_.keys(obj), _.values(obj))); | |
}, | |
googleCalendarNewEventUrl = _.concat('https://www.google.com/calendar/render?', objectAsURI(eventParams)); | |
window.open(googleCalendarNewEventUrl); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment