Chrome extension, 2 of APP Development Study Notes --- spoof Baidu, chrome2 ---
Chrome extension, 2 of APP Development Study Notes
Spoof Baidu
We have introduced a simple chrome extension clock. Now I will introduce a chrome extension program that spoof Baidu.
As mentioned above, the manifest. json file is used to describe this extension, which is the entrance of the entire extension and also tells chrome how to handle this extension.
Spoof Baidu:
Next we will write an extension program that spoof Baidu, hoping to have a better understanding of chrome expansion from this instance. First, let's take a look at the expansion effect, such:
We can guess that its function is to prevent you from clicking the Baidu button.
Create a new folder named "egao_baidu ). Create a new menifest. json file in the folder.
Next, let's take a look at the content of the menifest. json file.
{"Manifest_version": 2, "name": "Search buttons that are never clicked", "version": "1.0", "description ": "You will never be able to click the baidu search button", "content_scripts": [{"matches": ["*: // www.baidu.com/"], // match any of the following content: // www.baidu.com/. if your webpage is subject to URL matching, the script file will automatically execute "js": ["js/haha. js "] // the script file here is haha. js}]}
Let's take a look at some of Baidu's html source file information:
From the content of the source file, Baidu's id is su, and the following shows how to use haha. js.
From the above manifest. json file content, the main attraction is haha. js. Let's take a look at the content of this file.
Function btn_move (el, mouseLeft, mouseTop) {var leftRnd = (Math. random ()-0.5) * 20; var topRnd = (Math. random ()-0.5) * 20; var btnLeft = mouseLeft + (leftRnd> 0? 100:-100) + leftRnd; var btnTop = mouseTop + (topRnd> 0? 30:-30) + topRnd; btnLeft = btnLeft <100? (BtnLeft + window. innerWidth-200) :( btnLeft> window. innerWidth-100? BtnLeft-window.innerWidth + 200: btnLeft); btnTop = btnTop <100? (BtnTop + window. innerHeight-200) :( btnTop> window. innerHeight-100? BtnTop-window.innerHeight + 200: btnTop); // randomly generate some numbers, and then simply judge the location information, do not exceed the window display range. El. style. position = 'fixed'; el. style. left = btnLeft + 'px '; el. style. top = btnTop + 'px ';} function over_btn (e) {if (! E) {e = window. event;} btn_move (this, e. clientX, e. clientY);} document. getElementById ('su '). onmouseover = over_btn; // from the source file, Baidu click the button id is su. Use it to get the button and set the reaction of moving the cursor to the button.
All right, this spoof Is About Baidu extensions. You can get the complete code from here. Https://github.com/ZHONGHuanGit/Chrome_extensions_example/tree/master/egao_baidu
The extended installation method is the same as described in the previous article. You can see here http://blog.csdn.net/zhonghuan1992/article/details/40269647
References:
Chrome extension and application development (PS: I really appreciate the personality of this author. Not only do I share books, but I also donate all my donations to one fund. Buy electronic address: http://www.ituring.com.cn/book/1472)
Chrome cannot download extended applications. What should I do if I keep displaying them?
You can download and save the extension to your local computer in the cheetah browser store and drag it to chrome to install it.
You need Baidu to find out how to save the. crx plug-in method, which is not complicated. It is just a replacement of a small piece of code.
It's hard to write code here. Du Niang won't let it be published. You can use Baidu
Google chrome versions and extensions
Modify the hosts to enter the app store!
Baidu has a tutorial and cannot add links. You can search for them by yourself!
Hope to help you!