2013-05-05 127 views
0

我正在開發一個Chrome擴展,它將顯示一個警告,當用戶點擊Facebook像按鈕。檢測鼠標點擊Facebook像按鈕(從Chrome擴展)

我爲此目的使用jQuery,但它不工作。

下面是代碼

$("button").click(function(){ 
alert("Like"); 
}); 

我也試過這個代碼,類似按鈕的iframe內,但仍然沒有運氣!

var abc = $(document).find('iframe:first').contents().find('html:first').find('body:first'); 
abc.find("button").click(function(){ 
alert("Like"); 
}); 

manifest.json的(我添加權限到該文件)

"permissions": [ 
    "tabs", "http://*/*", "https://*/*", "http://*.facebook.com/", "https://*.facebook.com/" 
] 

任何幫助將不勝感激?

回答

1

那麼第一個問題可能是,在大多數情況下,'喜歡'是不是一個按鈕,所以$('button')不會選擇它。作爲檢測like鏈接被點擊,這是所有需要的:

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'); 
}); 
+0

它不工作.. :-( – 2013-05-06 04:15:52

+0

我複製了上面發佈的同樣的代碼,並且還包含了jquery.js,但是當我點擊「like button」時沒有任何反應。沒有日誌。我也用alert()替換了console.log,但仍然是n沒有發生。 – 2013-05-06 10:03:37

+0

這一個 http://s21.postimg.org/fcn8ja59j/btn.png – 2013-05-06 20:41:20