Js: Copy articles, add copyright at random, code at any location

Source: Internet
Author: User

Now many webmasters want others to copy their own website articles to bring a link, but this is just an idealized process where almost everyone will delete the source, the copyright information is automatically added to the end of the article. Below I want to organize a lot of examples randomly added to the copyright in the article.

Example 1:

After adding the file, you only need to copy the content of the page and add a url of the current file at random. However, unfortunately, many webmasters directly Delete the subsequent file with the copyright.

The Code is as follows: Copy code

Document. body. oncopy = function (){
SetTimeout (function ()
{
Var text = clipboardData. getData ("text ");
If (text ){
For more details about text = text + "rn, see:" + location. href;
ClipboardData. setData ("text", text );
}
}, 100)
}

Example 2,After the code above is improved, we add a url in an indefinite location based on the content length. This method has a slight effect.

The Code is as follows: Copy code

Function left (mainStr, lngLen ){
If (lngLen> 0) {return mainStr. substring (0, lngLen )}
Else {return null}
}
Function right (mainStr, lngLen ){
If (mainStr. length-lngLen> = 0 & mainStr. length> = 0 & mainStr. length-lngLen <= mainStr. length ){
Return mainStr. substring (mainStr. length-lngLen, mainStr. length )}
Else {return null}
}
Document. body. oncopy = function ()
{
SetTimeout (function (){
Var d = clipboardData. getData ("text ");
Var LenStr = d. length;
Var LeftNum = Math. floor (LenStr/2 );
Var RightNum = LenStr-LeftNum;
Var AddStr = "(www. bKjia. c0m )";
Var AddStr2 = "rn for more details, see:" + location. href;
If (LenStr> 50)
{NewContent = left (d, LeftNum) + AddStr + right (d, RightNum) + AddStr2 ;}
Else {NewContent = d ;}
ClipboardData. setData ("Text", NewContent );
}, 100)
}

Related Article

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.