我可以为Chrome页面(下载,扩展等)制作Google Chrome扩展程序吗? [英] Could I make a Google Chrome extension for chrome pages (downloads, extensions etc)?

查看:145
本文介绍了我可以为Chrome页面(下载,扩展等)制作Google Chrome扩展程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个非常简单的扩展程序,稍微改变下载页面的外观。更改历史记录页面可能也很有趣,但这是为了以后。



有没有办法做到这一点?



我尝试制作 内容脚本 扩展程序,chrome:// downloads作为匹配位于清单中上传.json 。 Chrome不会允许这样做,并且在打包扩展时出现错误。



还有其他简单方法吗?它必须简单,因为所有的变化都很简单,因为所有的 chrome:// 页面都是用HTML,JS和CSS构建的。

编辑

使用后台脚本稍微尝试后...



我无法获得 chrome.tabs.executeScript 工作!我添加了 background.html

  chrome.browserAction.onClicked。 addListener(function(tab){
alert(this.document.body.innerHTML);
alert(chrome.tabs.executeScript(null,{
code:document.body.style。 backgroundColor ='red';
}));
});

我在 manifest.json 添加一个(不可见的)'浏览器动作按钮':

 ,browser_action:{
/ *popup :background.html,* /
name:Alter page
}

onClicked 事件触发两个警报(第一个是 background.html 的正文,第二个未定义)。但是代码(带有 document.body.style.backgroundColor ='red'; 的字符串)不会执行!当然,这样的扩展没有调试=)



任何提示任何人?我试图获取该标签的 window.document 不是 background.html window.document !)。注入脚本(这就是 chrome.tabs.executeScript 应该做的)应该这样做。



PS

我从 make_page_red / manifest make_page_red / background.html < br>
到目前为止,我的'扩展': http://hotblocks.nl/js/ downloads.rar


编辑

我发现我想用CSS来实现。我不需要注入JavaScript。这是否使它更容易?这是否有可能? =) 根据这个文档 chrome:// URL是一个无效的方案,所以它们不会匹配:


匹配模式本质上是一个以许可方案开始的URL( http https file ftp ),并且可以包含'<$

我会考虑使用'字符。 //code.google.com/chrome/extensions/override.htmlrel =nofollow>改写页面






按照要求,这是我的扩展,至少可以在加载 chrome:// downloads 时加载,尽管如我所说,我不认为你即使您知道这是您正在查看的网页,也可以修改该网页。



manifest.json

  {
name:Test,
version:0.0.1,
background_page:background.html,
permissions: [
标签

}

background.html

 < script> 
chrome.tabs.onUpdated.addListener(函数(tabId,changeInfo,tab)
{
if(tab.status ==complete)
{
alert (tab.url);
//在该页面上应该提示'chrome:// downloads',你可以
//在这里检查这个URL,然后做任何你想要的
}
});
< / script>


I'd like to make a very simple extensions that slightly alters how the Downloads page looks. Changing the History page might be interesting too, but that's for later.

Is there a way to do that?

I tried making a Content Script extension, with "chrome://downloads" as match in manifest.json. Chrome won't allow that and responds with an error when packaging the extension.

Is there another simple way? It has to be simple, because changes would be simple, because all chrome:// pages are built with HTML, JS and CSS.

edit
After trying with background scripts a little...

I can't get chrome.tabs.executeScript to work! I added in background.html:

chrome.browserAction.onClicked.addListener(function(tab) {
    alert(this.document.body.innerHTML);
    alert(chrome.tabs.executeScript(null, {
        code : "document.body.style.backgroundColor = 'red';"
    }));
});

And I added this in manifest.json to add a (invisible) 'browser action button':

    ,"browser_action": {
/*      "popup": "background.html",*/
        "name": "Alter page"
    }

The onClicked event fires both alerts (first is background.html's body, second is undefined). But the code (a string with document.body.style.backgroundColor = 'red';) doesn't execute! And ofcourse there's no debugging for extensions like this =)

Any tips anyone? I'm trying to get a hold of the tab's window.document (not background.html's window.document!). An injected script (that's what chrome.tabs.executeScript is supposed to do) should do that.

PS
I'm stealing from make_page_red/manifest and make_page_red/background.html
The 'extension' I have so far: http://hotblocks.nl/js/downloads.rar

EDIT
I found out what I want to achieve is possible with just CSS. I don't need to inject javascript. Does that make it easier? Does that make it possible? =)

解决方案

According to this documentation, chrome:// URLs are an invalid scheme so they won't be matched:

A match pattern is essentially a URL that begins with a permitted scheme (http, https, file, or ftp), and that can contain '*' characters.

I would look into using override pages instead.


As requested, here's my extension that can at least load when chrome://downloads is loaded, although as I said, I don't think you can modify the page even if you know that's the page you're viewing.

manifest.json

{
    "name": "Test",
    "version": "0.0.1",
    "background_page": "background.html",
    "permissions": [
        "tabs"
    ]
}

background.html

<script>
    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
    {
        if (tab.status == "complete")
        {
            alert(tab.url);
            // should alert 'chrome://downloads' on that page. You can 
            // check for this url here and then do whatever you want
        }
    });
</script>

这篇关于我可以为Chrome页面(下载,扩展等)制作Google Chrome扩展程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆