2

Instagram Like (heart) auto click Post Bookmarklet

Objective: Click all "Like" heart on page http://www.gramfeed.com/instagram/tags#photo

Here is the code I was working with. This one worked on another site,

var a = document.getElementsByTagName('a'); var b = []; for(var i=0, len = a.length; i < len; i++){ if(a[i].id.indexOf('like') !== -1){b.push(a[i]) } }; for(var i=0, len = b.length; i < len; i++){ b[i].click() };
Aldwoni
  • 1,168
  • 10
  • 24
DASH006
  • 23
  • 1
  • 1
  • 4
  • What errors are you getting in your console? Here's one I bet you're getting: [`Uncaught TypeError: Object 'etc' has no method 'onClick'`](http://jsfiddle.net/FUMv8/). – Daedalus May 20 '12 at 01:18
  • I edited the above to show a screenshot of what I'm trying to click on, I dunno if the element id is wrong, there are no errors in console – DASH006 May 20 '12 at 13:17

1 Answers1

0

The following should work; I've tested it on my end, and it likes the hearts(though that doesn't work since I'm not logged in, etc).

javascript:(function(){for(i=0;i<document.getElementsByTagName('img').length;i++){if((' '+document.getElementsByTagName('img')[i].className+' ').indexOf(' liker ')> -1){document.getElementsByTagName('img')[i].click();}}})();

As to the class checking 'function', credit where credit is due in regards to this answer.

Update

javascript:(function(){for(i=0;i<document.getElementsByTagName('img').length;i++){if((' '+document.getElementsByTagName('img')[i].className+' ').indexOf(' liker ')>-1){var t=document.getElementsByTagName('img')[i];if(document.dispatchEvent){var o=document.createEvent('MouseEvents');o.initMouseEvent('click',true,true,window,1,1,1,1,1,false,false,false,false,0,t);t.dispatchEvent(o)}else if(document.fireEvent){t.fireEvent('onclick')}else if(t.click()){t.click()}}}})();

I am still unsure if the above code will really work, but it has so far 'worked' in jsfiddle(drag link to button bar, click link in button bar, observe console).

Community
  • 1
  • 1
Daedalus
  • 7,586
  • 5
  • 36
  • 61
  • @DASH006 Which part specifically? – Daedalus May 20 '12 at 08:39
  • @DASH006 Replacing .onClick() with .click() should work with your current code; .onClick() is not a method for the HTML element object, .click() however is. If you want to reduce your code, you're going to have to use the jquery javascript library. You include the library in your header, and use it accordingly. As to why it won't work, that's because some sites use these libraries. If you don't know what a library is, that is likely why it won't work on yours. – Daedalus May 20 '12 at 19:53
  • @DASH006 And by the last sentence, I mean that if you don't know what one is, you are likely not using one, and thus it doesn't have what is needed to work. – Daedalus May 20 '12 at 20:03
  • I replace the on click with the.click and the click is still not performed. – DASH006 May 21 '12 at 10:33
  • @DASH006 I'll try and get to work on a solution for you then, but it can't be tonight; it's almost 4am for me. Also, could you update your code with your current code? And a link to the specific page would be nice as well. – Daedalus May 21 '12 at 10:38
  • The page is http://www.gramfeed.com/instagram/tags#photo but before the hearts show up you have to click the list icon, next to the grid icon so the hearts appear. – DASH006 May 21 '12 at 10:40
  • Its basically a javascript bookmarklet that will click all the hearts – DASH006 May 21 '12 at 10:42
  • After Login The hearts still are not clicked, same problem as the code I originally used. – DASH006 May 22 '12 at 00:13
  • @DASH006 The problem may be with the site, according to the errors I'm getting in the console log. – Daedalus May 22 '12 at 00:16
  • It works in Firefox but not in safari, thats the only problem i can see, can we edit it to get it to work in safari? – DASH006 May 22 '12 at 06:37
  • IT WORKS HOOORAY!! THANK YOU, TOP CODE WORKS FOR FIREFOX, BOTTOM FOR SAFARI! – DASH006 May 22 '12 at 11:12