Skip to content

Instantly share code, notes, and snippets.

@gbrian
Last active June 27, 2018 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbrian/6f765b9e35580487b7871e4de765c653 to your computer and use it in GitHub Desktop.
Save gbrian/6f765b9e35580487b7871e4de765c653 to your computer and use it in GitHub Desktop.
function SongKickHotel(){
this.events = [];
}
SongKickHotel.prototype = {
buildHotelButton: function(href){
return $(`<a href="${href}" target="_blank">
<span class="button buy-tickets" style="
background: url('https://www.trivago.es/favicon.ico') no-repeat;
background-color: #27335f;
padding-left: 14px;
background-size: 24px;
background-position: 3px;
">Hotel</span>
</a>`);
},
buildCarButton: function(href){
return $(`<a href="${href}" target="_blank">
<span class="button buy-tickets" style="
background: url('https://image.shutterstock.com/image-vector/carsharing-service-icon-on-white-260nw-751422778.jpg') no-repeat;
background-color: #ffffff;
padding-left: 14px;
background-size: 47px;
background-position: -6px;
back: 10px 10px;
color: #27335f;
">Cabify</span>
</a>`);
},
addHotelButton: function(url, after){
this.buildHotelButton(url).insertAfter(after);
},
addCarButton: function(url, after){
this.buildCarButton(url).insertAfter(after);
},
findEvents: function(){ return $('.event-listings li').filter((i,el) => $(el).find('.venue-name a').length);},
init: function(){
var oThis = this;
this.location = $('.fn.org').text();
this.findEvents().toArray().map(el => $(el))
//.slice(0,1)
.map(jel => oThis.initEvent(jel));
},
initEvent: function(jel){
var oThis = this;
oThis.clean(jel);
var def = jQuery.Deferred();
$.get(jel.find('.venue-name a').get(0).href)
.then(html => def.resolve({
jel,
adr: oThis.buildAddress($(html).find('.venue-hcard')),
after: jel.find('p').get(1),
date: oThis.parseTime(jel.find('time').attr("datetime"))
}));
def.then(ev => oThis.enrichEvent(ev));
return def;
},
clean: function(jel){
jel.find('button[value="Interested"]').parent().remove();
},
buildAddress: function(hcard){
return `${hcard.find('span:first').text()}`;
},
enrichEvent: function(ev){
this.events.push(ev);
this.addHotelButton(this.getUrl(ev), ev.after);
this.addCarButton(this.getUrl(ev), ev.after);
},
getUrl: function(ev){
return `https://www.google.com/maps/?q=hotel in ${ev.adr.replace(/\s+/mg, "+")}`;
},
parseTime: function(dt){
return dt;
}
};
var after = $($('.event-listings li').get(1)).find('p').get(1)
var sh = new SongKickHotel()
sh.init()
//sh.addHotelButton(after)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment