使用Chrome扩展程序更改所有文字的背景颜色

时间:2015-10-13 21:38:23

标签: javascript google-chrome-extension

我刚开始学习chrome扩展的基础知识。使用“页面更改”扩展名(可更改整个网页的背景颜色)作为模板,我想制作一个更改所有文字背景颜色的扩展名。

来自https://developer.chrome.com/extensions/samples的页面更新: background.js:

" "

的manifest.json:

0

我可以更改以下代码行来改为选择所有文字吗?

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
  // No tabs or host permissions needed!
  console.log('Turning ' + tab.url + ' red!');
  chrome.tabs.executeScript({
    code: 'document.body.style.backgroundColor="red"'
  });
});

我尝试将其更改为:

{
  "name": "Page Redder",
  "description": "Make the current page red",
  "version": "2.0",
  "permissions": [
    "activeTab"
  ],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "browser_action": {
    "default_title": "Make this page red"
  },
  "manifest_version": 2
}

with content.css:

chrome.tabs.executeScript({
        code: 'document.body.style.backgroundColor="red"'

但没有成功。

0 个答案:

没有答案