简体   繁体   English

Chrome 扩展程序

[英]Chrome Extension

I am trying to create a chrome extension that once I click a certain button in my extension, it will highlight the current tab.我正在尝试创建一个 chrome 扩展,一旦我单击扩展中的某个按钮,它将突出显示当前选项卡。 However, I am having a little bit of trouble.但是,我遇到了一些麻烦。

Right now I have document.getElementById("button").addEventListener("click", function () {} in my JS file, but I can't seem to find a solution on how to colour the current tab. I know something is supposed to go in {}, but I am not exactly sure what. Any help would be appreciated.现在我的 JS 文件中有document.getElementById("button").addEventListener("click", function () {} ,但我似乎找不到如何为当前选项卡着色的解决方案。我知道一些应该进入 {},但我不确定是什么。任何帮助将不胜感激。

As of this writing, there are no methods or properties available as part of the tabs API for Chrome Extensions that allow you to set/modify the color of a tab.在撰写本文时, Chrome 扩展的tabs API中没有可用的方法或属性允许您设置/修改选项卡的颜色。

Thus, this is not (currently) possible to accomplish from within the extension context within Chrome.因此,这(目前)不可能从 Chrome 的扩展上下文中完成。

EDIT : On second thought, this actually might be possible, albeit in a bit of a shoehorned manner.编辑:再想一想,这实际上是可能的,尽管有点勉强。 By adding the example function to get the current tab (and then its id property), you can pass it to the chrome.tabs.group() method , then access the returned tabGroup in the callback parameter to set its color property :通过添加示例函数来获取当前选项卡(然后是其id属性),您可以将其传递给chrome.tabs.group()方法,然后在callback参数中访问返回的tabGroup以设置其color属性

chrome.tabs.group(
    options: {
        tabIds: (await getCurrentTab()).id
    },
    callback: function(groupId) {
        chrome.tabGroups.update(
            groupId: groupId,
            updateProperties: {
                color: "red"
            }
        );
    }
);

However, it's not clear if the resulting visual meets your requirements or not.但是,尚不清楚生成的视觉效果是否符合您的要求。

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

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