javascript Chrome 扩展:在加载页面之前替换 HTML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8534446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome extension: Replace HTML before loading the page
提问by Citizen SP
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. Let's say I open www.stackoverflow with Chrome and want to replace the following line of code:
在阅读了一些信息后,我认为问题是如何操作 DOM。假设我用 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?
我的问题不是这样做是否明智,而是如何做到这一点?
采纳答案by Badr Hari
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 或运行任何其他脚本之前。
http://code.google.com/chrome/extensions/content_scripts.html
http://code.google.com/chrome/extensions/content_scripts.html