This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| ... | |
| "content_scripts": [ | |
| { | |
| "js": ["scripts/content.js"], | |
| "matches": [ | |
| "https://developer.chrome.com/docs/extensions/*", | |
| "https://developer.chrome.com/docs/webstore/*" | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "background": { | |
| "service_worker": "background.js" | |
| // "scripts": ["jquery.js", "my-background.js"] | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "Action Extension", | |
| ... | |
| "action": { | |
| "default_icon": { // optional | |
| "16": "images/icon16.png", // optional | |
| }, | |
| "default_title": "Click Me", // optional, shown in tooltip | |
| "default_popup": "popup.html" // optional | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // background.js | |
| chrome.action.onClicked.addListener((tab) => { | |
| chrome.scripting.executeScript({ | |
| target: {tabId: tab.id}, | |
| files: ['content.js'] | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let changeColor = document.getElementById("changeColor"); | |
| changeColor.addEventListener("click", async () => { | |
| let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); | |
| chrome.scripting.executeScript({ | |
| target: { tabId: tab.id }, | |
| func: setPageBackgroundColor, | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "permissions": [ | |
| "activeTab", | |
| "tabs" // 可以 query 到所有 tab 的 url | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| changeColor.addEventListener("click", async () => { | |
| // 撈出指定屬性的 tabs | |
| let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); | |
| chrome.scripting.executeScript({ | |
| target: { tabId: tab.id }, | |
| func: () => console.log('do something...'), | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| chrome.storage.sync.set({ key: value }).then(() => { | |
| console.log("Value is set to " + value); | |
| }); | |
| chrome.storage.sync.get(["key"]).then((result) => { | |
| console.log("Value currently is " + result.key); | |
| }); | |
| // 清除 | |
| chrome.storage.local.clear(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| chrome.webRequest.onBeforeRequest.addListener( | |
| function(details) { return {cancel: true}; }, | |
| {urls: ["*://www.evil.com/*"]}, | |
| ["blocking"] | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "permissions": ["webRequest", "storage", "declarativeNetRequest", "declarativeNetRequestFeedback"], | |
| "host_permissions": ["https://*.udemy.com/*"], |
NewerOlder