LoginSignup
0
1

ページの背景を変更するchrome拡張機能作り方

Last updated at Posted at 2023-10-05

まずmanifest.jsonを作成します

manifest.json
{
  "name": "ページ 黒",
  "options_page": "options.html",
  "action": {},
  "manifest_version": 3,
  "version": "1.0",
  "description": "ページを黒にします。それにはこの拡張機能をクリックしてください",
  "permissions": [
    "activeTab",
    "scripting"
  ],
  "background": {
    "service_worker": "background.js"
  }
}

次に、background.js作成

background.js
function yu() {
  document.body.style.backgroundColor = 'black';//ここのblackを変えると他の色にできる
}

chrome.action.onClicked.addListener((tab) => {
  chrome.scripting.executeScript({
    target: { tabId: tab.id },
    function: yu
  });
});

そして拡張機能を押すと..
d.gif
ということでした

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1