Last active
August 5, 2019 22:27
-
-
Save heinermann/23782e5053168f0938a6a588b18696e1 to your computer and use it in GitHub Desktop.
Rew Open House Google Calendar Integration
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
// ==UserScript== | |
// @name Rew Google Calendar Integration | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Add Open House dates for a listing to your google calendar | |
// @author Adam Heinermann | |
// @match https://www.rew.ca/properties/* | |
// @grant none | |
// @require http://code.jquery.com/jquery-3.4.1.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var dateRangeRegex = /.*(January|February|March|April|May|June|July|August|September|October|November|December) ([0-9]+)[^0-9]*([0-9]+:[0-9]+(?:AM|PM)).*to.*([0-9]+:[0-9]+(?:AM|PM))/is; | |
var address1 = $('.propertyheader-address > span').contents().text(); | |
var address2 = $('.propertyheader-secondary > li:first-child').contents().text(); | |
var title = `Open House: ${address1}`; | |
var summarybar = $('.summarybar-item').contents().text(); | |
var beds = /(\d+)\s*Bed/.exec(summarybar)[1]; | |
var baths = /(\d+)\s*Bath/.exec(summarybar)[1]; | |
var sqft = /(\d+)\s*Sqft/.exec(summarybar)[1]; | |
var type = /([^\s]+)\s*Type/.exec(summarybar)[1]; | |
var description = ` | |
### Info | |
${address1}, ${address2} | |
${$('.propertyheader-price').contents().text()} | |
${beds} Beds | ${baths} Baths | ${sqft} Sqft | ${type} | |
### Website | |
${window.location.href} | |
### Agents | |
${$('#agentPhoneModal .agentphones-details').contents().text()} | |
`; | |
var toGoogleCalDate = function(date) { | |
return `${date.toString('yyyyMMdd')}T${date.toString('HHmmss')}`; | |
}; | |
var toGoogleCalDateRange = function(month, day, fromTime, toTime) { | |
var startDate = toGoogleCalDate(Date.parse(`${month} ${day}, ${fromTime}`)); | |
var endDate = toGoogleCalDate(Date.parse(`${month} ${day}, ${toTime}`)); | |
return `${startDate}/${endDate}`; | |
}; | |
var location = `${address1.replace(/^\d+-/, '')}, ${address2}`; | |
var items = $('.listgrid-list_item > p'); | |
items.each(function() { | |
var text = $(this).contents().text(); | |
var parsed = dateRangeRegex.exec(text); | |
var dateRange = toGoogleCalDateRange(parsed[1], parsed[2], parsed[3], parsed[4]); | |
var addToCalendarText = ` | |
<a target="_blank" rel="nofollow" href="http://www.google.com/calendar/render? | |
action=TEMPLATE | |
&text=${encodeURIComponent(title)} | |
&dates=${dateRange} | |
&details=${encodeURIComponent(description)} | |
&location=${encodeURIComponent(location)} | |
">Add to Google Calendar</a> | |
`; | |
$(this).append(`<p>${addToCalendarText}</p>`); | |
}); | |
/*.filter(function(){ | |
var txt = $('p', this).contents().filter(textNodeOnly).text(); | |
});*/ | |
// Your code here... | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment