Atualização automática: 2026-05-18 18:11:46

This commit is contained in:
Hermes
2026-05-18 18:11:46 +00:00
parent 700c47277d
commit 582977fc7a
+70 -28
View File
@@ -34,7 +34,7 @@ app.use(express.static(path.join(__dirname, 'public'), {
} }
})); }));
// Middleware para injetar fix de roteador em sites clonados (SPAs como React, Vue, Angular, Vite) // Middleware para injetar fix de roteador em sites clonados (SPAs como React, Vue, Angular, Vite) e reescrever JS
app.use((req, res, next) => { app.use((req, res, next) => {
if (!req.path.startsWith('/api') && req.path !== '/' && req.path !== '/old') { if (!req.path.startsWith('/api') && req.path !== '/' && req.path !== '/old') {
let urlPath = req.path; let urlPath = req.path;
@@ -48,6 +48,7 @@ app.use((req, res, next) => {
urlPath += 'index.html'; urlPath += 'index.html';
} }
// Interceptação de arquivos HTML (Camada 1 - DOM Mock Universal)
if (urlPath.endsWith('.html')) { if (urlPath.endsWith('.html')) {
const filePath = path.join(__dirname, '..', 'cloned-sites', urlPath); const filePath = path.join(__dirname, '..', 'cloned-sites', urlPath);
if (fs.existsSync(filePath)) { if (fs.existsSync(filePath)) {
@@ -58,32 +59,50 @@ app.use((req, res, next) => {
<script id="__CLONEWEB_ROUTER_FIX__"> <script id="__CLONEWEB_ROUTER_FIX__">
(function() { (function() {
try { try {
const originalPathname = Object.getOwnPropertyDescriptor(Location.prototype, 'pathname').get; window.__mockLocationPathname = '/';
const originalHref = Object.getOwnPropertyDescriptor(Location.prototype, 'href').get; window.__mockLocationHref = window.location.protocol + '//' + window.location.host + '/';
Object.defineProperty(Location.prototype, 'pathname', {
get: function() {
const path = originalPathname.call(this);
if (path !== '/' && path !== '/index.html' && (path.includes('_202') || path.includes('/cloned-sites/'))) {
return '/';
}
return path;
},
set: function(val) {
window.location.assign(val);
}
});
Object.defineProperty(Location.prototype, 'href', { let targetObj = window.location;
get: function() { let proto = Object.getPrototypeOf(targetObj);
const href = originalHref.call(this); let pathDesc = null;
if (href.includes('_202') || href.includes('/cloned-sites/')) { let hrefDesc = null;
const url = new URL(href);
return url.protocol + '//' + url.host + '/'; while (proto && (!pathDesc || !hrefDesc)) {
} if (!pathDesc) pathDesc = Object.getOwnPropertyDescriptor(proto, 'pathname');
return href; if (!hrefDesc) hrefDesc = Object.getOwnPropertyDescriptor(proto, 'href');
} proto = Object.getPrototypeOf(proto);
}); }
if (!pathDesc) pathDesc = Object.getOwnPropertyDescriptor(targetObj, 'pathname');
if (!hrefDesc) hrefDesc = Object.getOwnPropertyDescriptor(targetObj, 'href');
if (pathDesc && pathDesc.configurable) {
const origGet = pathDesc.get;
Object.defineProperty(proto || targetObj, 'pathname', {
get: function() {
const p = origGet ? origGet.call(this) : this.pathname;
if (p !== '/' && p !== '/index.html' && (p.includes('_202') || p.includes('/cloned-sites/'))) {
return '/';
}
return p;
},
set: pathDesc.set || function(v) { window.location.assign(v); }
});
}
if (hrefDesc && hrefDesc.configurable) {
const origHrefGet = hrefDesc.get;
Object.defineProperty(proto || targetObj, 'href', {
get: function() {
const h = origHrefGet ? origHrefGet.call(this) : this.href;
if (h.includes('_202') || h.includes('/cloned-sites/')) {
const u = new URL(h);
return u.protocol + '//' + u.host + '/';
}
return h;
},
set: hrefDesc.set || function(v) { window.location.assign(v); }
});
}
const OriginalURL = window.URL; const OriginalURL = window.URL;
window.URL = function(url, base) { window.URL = function(url, base) {
@@ -95,9 +114,9 @@ app.use((req, res, next) => {
window.URL.prototype = OriginalURL.prototype; window.URL.prototype = OriginalURL.prototype;
Object.assign(window.URL, OriginalURL); Object.assign(window.URL, OriginalURL);
console.log('🚀 [CloneWeb] Ultimate SPA Router fix initialized. Simulating root pathname /'); console.log('🚀 [CloneWeb] Ultimate SPA Router fix initialized successfully (Cross-browser Gecko/Blink support).');
} catch(e) { } catch(e) {
console.error(' [CloneWeb] Failed to initialize router fix:', e); console.error('⚠️ [CloneWeb] DOM mock fallback active. Using __mockLocationPathname. Error:', e);
} }
})(); })();
</script> </script>
@@ -115,6 +134,29 @@ app.use((req, res, next) => {
} }
} }
} }
// Interceptação de arquivos JS de sites clonados (Camada 2 - JS Rewriter Supremo)
if (urlPath.endsWith('.js') && (urlPath.includes('_202') || urlPath.includes('/cloned-sites/'))) {
const filePath = path.join(__dirname, '..', 'cloned-sites', urlPath);
if (fs.existsSync(filePath)) {
try {
let jsContent = fs.readFileSync(filePath, 'utf8');
// Substitui chamadas diretas a window.location.pathname e location.pathname
jsContent = jsContent.replace(/window\.location\.pathname/g, '(window.__mockLocationPathname || window.location.pathname)');
jsContent = jsContent.replace(/location\.pathname/g, '(window.__mockLocationPathname || window.location.pathname)');
// Substitui chamadas diretas a window.location.href e location.href
jsContent = jsContent.replace(/window\.location\.href/g, '(window.__mockLocationHref || window.location.href)');
jsContent = jsContent.replace(/location\.href/g, '(window.__mockLocationHref || window.location.href)');
res.setHeader('Content-Type', 'application/javascript');
return res.send(jsContent);
} catch (err) {
console.error('Erro ao reescrever JS do clone:', err);
}
}
}
} }
next(); next();
}); });