Skip to content

Commit cdd7b94

Browse files
committed
custom Message
1 parent cf139c5 commit cdd7b94

File tree

3 files changed

+92
-33
lines changed

3 files changed

+92
-33
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ noScreenshot({
2828
disableFunctionKeys: true,
2929
disableCtrlF4: true,
3030
mouseLeave: true, // required for overlay with mouse leave a browser window
31+
mouseEnterAutoHide: false, // required for auto hide overlay with mouse enter a browser window
3132
ctrlOverlay: true,
3233
altOverlay: false, // must be pass true for overlay with Alt or Options key press
3334
shiftOverlay: false, // must be pass true for overlay with Shift key press
34-
});
35+
} , 'custom-overlay-id');
3536
```
3637

3738
This function will disable right-click, keyboard shortcuts, inspect element, print screen, and various other methods commonly used for taking screenshots. Additionally, it will overlay a message on the screen indicating that screenshots are disabled.
3839

40+
Make sure to replace "custom-overlay-id" with the ID of the custom overlay you want to use, or omit it to use the default overlay.
41+
3942
```html
4043
<!DOCTYPE html>
4144
<html lang="en">
@@ -75,6 +78,7 @@ The `noScreenshot` function accepts the following options:
7578
- `disableFunctionKeys`: Disables function keys (F1-F12).
7679
- `disableCtrlF4`: Disables the Ctrl+F4 key combination.
7780
- `mouseLeave`: Activates overlay when cursor leaves the window.
81+
- `mouseEnterAutoHide`: Activates overlay when cursor enters the window.
7882
- `ctrlOverlay`: Activates overlay when Ctrl or Command key is pressed.
7983
- `altOverlay`: Activates overlay when Alt or Options key is pressed.
8084
- `shiftOverlay`: Activates overlay when Shift key is pressed.
@@ -94,10 +98,11 @@ window.onload = function() {
9498
disableFunctionKeys: true,
9599
disableCtrlF4: true,
96100
mouseLeave: true,
101+
mouseEnterAutoHide: false,
97102
ctrlOverlay: true,
98103
altOverlay: true,
99104
shiftOverlay: true,
100-
});
105+
} , 'custom-overlay-id');
101106
};
102107
```
103108

@@ -115,9 +120,11 @@ The `noScreenshot` function disables various methods of taking screenshots and o
115120
- `disableFunctionKeys`
116121
- `disableCtrlF4`
117122
- `mouseLeave`
123+
- `mouseEnterAutoHide`
118124
- `ctrlOverlay`
119125
- `altOverlay`
120126
- `shiftOverlay`
127+
- `overlayId`: Optional parameter to specify the ID of a custom overlay to use instead of the default one.
121128

122129
## License
123130

dist/secure-web.js

+82-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function noScreenshot(options) {
1+
function noScreenshot(options , overlayId) {
22
options = options || {};
33

44
const {
@@ -10,6 +10,7 @@ function noScreenshot(options) {
1010
disableFunctionKeys = true,
1111
disableCtrlF4 = true,
1212
mouseLeave = true,
13+
mouseEnterAutoHide = false,
1314
ctrlOverlay = true,
1415
altOverlay = false,
1516
shiftOverlay = false,
@@ -122,60 +123,97 @@ function noScreenshot(options) {
122123

123124
if (mouseLeave) {
124125
document.addEventListener('mouseleave', () => {
125-
overlayScreen(); // Overlay when cursor leaves the window
126+
overlayScreen(overlayId); // Overlay when cursor leaves the window
126127
});
127128
}
128129

130+
if (mouseEnterAutoHide) {
131+
document.addEventListener('mouseenter', () => {
132+
HideOverlayScreen(overlayId);
133+
});
134+
}
135+
129136
if (ctrlOverlay) {
130137
document.addEventListener('keydown', event => {
131138
if (event.ctrlKey || event.metaKey) {
132-
overlayScreen();
139+
overlayScreen(overlayId);
133140
}
134141
});
135142
}
136143

137144
if (altOverlay) {
138145
document.addEventListener('keydown', event => {
139146
if (event.altKey || event.optionsKey) {
140-
overlayScreen();
147+
overlayScreen(overlayId);
141148
}
142149
});
143150
}
144151

145152
if (shiftOverlay) {
146153
document.addEventListener('keydown', event => {
147154
if (event.shiftKey) {
148-
overlayScreen();
155+
overlayScreen(overlayId);
149156
}
150157
});
151158
}
152159
}
153160

161+
function overlayScreen(overlayId) {
162+
if (overlayId) {
163+
const customOverlay = document.getElementById(overlayId);
164+
if (customOverlay) {
165+
customOverlay.style.position = 'fixed';
166+
customOverlay.style.top = '0';
167+
customOverlay.style.left = '0';
168+
customOverlay.style.width = '100%';
169+
customOverlay.style.height = '100%';
170+
customOverlay.style.zIndex = '9999';
171+
customOverlay.style.display = 'flex';
172+
customOverlay.style.alignItems = 'center';
173+
customOverlay.style.justifyContent = 'center';
174+
175+
// Disable pointer events on body while the overlay is active
176+
document.body.style.pointerEvents = 'none';
177+
178+
document.addEventListener('keydown', escListener);
179+
180+
function escListener(event) {
181+
if (event.key === 'Escape') {
182+
customOverlay.style.display = 'none'; // Hide the custom overlay
183+
document.body.style.pointerEvents = 'auto'; // Re-enable pointer events on body
184+
document.removeEventListener('keydown', escListener);
185+
}
186+
}
187+
188+
return;
189+
}
190+
}
154191

155-
function overlayScreen() {
156-
const overlay = document.createElement('div');
157-
overlay.style.position = 'fixed';
158-
overlay.style.top = '0';
159-
overlay.style.left = '0';
160-
overlay.style.width = '100%';
161-
overlay.style.height = '100%';
162-
overlay.style.background = 'rgba(255, 255, 255, 1)'; // semi-transparent white background
163-
overlay.style.zIndex = '9999';
164-
overlay.style.display = 'flex';
165-
overlay.style.alignItems = 'center';
166-
overlay.style.justifyContent = 'center';
167-
168-
const message = document.createElement('div');
169-
message.textContent = 'Press Esc to close. Screenshots are disabled.';
170-
message.style.fontSize = '24px';
171-
message.style.color = 'black'; // You can adjust the color as needed
172-
message.style.padding = '20px'; // Add padding to the message
173-
message.style.background = 'rgba(255, 255, 255, 0.9)'; // semi-transparent white background for message
174-
message.style.borderRadius = '10px'; // Rounded corners for the message box
175-
message.style.boxShadow = '0px 0px 10px rgba(0, 0, 0, 0.5)'; // Drop shadow for the message box
176-
177-
overlay.appendChild(message);
178-
document.body.appendChild(overlay);
192+
const overlay = document.createElement('div');
193+
overlay.id = 'no-screenshot-overlay';
194+
overlay.style.position = 'fixed';
195+
overlay.style.top = '0';
196+
overlay.style.left = '0';
197+
overlay.style.width = '100%';
198+
overlay.style.height = '100%';
199+
overlay.style.background = 'rgba(255, 255, 255, 1)'; // semi-transparent white background
200+
overlay.style.zIndex = '9999';
201+
overlay.style.display = 'flex';
202+
overlay.style.alignItems = 'center';
203+
overlay.style.justifyContent = 'center';
204+
205+
const message = document.createElement('div');
206+
message.textContent = 'Press Esc to close. Screenshots are disabled.';
207+
message.style.fontSize = '24px';
208+
message.style.color = 'black'; // You can adjust the color as needed
209+
message.style.padding = '20px'; // Add padding to the message
210+
message.style.background = 'rgba(255, 255, 255, 0.9)'; // semi-transparent white background for message
211+
message.style.borderRadius = '10px'; // Rounded corners for the message box
212+
message.style.boxShadow = '0px 0px 10px rgba(0, 0, 0, 0.5)'; // Drop shadow for the message box
213+
214+
overlay.appendChild(message);
215+
document.body.appendChild(overlay);
216+
}
179217

180218
// Disable pointer events on body while the overlay is active
181219
document.body.style.pointerEvents = 'none';
@@ -188,7 +226,21 @@ function overlayScreen() {
188226
document.body.style.pointerEvents = 'auto'; // Re-enable pointer events on body
189227
document.removeEventListener('keydown', escListener);
190228
}
191-
}
229+
}
230+
231+
function HideOverlayScreen(overlayId) {
232+
if (overlayId) {
233+
const customOverlay = document.getElementById(overlayId);
234+
if (customOverlay) {
235+
customOverlay.style.display = 'none'; // Hide the custom overlay
236+
document.body.style.pointerEvents = 'auto'; // Re-enable pointer events on body
237+
return;
238+
}
239+
}
240+
var overlay = document.getElementById('no-screenshot-overlay');
241+
document.body.removeChild(overlay);
242+
document.body.style.pointerEvents = 'auto'; // Re-enable pointer events on body
243+
document.removeEventListener('keydown', escListener);
192244
}
193245

194246
module.exports = noScreenshot;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "secure-web",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Secure-Web is an npm package that prevents users from taking screenshots of your web page by securing it against various methods of screenshot capture. With customizable options to tailor the security measures according to your needs, Secure-Web ensures that your sensitive information remains protected and inaccessible to unauthorized individuals. Embrace the power of Secure-Web and take control of your online security today.",
55
"main": "old/secure-web.js",
66
"scripts": {

0 commit comments

Comments
 (0)