mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
Disabling inspector element
This commit is contained in:
parent
8b860ddecd
commit
343d5ee6f5
6 changed files with 129 additions and 2 deletions
|
|
@ -11,7 +11,9 @@
|
|||
"build": "webpack --mode production",
|
||||
"test": "jest",
|
||||
"lint": "eslint src",
|
||||
"scan-translations": "pnpx jest ./tests/i18nScan.test.js"
|
||||
"scan-translations": "pnpx jest ./tests/i18nScan.test.js",
|
||||
"build:all": "npm run build && echo Build complete && echo Obfuscating... && node scripts/obfuscate.js",
|
||||
"serve": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "7.26.0",
|
||||
|
|
|
|||
0
scripts/README.md
Normal file
0
scripts/README.md
Normal file
59
scripts/obfuscate.js
Normal file
59
scripts/obfuscate.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const JavaScriptObfuscator = require('javascript-obfuscator');
|
||||
|
||||
const INPUT_DIR = path.join(__dirname, '..', 'dist');
|
||||
const OUTPUT_DIR = path.join(__dirname, '..', 'dist-obf');
|
||||
|
||||
function ensureDir(dir) {
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
function obfuscateFileContents(sourcePath, destPath) {
|
||||
const code = fs.readFileSync(sourcePath, 'utf8');
|
||||
const obf = JavaScriptObfuscator.obfuscate(code, {
|
||||
compact: true,
|
||||
controlFlowFlattening: true,
|
||||
controlFlowFlatteningThreshold: 0.75,
|
||||
deadCodeInjection: true,
|
||||
deadCodeInjectionThreshold: 0.4,
|
||||
stringArray: true,
|
||||
stringArrayEncoding: ['base64'],
|
||||
rotateStringArray: true,
|
||||
stringArrayThreshold: 0.75,
|
||||
});
|
||||
fs.writeFileSync(destPath, obf.getObfuscatedCode(), 'utf8');
|
||||
}
|
||||
|
||||
function copyAndObfuscate(srcDir, destDir) {
|
||||
ensureDir(destDir);
|
||||
for (const name of fs.readdirSync(srcDir)) {
|
||||
const srcPath = path.join(srcDir, name);
|
||||
const destPath = path.join(destDir, name);
|
||||
const stat = fs.statSync(srcPath);
|
||||
if (stat.isDirectory()) {
|
||||
copyAndObfuscate(srcPath, destPath);
|
||||
} else {
|
||||
if (name.endsWith('.js')) {
|
||||
obfuscateFileContents(srcPath, destPath);
|
||||
} else {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!fs.existsSync(INPUT_DIR)) {
|
||||
console.error('Input dist folder not found. Run `npm run build` first.');
|
||||
process.exit(1);
|
||||
}
|
||||
if (fs.existsSync(OUTPUT_DIR)) {
|
||||
fs.rmSync(OUTPUT_DIR, { recursive: true, force: true });
|
||||
}
|
||||
copyAndObfuscate(INPUT_DIR, OUTPUT_DIR);
|
||||
console.log('Obfuscated build written to:', OUTPUT_DIR);
|
||||
} catch (err) {
|
||||
console.error('Obfuscation failed', err);
|
||||
process.exit(1);
|
||||
}
|
||||
28
server.js
Normal file
28
server.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
const express = require('express');
|
||||
const helmet = require('helmet');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const DIST = path.join(__dirname, 'dist-obf');
|
||||
// Security middleware
|
||||
app.use(helmet());
|
||||
app.use(helmet.contentSecurityPolicy({
|
||||
directives: {
|
||||
defaultSrc: ["'self'"],
|
||||
scriptSrc: ["'self'"],
|
||||
styleSrc: ["'self'", "'unsafe-inline'"],
|
||||
imgSrc: ["'self'", 'data:'],
|
||||
connectSrc: ["'self'"],
|
||||
}
|
||||
}));
|
||||
|
||||
app.use(express.static(DIST));
|
||||
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(DIST, 'index.html'));
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on http://localhost:${PORT}`);
|
||||
});
|
||||
38
src/utils/antiInspect.js
Normal file
38
src/utils/antiInspect.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
function disableShortcuts() {
|
||||
document.addEventListener('contextmenu', (e) => e.preventDefault());
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (
|
||||
e.key === 'F12' ||
|
||||
(e.ctrlKey && e.shiftKey && (e.key === 'I' || e.key === 'C' || e.key === 'J')) ||
|
||||
(e.ctrlKey && e.key === 'u')
|
||||
) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
}, { capture: true });
|
||||
}
|
||||
|
||||
function detectDevTools(onDetect = () => {}) {
|
||||
let last = new Date().getTime();
|
||||
setInterval(() => {
|
||||
const t0 = new Date().getTime();
|
||||
debugger;
|
||||
const t1 = new Date().getTime();
|
||||
if (t1 - t0 > 100) {
|
||||
onDetect();
|
||||
}
|
||||
last = t1;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
export function initAntiInspect() {
|
||||
try {
|
||||
disableShortcuts();
|
||||
detectDevTools(() => {
|
||||
console.warn('Developer tools detected — reloading page.');
|
||||
window.location.reload();
|
||||
});
|
||||
} catch (e) {
|
||||
// fail silently
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,6 @@
|
|||
"strict": true,
|
||||
},
|
||||
"include": [
|
||||
"src/",
|
||||
"src/", "scripts",
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue