gpt4 book ai didi

javascript - 使用 chrome 扩展修改加载页面的 HTML

转载 作者:IT王子 更新时间:2023-10-29 02:50:52 24 4
gpt4 key购买 nike

如果页面标题包含特定文本,我如何向加载的页面添加一些 HTML 代码?

Chrome 扩展对我来说是新领域,非常感谢您的帮助。

最佳答案

引用资料:

您可以将以下代码作为引用,添加一些HTML代码。

list .json

此文件将内容脚本注册到扩展。

{
"name":"Inject DOM",
"description":"http://stackoverflow.com/questions/14068879",
"version":"1",
"manifest_version":2,
"content_scripts": [
{
"matches": ["http://www.google.co.in/*","https://www.google.co.in/*"],
"js": ["myscript.js"]
}
]
}

myscript.js

Google 页面添加按钮的简单脚本

// Checking page title
if (document.title.indexOf("Google") != -1) {
//Creating Elements
var btn = document.createElement("BUTTON")
var t = document.createTextNode("CLICK ME");
btn.appendChild(t);
//Appending to DOM
document.body.appendChild(btn);
}

输出

您会看到一个添加到所需页面的按钮

enter image description here

关于javascript - 使用 chrome 扩展修改加载页面的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14068879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com