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