如何使用Chrome文档中的文件而不是URL

How to use files from the Chrome document instead of a URL?

本文关键字:URL 文件 何使用 Chrome 文档      更新时间:2024-04-28

我是一个大傻瓜,所以我会尽我所能解释这一点。总之,我正在学习扩展开发的步骤,我想把Greasemonkey脚本和Firefox插件中的元素融合在一起。到目前为止,我已经完成了一些工作,但我似乎不知道如何从脚本指向Chrome:Skin文件夹来制作图像和CSS文件
当前代码为:

var newstyle = document.createElement('link');
newstyle.rel = 'stylesheet';
newstyle.href = 'http://example.com/test.css';
newstyle.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(newstyle);
function main(){
var assets = Math.floor(Math.random()*8);
$('<div id="jumpFloatingButton" style="width:80px;height:30px;background-color:#21a0f1;background-image:url(http://colourlovers.com.s3.amazonaws.com/images/patterns/2757/2757110.png);position:fixed;right:0px;bottom:0px;background-attachment: scroll;cursor: pointer;"></div>').insertAfter('body *:last');
$('<div id="jumpFloating" style="width:400px;height:500px;position:fixed;bottom:30px;right:0px;border:1px solid black;background-image:url(http://colourlovers.com.s3.amazonaws.com/images/patterns/2757/2757110.png);"><ul id="jumpFloatingList" style="overflow:auto;max-height:500px;max-width:400px;margin-left:0px;"></ul></div>').insertAfter('#jumpFloatingButton');

上面代码中的链接是从其他来源链接的文件的示例。我想知道的是,如何从加载项的文件夹中而不是其他URL中创建链接点?类似:

newstyle.href = 'chrome://folder/skin/overlay.css';

$('<div id="jumpFloatingButton" style="width:80px;height:30px;background-color:#21a0f1;background-image:url(chrome://folder/skin/image.jpg);position:fixed;right:0px;bottom:0px;background-attachment: scroll;cursor: pointer;"></div>').insertAfter('body *:last');

我使用Netbeans。我的舱单

content file jar:chrome/file.jar!/content/
skin special classic/1.0 jar:chrome/special.jar!/skin/ contentaccessible=yes

我试过

var newstyle = document.createStyleSheet('overlay.css');
newstyle.rel = 'stylesheet';
newstyle.href = 'chrome://nb/skin/overlay.css';
newstyle.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(newstyle);

添加document.createStyleSheet会修复它吗?我的编辑

$('<div id="imagestack" style="width:304px;height:64px;background-image:url("chrome://special/skin/nav.png");

您需要将chrome.manifest中的chrome://folder/标记为可从web访问,否则网页将无法加载它。我看到您已经尝试过了,但您将contentaccessible=yes添加到了skin条目中。文件上写着:

contentaccessible标志仅适用于内容包:区域设置或外观注册无法识别它。但是,匹配的语言环境和皮肤包也将暴露在内容中。

这是因为你不能将chrome包的一部分标记为可访问网络——要么是全部(内容、皮肤和区域设置),要么什么都没有。所以你的chrome.manifest应该是这样的:

content file jar:chrome/file.jar!/content/ contentaccessible=yes
skin special classic/1.0 jar:chrome/special.jar!/skin/