We all know that JS is running on the client, so if we write a browser, it is bound to download down the source code to add JS. Unfortunately we do not have this ability. Fortunately, Chrome's extensions can help us do this.
This article will be a primer on Chrome plug-in development, enabling the use of chrome extensions to run our JS functionality on the target page. Details about the Chrome extension are available on the website.
Development tools are simple, Notepad is OK, and of course there is a Chrome browser.
Create a new folder, for example, HelloWorld
Then create a text file, as the extension's configuration file, so the file name is Manifest.json, note that the extension is JSON, and then enter the following content.
{ "name": "First Chrome plugin", "Manifest_version": 2, "version": "1.0", "description": "My first chrome plugin, Not bad ", " Browser_action ": { " Default_icon ":" 1.png "} }
1.png, just drag a picture to come in OK. It is also important to note that the text file needs to be saved with the UTF8 character set.
Your first Chrome extension is complete.
What the? It's done? So fast?
Yes, open chrome, open the menu, find the extender options, my extensions under wrench, tools, and so on.
Click to load the extension you are developing
As you can see, your 1.png has been placed next to the address bar as an icon. It's just that it's no function.
Now let's add the HelloWorld. Add a few lines of code to the manifest file.
"Content_scripts": [ {" matches": ["http://www.aaaaa.com/*"], "JS": ["Myscript.js"] } ]
Note that the previous code is separated by commas.
You can see that we have added a new content, that is content_scripts, detailed introduction should go to see the official documents, I briefly introduced here, Content_scripts is run in the Open page script, can get the entire page of the DOM object, So you can use the script to manipulate the page.
Create a new JS file Myscript.js, inside the code is very simple.
Alert ("HelloWorld");d ocument.body.style.backgroundcolor= "Gray";
Reload the plugin on the Extensions page to see the effect.
When I opened the Baidu, Oh,my god!
After clicking OK
The ugly explosion has wood, but it does turn gray. In addition Baidu, we can not change a background transparent PNG do logo?