我正在使用Chrome扩展程序取代Google徽标。我已经在主页上成功更改了它,但是注意到常规徽标仍然显示在newtab窗口中。我需要找到一种方法来执行一些JavaScript来将Google徽标的来源替换为新徽标。这是我正在使用的一些代码。
这是Manifest.json
{
"update_url": "https://clients2.google.com/service/update2/crx",
"manifest_version": 2,
"name": "glogochange",
"description": "blabla",
"version": "1.0",
"content_scripts": [
{
"run_at": "document_start",
"matches": [
"https://*.google.com/*"
],
"css": [
"style.css"
],
"js": [
"script.js"
]
}
],
"web_accessible_resources": [
"newlogo.png"
]
}
这是JavaScript
function DoIT() {
var domain, path, button, logo, ilogo, text, logourl;
domain = window.location.host;
path = window.location.pathname;
logo = document.getElementById("hplogo");
ilogo = '//*[@id="logo"]/img';
logourl = chrome.runtime.getURL("newlogo.png");
button = '//*[@id="tsf"]/div[2]/div[3]/center/input[1]';
text = "cool Search";
if(domain == "www.google.com" && path == "/") {
XPath(button).value = text;
logo.srcset = logourl;
logo.width = 292.5;
logo.height = 133.5;
logo.style.display = "block";
} else if(domain == "www.google.com" && path == "/search") {
XPath(ilogo).width = 120;
XPath(ilogo).height = 54;
XPath(ilogo).srcset = logourl;
XPath(ilogo).style.display = "block";
} else if(domain == "www.google.com" && path == "/webhp") {
XPath(button).value = text;
logo.width = 292.5;
logo.height = 133.5;
logo.srcset = logourl;
logo.style.display = "block";
}
}
我尝试更改清单,包括:
"permissions": [
"https://*/*",
"http://*/*",
"tabs"
]
并且无法在newtab屏幕上“注入”它。有人可以帮我们解决这个问题吗?