Reputation: 23
I am developing a chrome extension which will show an alert when user clicks on facebook like button.
I'm using jQuery for this purpose but it's not working.
Here is the code
$("button").click(function(){
alert("Like");
});
I also tried this code, as the like button is inside an iframe but still no luck!
var abc = $(document).find('iframe:first').contents().find('html:first').find('body:first');
abc.find("button").click(function(){
alert("Like");
});
manifest.json (I added permissions to this file)
"permissions": [
"tabs", "http://*/*", "https://*/*", "http://*.facebook.com/", "https://*.facebook.com/"
]
Any help would be greatly appreciated??
Upvotes: 0
Views: 627
Reputation: 8201
Well the first problem might be the fact that in most cases, the 'like' is an <a>
not a button, so $('button')
would not select it. As for detecting the like
link being clicked this is all that is needed:
manifest.json
"permissions": [
"tabs","*://*.facebook.com/*"
],
"content_scripts": [{
"matches": ["*://*.facebook.com/*"],
"js": ["jquery.js","click.js"]
}]
click.js
// For most of the likes on things such as comments and pictures and all that
$('a.UFILikeLink').click(function(){
console.log('Like link was clicked somewhere');
});
// For the Like 'Button' that can be found on pages
$('input[value="Like"]').click(function(){
console.log('Like button was clicked somewhere');
});
Upvotes: 1