我知道這個問題已被問過,但我的代碼仍然無法正常工作,我不知道爲什麼;我試圖做一個Chrome擴展,改變類的profilePic IMG「的圖像與點擊使用jquery更改img的src
這是我到目前爲止的代碼: background.js:
chrome.browserAction.onClicked.addListener(function (tab) {
if (tab.url.indexOf("https://www.facebook.com") != -1) {
chrome.tabs.executeScript(tab.id, {
"file": "contentscript.js"
}, function() {
console.log("Script Executed");
});
}
});
contentscript.js:
alert("alert");
$(document).ready(function() {
$(document).find('.profilePic img').attr('src', 'second.jpeg')
});
的manifest.json
{
"name": "stuff",
"version": "0.0.1",
"manifest_version": 2,
// Recommended
"description": "replaces fb profile pictures",
"web_accessible_resources": [
"second.jpeg"
],
"background":{
"scripts":["background.js"],
"page": "background.html"
},
"permissions":["https://www.facebook.com/*"],
"content_scripts": [
{
"matches":["http://www.facebook.com/*"],
"js":["jquery-2.1.4.min.js","background.js","contentscript.js"],
"all_frames": true,
"run_at": "document_start"
}
],
"browser_action": {
"default_icon": "icon.png",
"default_title": "testing"
}
}
警報彈出就好了,但沒有什麼改變......我有jquery已經包含在我的清單 編輯:我認爲這是上傳jquery的問題,因爲控制檯日誌錯誤是'$未定義'。抱歉!完全初學者在這裏:(
您在一處提到'contentscript.js',而在另一處提到'content.js'。 – jfriend00
向我們展示整個content.js代碼請 – Zl3n
需要查看HTML。我想我知道這個問題,只需要確定。 –