Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luizbizzio/siteguard
A JavaScript utility designed to detect and respond to the opening of developer tools in web browsers. It prevents right-click actions, drag events, and certain keyboard shortcuts, enhancing the protection of web content from unauthorized inspection.
https://github.com/luizbizzio/siteguard
anti blocker content-protection copy devtools javascript lock prevent security steal website
Last synced: 3 months ago
JSON representation
A JavaScript utility designed to detect and respond to the opening of developer tools in web browsers. It prevents right-click actions, drag events, and certain keyboard shortcuts, enhancing the protection of web content from unauthorized inspection.
- Host: GitHub
- URL: https://github.com/luizbizzio/siteguard
- Owner: luizbizzio
- License: mit
- Created: 2024-10-26T11:08:19.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-08T18:27:33.000Z (3 months ago)
- Last Synced: 2024-11-08T19:24:07.829Z (3 months ago)
- Topics: anti, blocker, content-protection, copy, devtools, javascript, lock, prevent, security, steal, website
- Language: JavaScript
- Homepage: https://luizbizzio.github.io/siteguard-test/
- Size: 190 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SiteGuard π‘οΈ
**Version:** 1.1.2
**Author:** Luiz Bizzio
**License:** MIT
**Repository:** [GitHub - SiteGuard](https://github.com/luizbizzio/siteguard)
**Published:** 2024-11-08## Overview π
SiteGuard is your ultimate **JavaScript** tool for protecting web content! Safeguard your intellectual property by preventing unauthorized access and interactions on your website. With SiteGuard, you can maintain control over your content and deter unwanted actions.
## Test the Features! π΅οΈββοΈ
[**Try to Steal This Content!** π](https://luizbizzio.github.io/siteguard-test/)
**Challenge:** Test the SiteGuard's capabilities! Try to copy, save, or inspect the content on this page. Think you can bypass it? Give it a shot! π
## Features π
| Feature | Description | Status |
| ------- | ----------- | ------ |
| π Dev Tools Detection | Monitors for Developer Tools and clears content if detected. | β Active |
| π Prevent Dragging Elements | Disables dragging of elements to maintain content integrity. | β Active |
| π§ Block Middle-click | Disable Middle-click from opening new tabs and images. | β Active |
| π« Disable Right-Click Menu | Prevents the context menu from appearing to reduce content theft. | β Active |
| π Block Key Combinations | Stops users from opening developer tools and the JavaScript console using shortcuts. | β Active |
| π Prevent Text Selection | Disables text selection on your web pages, making copying difficult. | β Active |
| π¨οΈ Hide Content During Print | Hides all content when the user attempts to print the page. | β Active |## How to Use π§
### Minified Script Version (Recommended) β
This lightweight, minified version is ideal for most use cases. Itβs streamlined and efficient, offering full protection without additional comments.
```html
/*!-----------------------------------------------------------------------------
* SiteGuard - Version 1.1.2
* License: MIT
* Repository: https://github.com/luizbizzio/siteguard
* Published: 2024-11-08
* -------------------------------------------------------------------------- */
function af(){var e=!1;setInterval(function(){var t=performance.now();console.profile(),console.profileEnd(),console.clear&&console.clear(),10<performance.now()-t&&!e&&(e=!0,document.documentElement.innerHTML="",location.reload())},1)}af(),document.addEventListener("dragstart",e=>e.preventDefault()),document.addEventListener("auxclick",e=>{1===e.button&&(e.stopPropagation(),e.preventDefault())}),document.addEventListener("contextmenu",function(e){e.preventDefault()}),document.onkeydown=e=>{[{ctrl:!0,shift:!0,code:"KeyI"},{ctrl:!0,shift:!0,code:"KeyJ"},{ctrl:!0,shift:!0,code:"KeyV"},{ctrl:!0,shift:!0,code:"KeyC"},{ctrl:!0,code:"KeyU"},{ctrl:!0,code:"KeyP"},{ctrl:!0,code:"KeyS"},{ctrl:!0,code:"KeyJ"},{ctrl:!0,code:"KeyF"},{code:"F12"}].some(t=>!!t.ctrl===e.ctrlKey&&!!t.shift===e.shiftKey&&e.code===t.code)&&e.preventDefault()},document.addEventListener("DOMContentLoaded",function(){document.body.style.setProperty("user-select","none","important");let e=document.createElement("style");e.type="text/css",e.media="print",e.innerHTML="* { display: none !important; }",document.head.appendChild(e);let t=document.createElement("style");t.type="text/css",t.innerHTML="body {-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(t)});```
### **IMPORTANT β **
Ensure this script is embedded directly at the very beginning of the `` tag, before the `` tag. This prevents users from easily blocking the script and ensures no traces remain if content is auto-cleared.
---
### Explained Script Version π
```html
/*!-----------------------------------------------------------------------------
* SiteGuard - Version 1.1.2
* Author: Luiz Bizzio
* License: MIT
* Repository: https://github.com/luizbizzio/siteguard
* Published: 2024-11-08
* -------------------------------------------------------------------------- */// Dev Tools Detector
function af() {
var e = !1; // Initializes a variable to track the detection of DevTools
setInterval(function() {
var t = performance.now(); // Gets the current time in milliseconds
console.profile(); // Starts a profiling session for performance analysis
console.profileEnd(); // Ends the profiling session
console.clear && console.clear(); // Clears the console if supported
// Detects if the developer tools are open
if (10 < performance.now() - t && !e) { // Adjusts the sensitivity of the performance detector (Recommended value between 5 and 10ms).
// Setting the threshold below 10ms may cause the script to trigger on older devices,
// Higher values increase sensitivity, potentially causing false positives.e = true; // Set e to true to indicate DevTools are detected
document.documentElement.innerHTML = ""; // Clear the document
location.reload(); // Reload the page
}
}, 1); // Executes the function every millisecond
}af(); // Invokes the function to start detection
// 1. Prevents users from dragging elements
document.addEventListener("dragstart", e => e.preventDefault()); // Prevents the default drag behavior// 2. Blocks middle mouse button clicks
document.addEventListener("auxclick", e => {
if (1 === e.button) { // Checks if the middle mouse button was clicked
e.stopPropagation(); // Prevents the event from bubbling up
e.preventDefault(); // Prevents the default action
}
});// 3. Disables the context menu (right-click)
document.addEventListener("contextmenu", function(e) {
e.preventDefault(); // Prevents the context menu from appearing
});// 4. Blocks key combinations
document.onkeydown = e => {
// Defines an array of key combinations to block
[{
ctrl: !0,
shift: !0,
code: "KeyI" // Ctrl + Shift + I for Developer Tools
}, {
ctrl: !0,
shift: !0,
code: "KeyJ" // Ctrl + Shift + J for JavaScript console
}, {
ctrl: !0,
shift: !0,
code: "KeyV" // Ctrl + Shift + V for paste
}, {
ctrl: !0,
shift: !0,
code: "KeyC" // Ctrl + Shift + C for element inspector
}, {
ctrl: !0,
code: "KeyU" // Ctrl + U for view source
}, {
ctrl: !0,
code: "KeyP" // Ctrl + P for print
}, {
ctrl: !0,
code: "KeyS" // Ctrl + S for save
}, {
ctrl: !0,
code: "KeyJ" // Ctrl + J for downloads
}, {
ctrl: !0,
code: "KeyF" // Ctrl + F for find
}, {
code: "F12" // F12 for Developer Tools
}].some(t => !!t.ctrl === e.ctrlKey && !!t.shift === e.shiftKey && e.code === t.code) && e.preventDefault();
};// 5. Prevents text selection on the entire body of the document
document.addEventListener("DOMContentLoaded", function() {
// Sets the user-select property to none to disable text selection
document.body.style.setProperty('user-select', 'none', 'important');// Style to hide all content during printing
const printStyle = document.createElement("style");
printStyle.type = "text/css";
printStyle.media = "print";
printStyle.innerHTML = "* { display: none !important; }"; // Hides all content during print
document.head.appendChild(printStyle);// Style to disable text selection for various browsers
const selectTextCss = document.createElement("style");
selectTextCss.type = "text/css";
selectTextCss.innerHTML = "body {-webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}"; // Prevents text selection
document.head.appendChild(selectTextCss);
});```
## Function Explanations π
This project employs various JavaScript functions and event listeners to block access to developer tools and prevent unauthorized interactions. Below is a breakdown of each functionβs purpose and functionality.
---
### 1. Dev Tools Detection π
The main function, `af()`, continuously monitors for Dev Tools by assessing performance lag:
- **Execution:** Runs every 50ms to detect Dev Tools.
- **Method:** Utilizes `console.profile()` and `console.profileEnd()` to measure code execution time.
- **Action Triggered:** If execution time exceeds 10ms, it assumes Dev Tools are open and clears the entire `document.documentElement`.his approach effectively monitors Dev Tools access by checking for performance delays that typically occur when Dev Tools are active, all without impacting normal user interactions.
---
### 2. Prevent Dragging Elements π
To prevent element dragging, a `dragstart` event listener is added:
- **Execution:** `document.addEventListener("dragstart", e => e.preventDefault())`
- **Functionality:** Prevents users from saving images or content by dragging, thereby preserving both visual structure and content security.---
### 3. Block Middle-Click π§
To block the middle-click action, an `auxclick` event listener is used:
- **Execution:** `document.addEventListener("auxclick", e => e.button === 1 && (e.stopPropagation(), e.preventDefault()))`
- **Functionality:** Prevents middle-click from opening new tabs, limiting potential unintended navigation and reinforcing content access restrictions.---
### 4. Disable Right-Click Menu π«
To block the right-click context menu, a `contextmenu` event listener is used:
- **Execution:** `document.addEventListener("contextmenu", e => e.preventDefault())`
- **Functionality:** Disables right-click to reduce access to inspection options and content copying.---
### 5. Block Key Combinations π
This function blocks common shortcuts that open Dev Tools and other inspection options:
- **Monitored Combinations:** Includes `Ctrl + Shift + I`, `Ctrl + Shift + J`, `Ctrl + U`, `Ctrl + Shift + J`, and `F12`.
- **Execution:** Uses `document.onkeydown` to listen for key presses.
- **Functionality:** Prevents default actions of key combinations commonly used to access Dev Tools, the JavaScript console, and source code viewing.---
### 6. Prevent Text Selection π
To prevent text selection across the page, the `userSelect` property of `document.body` is set to `"none"`:
- **Execution:** `document.body.style.userSelect = "none"`
- **Functionality:** Disables text selection, providing another layer of protection against direct content copying.---
### 7. Hide Content During Print π¨οΈ
TTo prevent content from being printed, a specific style is added for the print media:
- **Execution:** `const printStyle = document.createElement("style");
printStyle.type = "text/css";
printStyle.media = "print";
printStyle.innerHTML = "* { display: none !important; }";
document.head.appendChild(printStyle);`
- **Functionality:** Hides all content during printing, ensuring that nothing from the page is printed.---
These combined functions form a comprehensive barrier against unauthorized content access and manipulation, ideal for safeguarding sensitive or proprietary content on web pages.
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.