Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created June 14, 2012 05:00
Show Gist options
  • Save pamelafox/2928064 to your computer and use it in GitHub Desktop.
Save pamelafox/2928064 to your computer and use it in GitHub Desktop.
TxJS Hearty User Extension
// Also requires jQuery pasted in the top in Chrome
function loadHearts() {
$('#speakers').hide();
$('#scene').hide();
$('#schedule td').each(function() {
var $talkCell = $(this);
var rateLink = $talkCell.find('a');
if (!rateLink.length) return;
var id = rateLink.attr('href').split('/t/')[1];
$talkCell.data('id', id);
var heart = $('<a class="heart" href="javascript:void(0);" style="color: grey; float: right;font-size: 36px;">❤</a>');
$talkCell.prepend(heart);
if (localStorage.getItem(id)) {
heartTalk($talkCell);
}
heart.on('click', function() {
if ($talkCell.data('hearted') == 'true') {
unheartTalk($talkCell);
} else {
heartTalk($talkCell);
}
})
});
}
function unheartTalk($talkCell) {
$talkCell.data('hearted', 'false');
$talkCell.find('.heart').css({'color': 'grey'})
}
function heartTalk($talkCell) {
$talkCell.data('hearted', 'true');
$talkCell.find('.heart').css({'color': '#C20000'})
}
function storeHearts() {
$('#schedule td').each(function() {
if ($(this).data('hearted') == 'true') {
localStorage.setItem($(this).data('id'), 'hearted');
} else {
localStorage.removeItem($(this).data('id'));
}
});
}
window.onunload = storeHearts;
loadHearts();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment