4

I've created a custom tumblr like button and have put the iframe above it to make it clickable but I must have done something wrong because it doesn't work.. I haven't quite understood how it works sorry if this is a dumb question! I know you have to create your custom button and just put tumblr's iframe above but...

window.onload = function() {
  document.body.insertAdjacentHTML('beforeEnd', '<iframe id="my-like-frame" style="display:none;"></iframe>');
  document.addEventListener('click', function(event) {
    var myLike = event.target;
    if (myLike.className.indexOf('like') > -1) {
      var frame = document.getElementById('my-like-frame'),
        liked = (myLike.className == 'liked'),
        command = liked ? 'unlike' : 'like',
        reblog = myLike.getAttribute('data-reblog'),
        id = myLike.getAttribute('data-id'),
        oauth = reblog.slice(-8);
      frame.src = 'http://www.tumblr.com/' + command + '/' + oauth + '?id=' + id;
      liked ? myLike.className = 'like' : myLike.className = 'liked';
    };
  }, false);
};
.controls i {
  height: 10px;
  width: 10px;
  background: #ce9c87;
  border-radius: 100%;
  padding: 5px;
  display: block;
  overflow: visible;
  text-align: center;
  color: #fff;
  -webkit-transition: .2s ease;
  -moz-transition: .2s ease;
  -o-transition: .2s ease;
  transition: .2s ease;
}

.controls {
  float: right;
  margin-right: 10px;
}

.controls a {
  position: relative;
  display: inline-block;
  overflow: hidden;
  padding: 1px 2px;
  width: auto;
  height: auto;
  margin-left: 1em;
  float: right;
}

.like {
  position: relative;
  display: inline-block;
  overflow: hidden;
  padding: 1px 2px;
  width: auto;
  height: auto;
  margin-left: 1em;
  float: right;
  cursor: pointer;
}

.controls .like .liked+i,
.controls i:hover {
  color: #ce9c87;
  background-color: #fff;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<div class="controls">
  <a href="{Permalink}" class="permalink">
    <i class="fa fa-bookmark-o" aria-hidden="true"></i>
  </a>
  <a href="{ReblogURL}" target="_blank" class="reblog">
    <i class="fa fa-retweet" aria-hidden="true"></i>
  </a>
  <div class="like" data-reblog="{ReblogURL}" data-id="{PostID}">{LikeButton}
    <i class="fa fa-heart-o" aria-hidden="true"></i>
  </div>
</div>

If it isn't clear here is the link to the page..

Thank you!

Maëlle
  • 629
  • 1
  • 11
  • 25
  • If Tumblr wanted to you to be able to customize their Like buttons, they would provide you with options to do so. I would strongly recommend against what you are trying to do here, because this is likely to trigger some sort of “click jack” detection at some point. And if that happens via some automated tool/algorithm, it might lead to all likes gathered that way simply being removed. – CBroe Jun 06 '17 at 12:36
  • 3
    I think it's help for you. https://stackoverflow.com/questions/21708662/customise-tumblrs-new-like-button-iframe-likebutton – Hardik Chapla Jun 06 '17 at 12:37
  • @CBroe Thank you for the documented reply, I didn't quite get what I risked by changing the like button though? Because they have provided this {LikeButton} thingy and a lot of accounts are changing it so I'm not sure it would be wrong?.. – Maëlle Jun 06 '17 at 14:02
  • What are you using the script for is that what tumblr does or your own? – chloe784 Jun 09 '17 at 10:28
  • @chloe784 This is my own code – Maëlle Jun 09 '17 at 10:40
  • What is the point of the script? – chloe784 Jun 09 '17 at 10:49
  • I want the like button to work on the index page @chloe784 – Maëlle Jun 09 '17 at 10:51
  • The like button does work on the index page without a script. That question linked in the comments above details how to achieve that. – chloe784 Jun 09 '17 at 11:25
  • You seem to have the like button working now. How did you solve your problem? You should post how you solved it as an answer and then accept it. – chloe784 Jun 21 '17 at 09:49
  • 1
    @chloe784 I've found a way but I removed the background.. And also for now it's not working on every browser so I'm trying to fix this and then I'll post an answer! Thank you – Maëlle Jun 21 '17 at 11:55

1 Answers1

4

Possibly the problem you are having is because tumblr no longer allows you to like posts on any of your own blogs. You can work around this by opening the console and clicking your like button and if this error occurs it means your like button works but tumblr is preventing you from liking your own posts.

enter image description here

chloe784
  • 609
  • 3
  • 15