歌剧扩展
简而言之:在注入的 Opera 扩展脚本中获取 head 元素的最快方法是什么? (比等待 DOMContentLoaded 更快)
我将一堆样式插入到加载的页面中,并且我不等待 DOMContentLoaded (因为用户希望在页面加载时看到渲染的 css,就像 usercss 一样)。
所以我只获取 head 元素(document.getElementsByTagName("head")[0] 或 document.head)并将样式元素插入其中;这适用于大多数网站,但我最近发现它不适用于维基百科,因为我无法在不等待 DOMContentLoaded 的情况下获取 head 元素。
附: 我知道 Opera 扩展是在任何其他脚本之前插入的,所以这是否意味着插入脚本时不会加载 head 元素?那么为什么它在某些网站上有效?
To put it simple: What's the fastest way to get the head element in an injected opera extension script ? (faster than waiting for DOMContentLoaded)
I insert a bunch of styles into loaded pages, and I'm not waiting for DOMContentLoaded (because the user wants to see the rendered css when the page loads, just like an usercss).
So I just get the head element (document.getElementsByTagName("head")[0] or document.head) and insert style elements into it; this works on most websites but I recently found out that it doesn't work on wikipedia because I can't get the head element without waiting for DOMContentLoaded.
PS:
I know that Opera extensions are inserted before any other script so does that mean that the head element isn't loaded when the script is inserted ? So why does it work on some sites ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,您可以立即在扩展程序的脚本中执行 document.documentElement.appendChild() 。浏览器应该可以很好地解决问题。
AFAIK, you can just do document.documentElement.appendChild() right away in your extension's script. The browser should sort things out just fine.