This repository has been archived by the owner on Sep 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpageguard.min.js
7 lines (7 loc) · 4.88 KB
/
pageguard.min.js
1
2
3
4
5
6
7
/*!
* PageGuard.js v1.2.0 (https://github.com/Netrvin/PageGuard.js)
* Licensed under the MIT license
* Included some codes from https://github.com/sindresorhus/devtools-detect
* Used some codes from https://stackoverflow.com/questions/7798748/find-out-whether-chrome-console-is-open
*/
!function(){var e={},t=function(){},n=!1,o=0,r=0,i=!0,u=0,c=0,a=!1,d=9,s=-1!=navigator.userAgent.indexOf("Firefox"),l=-1!=navigator.userAgent.indexOf("Edge"),m=-1!=navigator.userAgent.indexOf("MSIE"),p=function(e){return!1};if(!m)var f="function"==typeof Event.prototype.preventDefault,v="function"==typeof Event.prototype.stopPropagation,g="function"==typeof Event.prototype.stopImmediatePropagation;var w=document.createElement("any");w.__defineGetter__&&w.__defineGetter__("id",function(){t()});var y=/./;function E(){return setInterval(function(){document.oncontextmenu=p,document.oncopy=p,document.onselectstart=p,document.ondragstart=p,document.oncut=p,document.onbeforecopy=p,window.onhelp=p,document.onkeydown=function(e){if(123==e.keyCode||e.shiftKey||e.altKey||e.ctrlKey)return!1}},100)}y.toString=function(){t()},e.anticopy=E;var h=function(e){var t,n=document.getElementsByTagName("body")[0];t=window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection?document.selection.createRange().text:"";var o=document.createElement("div");o.style.left="-99999px",o.style.position="absolute",n.appendChild(o),o.innerHTML="",t.selectAllChildren(o),window.setTimeout(function(){n.removeChild(o)},0),f&&e.preventDefault(),v&&e.stopPropagation(),g&&e.stopImmediatePropagation()},L=function(e){document.body.blur(),f&&e.preventDefault(),v&&e.stopPropagation(),g&&e.stopImmediatePropagation()},b=L,P=function(e){(123==e.keyCode||e.shiftKey||e.altKey||e.ctrlKey)&&(e.keyCode=0,f&&e.preventDefault(),v&&e.stopPropagation(),g&&e.stopImmediatePropagation())},I=function(e){2==e.button&&(e.button=0,f&&e.preventDefault(),v&&e.stopPropagation(),g&&e.stopImmediatePropagation())},D=function(e){f&&e.preventDefault(),v&&e.stopPropagation(),g&&e.stopImmediatePropagation()},x=D;if(g)var k=Event.prototype.stopImmediatePropagation;if(v)var S=Event.prototype.stopPropagation;e.antiCopy=function(){if(i){if(i=!1,u=Math.random(),m)c=E();else{var e=["copy","cut","contextmenu","keydown","selectstart","dragstart","beforecopy","mousedown"];v&&(Event.prototype.stopPropagation=function(){e.includes(this.type)&&!i||S.apply(this,arguments)}),g&&(Event.prototype.stopImmediatePropagation=function(){e.includes(this.type)&&!i||k.apply(this,arguments)}),document.addEventListener("copy",h,!0),document.addEventListener("selectstart",L,!0),document.addEventListener("mousedown",I,!0),document.addEventListener("keydown",P,!0),document.addEventListener("contextmenu",x,!0),document.addEventListener("cut",D,!0),document.addEventListener("dragstart",b,!0)}return u}return!1},e.allowCopy=function(e){return!i&&(e==u&&(m?(clearInterval(c),document.oncontextmenu=null,document.oncopy=null,document.onselectstart=null,document.ondragstart=null,document.oncopy=null,document.onbeforecopy=null,document.onkeydown=null,window.onhelp=null):(document.removeEventListener("copy",h,!0),document.removeEventListener("selectstart",L,!0),document.removeEventListener("mousedown",I,!0),document.removeEventListener("keydown",P,!0),document.removeEventListener("contextmenu",x,!0),document.removeEventListener("cut",D,!0),document.removeEventListener("dragstart",b,!0)),!0))},e.detectDevTools=function(e){return!n&&(n=!0,t=e,o=Math.random(),s&&console.log(y),r=setInterval(function(){!function(){if(!s&&!l&&(console.log(w),10==++d)){console.clear(),d=0;var e=/./;e.toString=function(){t()},console.log("%c",e)}var n=window.outerWidth-window.innerWidth>50,o=window.outerHeight-window.innerHeight>200;o&&n||!(window.Firebug&&window.Firebug.chrome&&window.Firebug.chrome.isInitialized||n||o)||t(),window.console&&window.console.firebug&&t()}()},100),o)},e.stopDetectingDevTools=function(e){return!!n&&(e==o&&(n=!1,clearInterval(r),t=function(){},!0))},e.stopDetecting=e.stopDetectingDevTools,e.disableFunctions=function(){return!a&&(a=!0,window.open=function(){return!1},m||(URL.createObjectURL=function(){return!1}),!0)};var C=!1,_=0,T=!1,A=!0,K=!0,F=p,M=p,O=0,G=function(e){return function(t){for(var n=t.relatedTarget;n!=this&&n;)try{n=n.parentNode}catch(t){break}n!=this&&e(t)}};e.detectSuspectActions=function(e,t){return!C&&(C=!0,_=Math.random(),F=G(function(t){T||(T=!0,e()),K=!1}),M=G(function(e){T&&A&&(T=!1,t()),K=!0}),m||(document.addEventListener("mouseover",M,!0),document.addEventListener("mouseout",F,!0)),O=setInterval(function(){window.onblur=function(){T||(T=!0,e()),A=!1},window.onfocus=function(){T&&K&&(T=!1,t()),A=!0}},100),_)},e.stopDetectingSuspectActions=function(e){return!!C&&(e==_&&(C=!1,m||(document.removeEventListener("mouseover",M,!0),document.removeEventListener("mouseout",F,!0)),clearInterval(O),window.onblur=null,window.onfocus=null,!0))},window.PageGuard=e}();