11/*!
2- * PageGuard.js v1.1.1 (https://github.com/Netrvin/PageGuard.js)
2+ * PageGuard.js v1.2.0 (https://github.com/Netrvin/PageGuard.js)
33 * Licensed under the MIT license
44 * Included some codes from https://github.com/sindresorhus/devtools-detect
55 * Used some codes from https://stackoverflow.com/questions/7798748/find-out-whether-chrome-console-is-open
1313 var allow_copy = true ;
1414 var copy_key = 0 ;
1515 var copy_old_id = 0 ;
16+ var protect_function = false ;
17+ //var protect_function_key = 0;
1618 var ele = 9 ;
1719
1820 var is_firefox = navigator . userAgent . indexOf ( 'Firefox' ) != - 1 ;
1921 var is_edge = navigator . userAgent . indexOf ( 'Edge' ) != - 1 ;
20- var is_ie = navigator . userAgent . indexOf ( "MSIE" ) != - 1 || ( ! ! window . ActiveXObject || "ActiveXObject" in window ) ;
22+ var is_ie = navigator . userAgent . indexOf ( "MSIE" ) != - 1 ; // <= IE 10
23+
24+ var returnFalse = function ( e ) {
25+ return false ;
26+ } ;
2127
2228 if ( ! is_ie ) {
2329 var can_preventDefault = typeof Event . prototype . preventDefault === "function" ;
6672
6773 function antiCopy_old ( ) {
6874 return setInterval ( function ( ) {
69- var returnFalse = function ( e ) {
70- return false ;
71- } ;
7275 document . oncontextmenu = returnFalse ;
7376 document . oncopy = returnFalse ;
7477 document . onselectstart = returnFalse ;
283286 }
284287 } ;
285288
286- PageGuard . stopDetecting = function ( key ) {
289+ PageGuard . stopDetectingDevTools = function ( key ) {
287290 if ( is_detecting ) {
288291 if ( key == stop_key ) {
289292 is_detecting = false ;
298301 }
299302 } ;
300303
304+ PageGuard . stopDetecting = PageGuard . stopDetectingDevTools ;
305+
306+ PageGuard . disableFunctions = function ( ) {
307+ if ( ! protect_function ) {
308+ protect_function = true ;
309+ window . open = function ( ) {
310+ return false ;
311+ } ;
312+ if ( ! is_ie ) {
313+ URL . createObjectURL = function ( ) {
314+ return false ;
315+ } ;
316+ }
317+ return true ;
318+ } else {
319+ return false ;
320+ }
321+ } ;
322+
323+ var is_detecting_suspect = false ;
324+ var detect_suspect_key = 0 ;
325+ var ds_status = false ;
326+ var focus_status = true ;
327+ var mouse_status = true ;
328+ var on_ds_begin = returnFalse ;
329+ var on_ds_end = returnFalse ;
330+ var ds_interval_id = 0 ;
331+
332+ var withoutChildFunction = function ( func ) {
333+ return function ( e ) {
334+ var parent = e . relatedTarget ;
335+ while ( parent != this && parent ) {
336+ try {
337+ parent = parent . parentNode ;
338+ } catch ( e ) {
339+ break ;
340+ }
341+ }
342+ if ( parent != this )
343+ func ( e ) ;
344+ }
345+ }
346+
347+ PageGuard . detectSuspectActions = function ( func1 , func2 ) {
348+ if ( ! is_detecting_suspect ) {
349+ is_detecting_suspect = true ;
350+ detect_suspect_key = Math . random ( ) ;
351+ on_ds_begin = withoutChildFunction ( function ( e ) {
352+ if ( ! ds_status ) {
353+ ds_status = true ;
354+ func1 ( ) ;
355+ }
356+ mouse_status = false ;
357+ } ) ;
358+ on_ds_end = withoutChildFunction ( function ( e ) {
359+ if ( ds_status && focus_status ) {
360+ ds_status = false ;
361+ func2 ( ) ;
362+ }
363+ mouse_status = true ;
364+ } ) ;
365+ if ( ! is_ie ) {
366+ document . addEventListener ( 'mouseover' , on_ds_end , true ) ;
367+ document . addEventListener ( 'mouseout' , on_ds_begin , true ) ;
368+ }
369+ ds_interval_id = setInterval ( function ( ) {
370+ window . onblur = function ( ) {
371+ if ( ! ds_status ) {
372+ ds_status = true ;
373+ func1 ( ) ;
374+ }
375+ focus_status = false ;
376+ } ;
377+ window . onfocus = function ( ) {
378+ if ( ds_status && mouse_status ) {
379+ ds_status = false ;
380+ func2 ( ) ;
381+ }
382+ focus_status = true ;
383+ } ;
384+ } , 100 ) ;
385+ return detect_suspect_key ;
386+ } else {
387+ return false ;
388+ }
389+ } ;
390+
391+ PageGuard . stopDetectingSuspectActions = function ( key ) {
392+ if ( is_detecting_suspect ) {
393+ if ( key == detect_suspect_key ) {
394+ is_detecting_suspect = false ;
395+ if ( ! is_ie ) {
396+ document . removeEventListener ( 'mouseover' , on_ds_end , true ) ;
397+ document . removeEventListener ( 'mouseout' , on_ds_begin , true ) ;
398+ }
399+ clearInterval ( ds_interval_id ) ;
400+ window . onblur = null ;
401+ window . onfocus = null ;
402+ return true ;
403+ } else {
404+ return false ;
405+ }
406+ } else {
407+ return false ;
408+ }
409+ } ;
410+
411+ // Need to be fixed
412+ /*
413+ function randomText(len) {
414+ var s = '';
415+ var chars = 'ABCDEFGHIJKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
416+ var char_len = chars.length;
417+ for (var i = 0; i < len; i++) {
418+ s += chars.charAt(Math.floor(Math.random() * char_len));
419+ }
420+ return s;
421+ }
422+
423+ function confuseContent() {
424+ var ele_list = ['p', 'a', 'span', 'textarea'];
425+ for (var i=0;i<ele_list.length;i++) {
426+ var ele_clt=document.getElementsByTagName(ele_list[i]);
427+ for (var j=0;j<ele_clt.length;j++) {
428+ var new_span = document.createElement('span');
429+ new_span.innerText = randomText(100);
430+ new_span.style.position = 'fixed !important';
431+ new_span.style['z-index'] = '-99999 !important';
432+ new_span.style.right = '-1000% !important';
433+ new_span.style.display = 'inline !important';
434+ ele_clt[j].parentNode.insertBefore(new_span, ele_clt[j]);
435+ }
436+ }
437+ }
438+
439+ PageGuard.confuseContent = confuseContent;
440+ */
441+
301442 window . PageGuard = PageGuard ;
302443} ) ( ) ;
0 commit comments