1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/fuload-copyrightmark

Клонировать/Скачать
copyrightmark.min.js 16 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
ye kangfu Отправлено 03.01.2020 12:06 c2382e2
/**
* CopyrightMark - a website content copyright plugin
* version 1.0.0
* Copyright (c) 2019-2020, Ye Kangfu (https://github.com/fuload).
* https://www.fuload.cn/copyrightmark
*
* Author: Ye Kangfu (fuload)
* Email: 373539902@qq.com
* Website: https://fuload.cn
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
(function(e){"use strict";e()})(function(){"use strict";var e,t=function(e){var t,n,r=function(e,t){return e?e.querySelectorAll(t):null},a=function(e,t){if(t&&t.length>0)for(var n=0;n<t.length;n++)if(t[n]===e)return!0;return!1},i=[];if(e&&"object"==typeof e)i[0]=e;else if("body"==e)i[0]=document.body;else if(/^\#[a-zA-Z0-9\-\_]+/.test(e))i[0]=document.getElementById(e.substr(1));else if(/^[a-zA-Z]{1,10}[1-6]?$/.test(e))i=document.getElementsByTagName(e);else if(/^\<[a-zA-Z]{1,10}[1-6]?\/?\>/i.test(e)){var o=e.match(/^\<([a-zA-Z]{1,10}[1-6]?)\/\>$|([^\0]+)/i),l=document.createElement(o[1]||"div");o[2]&&(l.innerHTML=o[2],l=l.firstChild),i[0]=l}else i=r(document,e);return t={eq:function(e){return n=i[0|e],this},find:function(e){return i=r(i[0],e),this},on:function(e,t){n=n||i[0];var r,a=e.split(" ");for(r in a)if(a[r]){var o=a[r].split(".");n.addEventListener?n.addEventListener(o[0],function(e){t(e)},!1):n.attachEvent("on"+o[0],function(e){t(e)},!1)}return this},attr:function(e,t){return n=n||i[0],t?this:n?n.getAttribute(e):void 0},css:function(e,t){var r=e+":"+t+";";return n=n||i[0],n.style.cssText=r,this},append:function(e){n=n||i[0];var t=document.createElement("div");t.innerHTML=e;for(var r=t.childNodes,a=0;a<=r.length;a++)n.appendChild(r[0]);return this},parents:function(e){if(e){if(i[0]){for(var t=i[0],o=r(t.parentNode,e),l=a(t,o);t&&"BODY"!=t.nodeName&&!l;)t=t.parentNode,o=r(t.parentNode,e),l=a(t,o);i[0]=o.length>0&&l?t:null}}else i[0]=n.parentNode;return this},is:function(e){if(n=n||i[0],!n)return!1;if("function"!=typeof e){var t=r(n.parentNode,e);return!(!t||!a(n,t))}var o=n;o.expr=e,o.expr()},html:function(){return n=n||i[0],n?n.innerHTML:""},outerHtml:function(){return n=n||i[0],n?n.outerHTML:""},text:function(){return n=n||i[0],n?n.textContent||n.innerText:""},val:function(){return n=n||i[0],n?n.value:""},remove:function(e){if(n)e||n.parentNode.removeChild(n);else if(i)for(var t=0,r=i.length;t<r;t++)e||i[t].parentNode.removeChild(i[t])},elems:function(e){return e>=0?i[0|e]:i}},t},n=function(e){return e.outerHtml()},r=function(e,n,r){return t(e).parents(n).elems(r)},a=function(e,n,r){return t(e).find(n).elems(r)},i={template:{label:"p",attrs:{},content:{notice:{setHtml:"<span>This article copyright belongs to the original author all, reproduced please indicate the source.</span><br>"},source:{getNode:{main:"head",name:'meta[property="og:site_name"]'}},author:{getNode:{main:"head",name:'meta[name="author"]'},setHtml:"<span>Author: {author} {if source}(From {source}){/if}</span><br>"},link:{setHtml:'<span>Web link: <a href="{url}">{url}</a></span><br>'}}},separator:"br",topInsert:!1,rangeDeviate:!1,selector:"body",removeNode:null,removeAttr:null,discern:!0,minCopy:100,barrier:!1,barrierStyle:"position:absolute;left:auto;top:auto;background:#000c;padding:5px 8px;color:#fff;",assign:[],allowAuthorSet:!1,showInArticle:!1},o=function(e){return null!==e&&"object"==typeof e&&!(e instanceof Array)},l=function(e){return e instanceof Array},u=function(e){return"string"==typeof e},c=function(e){return e.toString?e.toString():e+""},s=function(e,t){var n,r=e;for(n in t)o(t[n])&&o(r[n])?r[n]=s(r[n],t[n]):r[n]=t[n];return r},f=function(e){return e.replace(/\r\n+/g,"\r")},d=function(e,t){var n,r,a,i;window.clipboardData?(r=O.innerHTML,O.innerHTML='<iframe allowtransparency="true" src="about:blank"></iframe>',a=O.firstChild,i=a.contentWindow.document,i.write('<html><head><meta charset="UTF-8"></head><body></body></html>'),i.body.innerHTML=r,e.preventDefault?(t&&k.removeAllRanges(),e.preventDefault(),n=i.createRange(),n.selectNodeContents(i.body),a.contentWindow.getSelection().addRange(n)):(e.returnValue=!1,n=i.body.createTextRange(),n.select()),document.execCommand("copy")):t?k.selectAllChildren(O):(n=document.createRange(),n.selectNodeContents(O),k.addRange(n))},m=function(e){if(e){var t=location.protocol+"//"+location.host,n=e.match(/^(\.[\.\/]{1,})(.*)/);if(n){var r=0,a=n[1].split("/"),i=location.pathname,o=i.split("/");for(o.splice(0,1),o.splice(-1,1);r<a.length;r++)".."==a[r]&&o.splice(-1,1);for(var l in o)t+="/"+o[l];e=t+"/"+n[2]}else if(!/^(https?:\/\/|\/\/)/i.test(e)){var u=/^\//.test(e)?"":"/";e=t+u+e}}return e},p=function(){window.getSelection?k=window.getSelection():document.getSelection?k=document.getSelection():document.selection&&(k=document.selection.createRange())},v=function(e,n){var r,a;_<z?(r=_,a=I):(r=z,a=B),n=n.replace(/(left|top)\:\s*auto/gi,function(e,t){switch(t){case"left":e="left:"+r+"px";break;case"top":e="top:"+a+"px"}return e}),t("body").append('<div id="'+M+'-barrier-dialog" style="'+n+'">'+e+"</div>")},h=function(e,t,n){if(o(t))for(var r in t)if(!n||"id"!=r){var a=document.createAttribute(r);a.nodeValue=t[r],e.setAttributeNode(a)}},g=function(e,n){var r,a="",i="",o="",c="";if(e.getNode){r=u(e.getNode)?{main:e.getNode}:e.getNode;var s=!1,f=!1;if(r.main&&(t(n).find(r.main).is(r.main)?s=!0:t(r.main).is(r.main)&&(f=!0,s=!0)),s){var d=r.name?f?t(r.main).find(r.name):t(n).find(r.main).find(r.name):t(n).find(r.main),p=r.url?f?t(r.main).find(r.url):t(n).find(r.main).find(r.url):null,v=function(){var e=d.attr("title");return e||null===p||(e=p.attr("title"),!e&&p.is("a")&&(e=p.find("img").attr("title")||p.find("img").attr("alt")||"")),e||""},h=function(e,t){var n;return n=e.is("input")?e.val():e.is("meta")?e.attr("content"):t?e.attr("href"):e.text(),n};if(!p&&d.is("a")&&(p=d),i=h(d),o=p?h(p,1):"",i&&i.replace(/[\n\r\f\t\v\s]+/gm,"")?(i=i.replace(/[\n\r\f\t\v]+|^\s+|\s+$/gm,""),c=v()):(i=v(),c=i),i){if(e.replace)if(l(e.replace)){var g=e.replace;if(g.length>1){var b=g[0],y=g[1],w=g[2],x=l(b)?b.join("|"):b;i=i.replace(new RegExp(x,"ig"),function(e){var t=l(b)?b.indexOf(e):0,n=l(y)?y[t]:y;return w&&("<"==w&&(n+=i),">"==w&&(n=i+n)),n})}}else u(e.replace)&&(i=e.replace);o=m(o),a=o?'<a href="'+o+'"'+(c?' title="'+c+'"':"")+">"+i+"</a>":i}}}return{label:a,name:i,url:o}},b=function(e,t){return e.setHtml?e.setHtml.replace(/^\s*((\<br\s?\/?\>|\<hr\s?\/?\>)+)?\<([a-zA-Z0-9]{1,10})/,'<$3 id="'+M+"-"+t+'"'):""},y=function(e,t,n,r,i){var o=0,l=i?{}:"",u=a(e,'input[id^="'+M+"-"+t+'-"]');if(u.length>0)for(;o<u.length;o++){var c="<"+n+">"+u[o].value+"</"+n+">"+r;if(i){var s=u[o].id;s=s.substr(s.lastIndexOf("-")+1),l[s]={setHtml:c}}else l+=c}else-1!=t.indexOf("author-")&&(l=y(e,t.replace("author-",""),n,r,i));return l},w=function(e){var t,n="";if(o(e)){var r,a=e.content;for(r in a)if(t=a[r].setHtml,t)break}else u(e)&&(t=e);return t&&(n=/^\s*((\<br\s?\/?\>\s*|\<hr\s?\/?\>\s*)+)?\<([a-zA-Z0-9]{1,10})/.exec(t),n=n[3]),n},x=function(e,t,n){var r="",a=e.content,i=w(e),l=/^span|em|i|u|b|string|small/i.test(i)?"<br>":"";if(u(a))r=n?a:y(t,"author-top",i,l)+a+y(t,"author-bottom",i,l);else if(o(a)){var c={};if(!n){var f=y(t,"author-top",i,l,!0);a=s(f,a),f=y(t,"author-bottom",i,l,!0),a=s(a,f)}for(var d in a)if(o(a[d])){var m={},p=g(a[d],t);m[d]=p.label,m[d+"_name"]=p.name,m[d+"_url"]=p.url,c[d]=m,r+=b(a[d],d)}for(var v in c)r=r.replace(new RegExp("\\{"+v+"\\}|\\{"+v+"_name\\}|\\{"+v+"_url\\}|\\{if\\s("+v+"|"+v+"_name|"+v+"_url)\\}.+\\{\\/if\\}","g"),function(e,t){var n="";switch(e){case"{"+v+"}":n=c[v][v];break;case"{"+v+"_name}":n=c[v][v+"_name"];break;case"{"+v+"_url}":n=c[v][v+"_url"];break;default:var r=c[v][t];r&&(n=e.replace(new RegExp("^\\{if\\s"+t+"\\}([^\\{]*.*[^\\}]*)\\{\\/if\\}$"),function(e,t){var n=t.match(/\{([^\{\}]+)\}/g),r=t;for(var a in n){var i=/\{([^\{\}\_]+)\_?([^\{\}]*)\}/.exec(n[a]),o=i[1]+(i[2]?"_"+i[2]:""),l=c[i[1]];if(l||"url"==o){var u="url"==o?document.URL:l?l[o]:"";r=r.replace(new RegExp("\\{"+o+"\\}"),u||"")}}return r}))}return n})}if(r){r=r.replace(/\{url\}/g,document.URL);var x=document.createElement(u(e.label)?e.label:"div");return e.attrs&&o(e.attrs)&&h(x,e.attrs,!0),x.id=M,x.innerHTML=r,x}return null},N=function(e){var t=[];if(e){var n=(u(e)?e:"br").split(/\s*\,\s*/);for(var r in n)t[r]=document.createElement(n[r])}return t},T=function(e){return e.replace(/\<[a-z]{1,10}[1-5]?[^\<\>]*\>[\n\f\r\t\v\s]*\<\/[a-z]{1,10}[1-5]?\>|\<(p|h[1-5]|div|ul|ol|li)([^\<\>]*)\>|\<\/(p|h[1-5]|div|ul|ol|li)\>|(\<br\s*\/?\>)/gim,function(e,t,n,r,a){var i="";return"div"==t||"li"==t?i="\r<"+t+n+">":"ul"==t||"ol"==t?i="\r\t<"+t+n+">":t&&(i="\r<"+t+n+">"),"div"==r||"li"==r?i="</"+r+">\r":r&&(i="</"+r+">\r\n"),a&&(i="\n"),i})},E=function(i){var s,m,h,g,b,y,w,E,A,H,C,L,S,D=e.selector,R=e.assign,_=i.target||i.srcElement,I="";if(p(),S=document.createElement("cm"),S.id="temp-"+M,S.style.display="block",S.style.fontFamily="inherit",S.style.position="fixed",S.style.top="0",S.style.left="-1px",S.style.zIndex="999999999999",S.style.overflow="hidden",S.style.width="1px",S.style.height="1px",S.style.background="#FFF",k.getRangeAt)for(var z=0;z<k.rangeCount;z++){var B=k.getRangeAt(z).cloneContents();S.appendChild(B),I+=c(k.getRangeAt(z))}else S.innerHTML=k.htmlText,I=k.text;if(l(R)&&R.length>0){for(var z in R){var P=R[z];if(m=r(_,P.selector,0),t(m).is(P.selector)){s=P;break}}if(!s){var Y=0;for(var z in R){P=R[z];for(var G=a(S,P.selector),J=0;J<G.length;J++){var K=t(G[J]).text().length;(0==Y||Y>0&&K>Y)&&(m=G[J],Y=K,s=P)}}}if(!s)return!1;h=null!=s.removeNode?s.removeNode:e.removeNode,g=null!=s.removeAttr?s.removeAttr:e.removeAttr,C=null!=s.barrier?s.barrier:e.barrier,b=null!=s.minCopy?s.minCopy:e.minCopy,y=null!=s.discern?s.discern:e.discern,L=null!=s.barrierStyle?s.barrierStyle:e.barrierStyle,H=null!=s.rangeDeviate?s.rangeDeviate:e.rangeDeviate,w=null!=s.topInsert?s.topInsert:e.topInsert,E=o(s.template)?s.template:e.template,A=null!=s.separator?s.separator:e.separator}else{if(!D)return!1;var Q=!1;if(m=r(_,D,0),t(m).is(D))Q=!0;else for(Y=0,G=a(S,D),J=0;J<G.length;J++){K=t(G[J]).text().length;(0==Y||Y>0&&K>Y)&&(m=G[J],Y=K,Q=!0)}if(!Q)return!1;h=e.removeNode,g=e.removeAttr,C=e.barrier,b=e.minCopy,y=e.discern,L=e.barrierStyle,H=e.rangeDeviate,w=e.topInsert,E=e.template,A=e.separator}if(b=0|t(m).find("input#"+M+"-author-min").val()||0|t(m).find("input#"+M+"-min").val()||0|t("body").find("input#"+M+"-min").val()||b,I.length>=b){var X,ee=t(m).find("input#"+M+"-author-bar").val()||t(m).find("input#"+M+"-bar").val()||t("body").find("input#"+M+"-bar").val();if("1"==ee||"true"==ee?C=!0:"function.on"==ee?X=!1:"function.off"==ee?X=!0:ee&&(C=ee),C){if("function"!=typeof C)return i.preventDefault?i.preventDefault():i.returnValue=!1,u(C)&&v(C,L),!1;if(C(i,X))return i.preventDefault?i.preventDefault():i.returnValue=!1,!1}var te,ne,re=[],ae=!1;if(y){var ie=u(y)?y:"#"+M;t(m).find(ie).is(function(){t(S).find("#"+M).remove(),ae=!0}),t(m).find("#"+M+"-reprint").is(function(){te=n(t(m).find("#"+M+"-reprint")),t(S).find("#"+M+"-reprint").remove(),ae=!0})}if(re=N(A),te?(ne=document.createElement("div"),ne.innerHTML=te,ne=ne.childNodes[0]):(ne=x(E,m),ne&&(ne.id=M+"-reprint")),ne){if(h&&u(g)&&(t(S).find(h).remove(),ae=!0),g&&u(g)){var oe=S.innerHTML,le=g.replace(/\,\ *|\-/g,function(e){return"-"==e?"\\-":"|"}),ue=oe.replace(/\<[a-zA-Z]{1,10}[0-6]?.*\>/gim,function(e){var t=new RegExp("(\\ ("+le+")\\=\\'[^\\<\\>\\'\\n\\f\\r\\t\\v]*\\'|\\ ("+le+')\\=\\"[^\\<\\>\\"\\n\\f\\r\\t\\v]*\\")',"igm");return e.replace(t,"")});S.innerHTML=ue,ae=!0}if(w){for(z in re)S.insertBefore(re[z],S.childNodes[0]);S.insertBefore(ne,S.childNodes[0])}else{for(z in re)S.appendChild(re[z]);S.appendChild(ne)}if(ae||window.clipboardData){if(document.body.appendChild(S),O=document.getElementById("temp-"+M),!Z)if(W)F=k.anchorNode,V=k.anchorOffset,j=k.focusNode,U=k.focusOffset;else if(q){var ce=0,se=f(I).length;$=-document.body.innerText.length,k.moveStart("character",$),ce=f(I).length+H,V=ce-se,U=se}k.selectAllChildren?d(i,!0):(W?k.removeAllRanges():q&&document.selection.empty(),d(i)),window.setTimeout(function(){if(O.innerHTML="",W?k.removeAllRanges():q&&document.selection.empty(),O.parentNode.removeChild(O),W){var e=document.createRange();e.setStart(F,V),e.setEnd(j,U);var t=c(e);t||(e.setStart(j,U),e.setEnd(F,V)),k.addRange(e)}else q&&!1!==H&&(k.moveToElementText(document.body),k.moveStart("character",$),k.moveEnd("character",$),k.moveStart("character",V),k.moveEnd("character",U),k.select());Z=!0})}else{var fe,de,me,pe,ve='<meta charset="utf-8">',he="";for(z in i.preventDefault(),i.originalEvent?fe=i.originalEvent.clipboardData:i.clipboardData&&(fe=i.clipboardData),fe.setData("text/html",ve+S.innerHTML),de=document.createElement("div"),re)de.appendChild(re[z]);ne.innerHTML=T(ne.innerHTML),he=ne.innerText,he=he.replace(/^[\n\f\r\t\v\s]+|[\n\f\r\t\v\s]+$/gm,""),pe=ne.nodeName,he=(w?"":"\r")+he+("p"==pe||""==pe||""==pe?"\r\n":"\r"),de.innerHTML=T(de.innerHTML),me=de.innerText,he=w?he+me+k:k+me+he,fe.setData("text/plain",he)}}}},A=function(e){var t=e.button;return!(t>0)||!!q&&1==t},H=function(e,n){e.type==n?(_=e.x,I=e.y,t("#"+M+"-barrier-dialog").is(function(){setTimeout(function(){t("#"+M+"-barrier-dialog").remove()},0)})):(z=e.x,B=e.y)},C=function(){if(e.allowAuthorSet){for(var t=0,n=[],r=document.getElementsByTagName("p");t<r.length;t++){var a,i=r[t].innerHTML;if(a=/^\s*(\<(strong|small|span|em|b|u|i)[^\<\>\r\n\t\v\f]*\>\s*)*(\{{3}(\-?[a-z]{1,10})\:([^\r\n\t\v\f]{1,200})\}{3})(\s*\<\/(i|u|b|em|span|small|strong)\>)*\s*$/i.exec(i)){var o,l=r[t],u=a[4],c=a[5],s=(a[1]||"")+c+(a[6]||"");u="-"==u.substr(0,1)?"top"+u:"min"==u||"bar"==u?u:"bottom-"+u,o=document.createElement("input"),o.type="hidden",o.id=M+"-author-"+u,o.value="min"==u?c:s,l.parentNode.appendChild(o),n.push(l)}}for(t in n)n[t].parentNode.removeChild(n[t])}},L=function(){if(e.showInArticle){var t,n=e.showInArticle,r=e.template,i=e.topInsert,l=e.separator,u=e.selector,c=function(){var e,n=a(document,u,0);if(n){var o=N(l),c=x(r,n,t);if(i){for(e in o)n.insertBefore(o[e],n.childNodes[0]);n.insertBefore(c,n.childNodes[0])}else{for(e in o)n.appendChild(o[e],n.childNodes[0]);n.appendChild(c,n.childNodes[0])}}else console.log("The '"+u+"' selector cannot find a matching element")};o(n)?(r=o(n.template)?n.template:r,i=null!=n.topInsert?n.topInsert:i,l=null!=n.separator?n.separator:l,u=null!=n.selector?n.selector:u,t=n.notPostscript,c()):c()}},S=function(n){var r=(t("html").attr("lang")||navigator.userLanguage||navigator.language).toLowerCase().replace("-","_");if("zh_cn"==r){var a={template:{label:"p",content:{notice:{setHtml:"<span>\\u672c\\u6587\\u8457\\u4f5c\\u6743\\u5f52\\u4f5c\\u8005\\u6240\\u6709\\uff0c\\u8f6c\\u8f7d\\u8bf7\\u9644\\u4e0a\\u672c\\u58f0\\u660e\\u53ca\\u51fa\\u5904\\u94fe\\u63a5\\u3002</span><br>"},author:{getNode:{main:"head",name:'meta[name="author"]'},setHtml:"<span>\\u4f5c\\u8005\\uff1a{author} {if source}\\uff08\\u6765\\u81ea {source}\\uff09{/if}</span><br>"},source:{getNode:{main:"head",name:'meta[property="og:site_name"]'}},link:{setHtml:'<span>\\u94fe\\u63a5\\uff1a<a href="{url}">{url}</a></span><br>'}}}};e=s(i,a)}e=s(i,o(n)?n:{}),C(),L(),t("body").on("copy."+M,E),t(document).on("click",function(){Z=!1}).on("mousedown mouseup",function(e){A(e)&&H(e,"mousedown")}).on("touchstart touchend",function(e){H(e,"touchstart")})},D=function(e){var t=function(){S(e)};"complete"===document.readyState?setTimeout(t,1):document.addEventListener?(document.addEventListener("DOMContentLoaded",t,!1),window.addEventListener("load",t,!1)):(document.attachEvent("onreadystatechange",t),window.attachEvent("onload",t))},R=function(e){document.body?S(e):D(e)},M="copyrightmark",k=null,_=0,I=0,z=0,B=0,O=null,Z=!1,$=0,F=null,V=null,j=null,U=null,W=window.getSelection||document.getSelection,q=document.selection;window.copyrightmark=R,window.copyrightmark.loadSet=function(){C()},window.copyrightmark.loadShow=function(){L()}});

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/fuload-copyrightmark.git
git@api.gitlife.ru:oschina-mirror/fuload-copyrightmark.git
oschina-mirror
fuload-copyrightmark
fuload-copyrightmark
master