简体   繁体   English

Chrome 扩展:在加载页面之前替换 HTML

[英]Chrome extension: Replace HTML before loading the page

I have a question about how to change web pages with a Chrome extension.我有一个关于如何使用 Chrome 扩展程序更改网页的问题。

After reading some info I think the question is how to manipulating the DOM.在阅读了一些信息后,我认为问题是如何操作 DOM。 Let's say I open www.stackoverflow with Chrome and want to replace the following line of code:假设我用 Chrome 打开 www.stackoverflow 并想替换以下代码行:

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

and replace it with:并将其替换为:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>

My question is not if it's a smart thing to do, but how to do this?我的问题不是这样做是否明智,而是如何做到这一点?

Try to modify you manifest's file run_at string.尝试修改清单文件的 run_at 字符串。

In the case of "document_start", the files are injected after any files from css, but before any other DOM is constructed or any other script is run.在“document_start”的情况下,文件在来自 css 的任何文件之后注入,但在构建任何其他 DOM 或运行任何其他脚本之前。

https://developer.chrome.com/docs/extensions/mv2/content_scripts/ https://developer.chrome.com/docs/extensions/mv2/content_scripts/

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

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