Example code for a Chrome Extension

Here's an example code for a simple Chrome Extension that replaces all occurrences of the word "lock" with "unlock" on a web page:

manifest.json:

{
  "manifest_version": 2,
  "name": "Locksmith Extension",
  "version": "1.0",
  "description": "Replace all occurrences of 'lock' with 'unlock'.",
  "permissions": ["activeTab"],
  "content_scripts": [{
    "matches": ["http://*/*", "https://*/*"],
    "js": ["content.js"]
  }]
}


content.js:

// Replace all occurrences of 'lock' with 'unlock'
document.body.innerHTML = document.body.innerHTML.replace(/lock/gi, 'unlock');

 

In this example, the manifest.json file is used to declare the name, version, and permissions of the extension, as well as to specify the content script that will be injected into web pages. The content.js file is the content script that will be executed on web pages that match the matches property in the manifest.

Note that this is a very basic example and most extensions will be much more complex. Also, keep in mind that the activeTab permission is a powerful permission that allows the extension to access and modify the content of the currently active tab. Use this permission carefully and only when necessary.

Related Articles

- All From ChatGPT
PLG_GSPEECH_SPEECH_BLOCK_TITLE