想法:基于环境的条件Chrome主题 [英] Idea: Conditional Chrome theme based on environment

本文介绍了想法:基于环境的条件Chrome主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一名Web开发人员,我不断在不同环境(本地,分期,测试,生产)中开展项目。我主要从事Drupal项目。通过浏览网站,我无法告诉你从本地到生产的次数。然后不小心改变了一个真正只在本地环境中改变的生产环境。



所以这里有一个想法:Chrome主题根据



例如:on local.mysite.com * 浏览器chrome应为绿色,在分段.mysite.com * 应该是蓝色的,而在 mysite.com * 上,颜色应该是标准的铬灰色。



这可以避免许多在不同环境中工作的人的混乱。不仅对开发人员而言,也是内容的人。



可惜的是,我不知道如何使用这种行为来编写Chrome主题。

解决方案

主题不是动态的,所以解决方案并不直接。

可以使用管理API 。至少需要三个扩展名:




  • 切换主题的主要扩展名。

  • 主题#1 ,主题#2等(每个附加主题额外的扩展名)。



如何




  1. 创建主题 - 请参阅 Chrome主题文件

  2. 绑定 chrome.tabs.onUpdated 事件来监听选项卡更改,并可能将散列中的已知主题选项卡的状态(由tabId )。使用删除运算符时,不要忘记删除该标签的URI不是特殊的tabId。

  3. 创建另一个扩展程序,使用后台脚本

    添加 chrome.tabs.onActivated 警告:请参阅下面的 事件,以监听选项卡更改。此事件传递一个windowId和tabId。使用在步骤2中创建的哈希来检查主题是否必须更改。

  4. 如果URL与某个模式匹配,请使用 chrome.management.setEnabled 方法。

步骤3-4的替代方法:使用内容脚本调用方法的背景页面。 匹配模式可以在清单文件,在content_scripts匹配部分。



警告 onActivated 事件是不支持Chrome 18 。在Chrome 18之前,该事件称为 onActiveChanged



扩展名如步骤2-4需要以下权限




As a web developer I'm constantly working on projects in different environments (local, staging, testing, production). I mostly work on Drupal projects. I can't tell you the number of times I've been led from local to production by just browsing the site. And then accidentally changing a setting on production that was really only supposed to be changed on my local environment.

So here's an idea: A Chrome theme that changes color depending on the sub domain of a site.

For example: on local.mysite.com* the browser chrome should be green, on staging.mysite.com* it should be blue, and on mysite.com* the color should be standard chrome grey.

This could avoid a lot of confusion for a lot of people working in different environments. Not only for developers, also for "content" people.

Sadly, I have no idea how to code a Chrome theme with that kind of behavior.

解决方案

Themes are not dynamic, so the solution is not straightforward.
It's possible to create the feature using the management API. At least three extension are needed:

  • The main extension for switching themes.
  • Theme #1, theme #2 etc (an extra extension for every additional theme).

How to

  1. Create a theme - See the Chrome themes documentation.
  2. Bind a chrome.tabs.onUpdated event to listen for tab changes, and possibly save the state of known "theme-tabs" in a hash (by tabId). Don't forget to remove the tabId when the tab's URI is not "special" any more, using the delete operator.
  3. Create another extension, with a background script.
    Add a chrome.tabs.onActivated Warning: See below event, to listen for tab changes. This event is passed a windowId and tabId. Use the hash, created in step 2, to check whether the theme has to be changed or not.
  4. If the URL matches a certain pattern, activate the new theme using the chrome.management.setEnabled method.

Alternative approach for step 3-4: Use Content scripts to call a method the background page. The match patterns can then be set in the manifest file, at the "content_scripts", "matches" section.

Warning: The onActivated event was not supported prior Chrome 18. Before Chrome 18, the event was called onActiveChanged.

The extension as described in steps 2-4 requires the following permissions:

这篇关于想法:基于环境的条件Chrome主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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