-
Notifications
You must be signed in to change notification settings - Fork 10
/
noprint.js
90 lines (79 loc) · 2.54 KB
/
noprint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
NoPrint.js V1.0
Created by PDFAntiCopy.com
*/
if (noCopy)
{
document.body.oncopy = function(){return false};
document.body.oncontextmenu = function(){return false};
document.body.onselectstart = document.body.ondrag = function(){
return false;
}
document.onkeydown = function() {
if((event.ctrlKey == true || event.metaKey == true) && event.keyCode == 83) {
event.preventDefault();
}
if((event.ctrlKey == true || event.metaKey == true) && event.code == 83) {
event.preventDefault();
}
}
}
if (noPrint)
{
var c=document.createElement("span");
c.style.display="none";
c.style.postion="absolute";
c.style.background="#000";
var first=document.body.firstChild;
var wraphtml=document.body.insertBefore(c,first);
c.setAttribute('width', document.body.scrollWidth);
c.setAttribute('height', document.body.scrollHeight);
c.style.display="block";
var cssNode3 = document.createElement('style');
cssNode3.type = 'text/css';
cssNode3.media = 'print';
cssNode3.innerHTML ='body{display:none}';
document.head.appendChild(cssNode3);
}
var cssNode2 = document.createElement('style');
cssNode2.type = 'text/css';
cssNode2.media = 'screen';
cssNode2.innerHTML ='div{-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}';
document.head.appendChild(cssNode2);
document.body.style.cssText="-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;";
function toBlur()
{
if (autoBlur)
document.body.style.cssText="-webkit-filter: blur(5px);-moz-filter: blur(5px);-ms-filter: blur(5px);-o-filter: blur(5px);filter: blur(5px);"
}
function toClear()
{
document.body.style.cssText="-webkit-filter: blur(0px);-moz-filter: blur(0px);-ms-filter: blur(0px);-o-filter: blur(0px);filter: blur(0px);"
}
document.onclick = function(event){
toClear();
}
document.onmouseleave = function(event){
toBlur();
}
document.onblur = function(event){
toBlur();
}
document.addEventListener('keyup', (e) => {
if (e.key == 'PrintScreen') {
if (noScreenshot)
{
navigator.clipboard.writeText('');
}
}
});
document.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key == 'p') {
if (noPrint)
{
e.cancelBubble = true;
e.preventDefault();
e.stopImmediatePropagation();
}
}
});