Not sure why that would be getting called on load, but have you tried to use Jquery OnClick event of the link ID?
something like this:
<script type="text/javascript">
$(document).ready(function() {
//Link click
$('#testid').on("click",
function(e) {
var heartcolor = {% LikingClick(DocumentID, CurrentUser.UserName) #%};
// do some thing
});
});
</script>
**EDIT: If Like Click is doing something like updating a database table, it will run each time the transformation loads - and if the transformation is in a repeater, it will run for each item in the repeater. The code above is just assuming the likingclick is returning a value and not updating anything. If you are updating something, you would probably need to do an ajax call.