我知道这个问题已被问过,但我的代码仍然无法正常工作,我不知道为什么;我试图做一个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。我想我知道这个问题,只需要确定。 –