简体   繁体   English

如何使用 chrome 扩展 javascript 操作 DOM

[英]How can I manipulate the DOM using the chrome extension javascript

I want to create a chrome extension that is similar to the Toucan extension我想创建一个类似于Toucan 扩展的 chrome 扩展

For example I have this example.html without the extension例如我有这个 example.html 没有扩展名例子

When I loaded the extension of Toucan it will manipulate the DOM of the website it will change some text content of the当我加载 Toucan 的扩展时,它会操纵网站的 DOM,它会更改网站的一些文本内容

tag.标签。 Unfortunately, I don't have any idea how to achieve this in javascript. (I have knowledge about content, background and popup in manifestation json.)不幸的是,我不知道如何在 javascript 中实现这一点。(我了解 json 中的内容、背景和弹出窗口。)

在此处输入图像描述

The general direction is to use a content script (defined in the extension manifest), that contains something like the following:总体方向是使用内容脚本(在扩展清单中定义),其中包含如下内容:

let paragraphs = Array.from(document.getElementsByTagName("p"));

Then, you can modify the first paragraph using然后,您可以使用修改第一段

paragraphs[0].innerText = "new text";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM