Chrome plug-in development plug-in-acfun see Figure 2, chrome-acfun

Source: Internet
Author: User

Chrome plug-in development plug-in-acfun see Figure 2, chrome-acfun

Continue, and then focus. For the right-click menu, use the chrome. contextMenus. create () function to create the right-click menu. Create a js file to store these functions.

These functions and event responses must be called when the browser is running. Therefore, add js items to "scripts" in the "background" item in manifest, it indicates that these are the background for the browser to run. These js scripts are always running listening.

     "background": {    "scripts": ["menu.js"]  },

In chrome plug-in code, many of the definitions of such items are enumerated and installed using.

Then, right-click the menu of the graph plug-in and the operation code:

Chrome. contextMenus. create ({// right-click the menu to create "title": "ACfun View", // title "type": "normal", // type, default: normal "documentUrlPatterns ": ["http://www.acfun. TV/*"], // match, trigger the right-click menu only in the matched URI. "TargetUrlPatterns": ["http: // */*"], // corresponds to <span style = "font-family: Arial, Helvetica, sans-serif; "> documentUrlPatterns is similar to </span>" contexts ": [" link "," image "], // context response condition, you can use the right-click menu only for link and image objects on the page. "Onclick": function (info, tab) {// right-click the menu and select the trigger time. // right-click the context to obtain the address of the selected object.
// Tab is the page label. You can obtain the page address. // There are two addresses in info: The address srcUrl of an image, and the connection address linkUrlif (info. srcUrl = null) {// when there is no srcUrl for the object property, that is, the object is connected. Here, we will judge whether the object is connected or an image. If the property does not exist, it is null. Var uri = info. linkUrl; uri = uri. replace (". jpg ",". jpeg "); // replace. For those images that cannot be displayed, you need to change the suffix, and I am doing this plug-in for this step. Chrome. windows. create ({// create window url: uri // url}, function () {}); // There Is A functon () {} behind the function (){}, this should mark the meaning of the function to be executed .} Else {var uri = info. srcUrl; uri = uri. replace (". jpg ",". jpeg "); chrome. windows. create ({url: uri}, function () {}) ;}}, function (){});


There is nothing too complicated here, and I finally fully realized my initial goal.

:




I am not doing too much research on complicated chrome plug-ins. It is enough to write a small thing. When you are free, fill in the android pitfalls you have dug before.



Can chrome plug-ins only be developed using javascript?

You can use the NPAPI (I have never used it for implementation, but it can be done directly using js. The NPAPI can use dll, And the dll can be developed in multiple languages ):
It is very easy to develop new extensions using HTML and JavaScript. However, if you want to reuse the code and functions that have been developed in the extension, you can use the NPAPI plug-in to achieve your goal. The NPAPI plug-in allows JavaScript code to call local binary code.
NPAPI is a heavy weapon. It is recommended that you use it only when other methods cannot reach your goal.
It is dangerous to include an NPAPI plug-in your extension. Because the NPAPI plug-in has full access permissions to your local machine and is not controlled. If your plug-in is not robust enough and contains vulnerabilities, hackers can exploit this vulnerability to install malicious software on their machines. In this case, try to avoid using the NPAPI plug-in expansion.

If you only allow access to local files, try to declare "permissions" in the manifest. json file: ["file: // *"]
To support reading local files. After declaring the file, try to use AJax to obtain the local file.
Java should not work, because java must have a Java Virtual Machine

How to Develop Chrome plug-ins? On some of my websites, I found that the plug-in will be automatically used without my permission. This is different from IE ActiveX.

Chrome uses javascript for development. There is a complete tutorial for translation on the 360 rapid browser. javascript does not have the permission to access local files, but there are still some security risks, such as privacy leaks. You should pay attention to this.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.