Chrome plug-in development

Source: Internet
Author: User

Chrome plug-in development

I'm reading:

document.body.oncontextmenu=function(){return false;};document.body.ondragstart=function(){return false;};document.body.onselectstart=function(){return false;};document.body.onbeforecopy=function(){return false;};document.body.onselect=function(){document.selection.empty();};document.body.oncopy=function(){document.selection.empty();};

In fact, one of the ways for websites to prevent copying is similar. The same is true for articles in the 306doc Library:


Its key code is:

Document. body. oncopy = function () {var CurUserNameCookiescgcg = getCookie ("LoginName"); if (CurUserNameCookiescgcg = "" | CurUserNameCookiescgcg = null) {var docarttitle = document. getElementById ("docarttitle"); var docencodetitle = "\"; if (docarttitle = null) {docencodetitle = ""} else {docencodetitle = "& titleencode =" + docarttitle. value} $. ajax ({url: "http://www.360doc.com/ajax/GetLo GinForm20130912.ashx? ArtID = "+ ArticleID +" & type = 2 & arttype = "+ CurArtType + docencodetitle, cache: false, success: function (result) {$ ("# LayerLogin" result .html (result); showBg ("dialog", "dialog_content", "1")}, error: onFailed }); return false} else {var selhtml = ""; var selection; if (window. getSelection) {selection = window. getSelection (); if (selection! = Null) {selhtml = selection. toString ()} else if (document. selection) {selection = document. selection. createRange (); if (selection! = Null) {selhtml = selection. text} if (selhtml. length & gt; 200) {document. getElementById ('fuzhitishidiv '). style. display = 'none'; if (getCookie ("360doc1 ")! = Null & UserID! = 0) {$. ajax ({url: "http://www.360doc.com/ajax/GetLoginForm20130912.ashx? ArtID = "+ ArticleID +" & type = 5 & arttype = "+ CurArtType +" ", cache: false, success: function (result) {if (result = "-1") {return true} else {if (document. getElementById ("fuzhitishidiv ")! = Null) {document. getElementById ("fuzhitishidiv"). innerHTML =""; Window. scroll (0, 0); document. getElementById ("fuzhitishidiv "). style. display = ''} else {alert (" Tip: click "transfer to my library" under the title to save the article to your personal library, then you can copy the content of the article! ")} Return false }}, error: onFailed})} else {if (document. getElementById (" fuzhitishidiv ")! = Null) {document. getElementById ("fuzhitishidiv"). innerHTML =""; Window. scroll (0, 0); document. getElementById ("fuzhitishidiv "). style. display = ''} else {alert (" Tip: click "transfer to my library" under the title to save the article to your personal library, then you can copy the content of the article! ")} Return false} else {return true }}}

To solve these problems, the first thought is:

I. Remove the code or external js links, but it is unrealistic to do so:

In the first case, blocking plug-ins such as ScriptBlock by using a browser script also fails. blocking all JS files may make the webpage unable to display normally. 2. Disabling Javascript Execution by the browser

Likewise, the above principle 2 cannot work;

3. Develop Chrome plug-in + api hook implementation

This method seems to be the most effective;

Plugin creation process:

Enter Chrome: // extensions/in the chrome address bar to open the Extended Program window. Check the developer option. Select the directory of the previously created plug-in. After the code debugging is complete, confirm the release, you can click package extension in to package. drag the crx file into the browser for installation;


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Authorization + sLro7o8L3A + authorization + cve-vcd4kpha + PHByZSBjbGFzcz0 = "brush: java;"> {"name": "UBC", "manifest_version": 2, "version": "1.0.0 ", "description": "UnBlock Copy", "browser_action": {"default_icon": "http://www.bkjia.com/uploads/allimg/140821/0424095S2-3.png", "default_title": "UnBlock Copy", "default_popup": "popup.html "}, "content_scripts": [{"matches": ["http: // */*", "https: // */*"], "js ": ["js/hookapi. js "]," run_at ":" document_end "," all_frames ": true}]}
Note:

"manifest_version": 2,

This line is fixed. The new Chrome plug-in development specifications do not support this line in most online tutorials.

Popup.html

   
  
  
  1. Unblock Copy   Event
  2. Unblock Paste  Event
  3. Unblock Select Event


Hookapi. js

// UnHook Copy Related Eventsvar arr_hook_event = ["oncontextmenu", "ondragstart", "onselectstart", "onselect", "onbeforecopy", "oncopy"]; function Array_indexOf (arr, item) {for (var I = 0; I
Test results: the two websites can select and copy the content:




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.