diff --git a/backend/routes/clickTtHttpPageRoutes.js b/backend/routes/clickTtHttpPageRoutes.js
index 45d18fdf..619a4842 100644
--- a/backend/routes/clickTtHttpPageRoutes.js
+++ b/backend/routes/clickTtHttpPageRoutes.js
@@ -162,75 +162,61 @@ function rewriteFormActionsInHtml(html, proxyBaseUrl, pageBaseUrl, sid) {
function injectProxyNavigationScript(html, proxyBaseUrl, pageBaseUrl, sid) {
if (!html || !proxyBaseUrl || !pageBaseUrl) return html;
- const script = `
-`;
+ const scriptContent = [
+ '(function(){',
+ `var PROXY_BASE_URL=${JSON.stringify(proxyBaseUrl)};`,
+ `var PAGE_BASE_URL=${JSON.stringify(pageBaseUrl)};`,
+ `var SID=${JSON.stringify(sid || '')};`,
+ 'function normalizeUrl(value, base){',
+ 'if(!value)return null;',
+ "var trimmed=String(value).trim();",
+ "if(!trimmed||trimmed.indexOf('#')===0||trimmed.indexOf('javascript:')===0)return null;",
+ 'try{return new URL(trimmed, base||PAGE_BASE_URL).href;}catch(e){return null;}',
+ '}',
+ 'function shouldProxyUrl(value){',
+ 'try{var hostname=new URL(value).hostname;return /(^|\\\\.)click-tt\\\\.de$|(^|\\\\.)httv\\\\.de$/i.test(hostname);}catch(e){return false;}',
+ '}',
+ 'function buildProxyUrl(targetUrl){',
+ "var separator=PROXY_BASE_URL.indexOf('?')>=0?'&':'?';",
+ "return PROXY_BASE_URL+separator+'url='+encodeURIComponent(targetUrl)+(SID?'&sid='+encodeURIComponent(SID):'');",
+ '}',
+ 'function navigateViaProxy(targetUrl){',
+ 'if(!targetUrl||!shouldProxyUrl(targetUrl))return false;',
+ 'window.location.assign(buildProxyUrl(targetUrl));',
+ 'return true;',
+ '}',
+ 'function getSubmitTarget(form, submitter){',
+ "var action=submitter&&submitter.getAttribute?submitter.getAttribute('formaction'):null;",
+ 'if(action)return normalizeUrl(action,PAGE_BASE_URL);',
+ "return normalizeUrl((form&&form.getAttribute?form.getAttribute('action'):null)||PAGE_BASE_URL,PAGE_BASE_URL);",
+ '}',
+ "document.addEventListener('click',function(event){",
+ "var anchor=event.target&&event.target.closest?event.target.closest('a[href]'):null;",
+ 'if(!anchor||event.defaultPrevented)return;',
+ "var targetUrl=normalizeUrl(anchor.getAttribute('href'),PAGE_BASE_URL);",
+ 'if(!targetUrl||!shouldProxyUrl(targetUrl))return;',
+ 'event.preventDefault();',
+ 'navigateViaProxy(targetUrl);',
+ '},false);',
+ "document.addEventListener('submit',function(event){",
+ 'var form=event.target;',
+ "if(!form||!form.tagName||form.tagName.toLowerCase()!=='form')return;",
+ 'var submitter=event.submitter||null;',
+ 'var targetUrl=getSubmitTarget(form,submitter);',
+ 'if(!targetUrl||!shouldProxyUrl(targetUrl))return;',
+ "form.setAttribute('action',buildProxyUrl(targetUrl));",
+ '},true);',
+ 'if(window.HTMLFormElement&&window.HTMLFormElement.prototype&&window.HTMLFormElement.prototype.submit){',
+ 'var nativeSubmit=window.HTMLFormElement.prototype.submit;',
+ 'window.HTMLFormElement.prototype.submit=function patchedSubmit(){',
+ 'var targetUrl=getSubmitTarget(this,null);',
+ "if(targetUrl&&shouldProxyUrl(targetUrl)){this.setAttribute('action',buildProxyUrl(targetUrl));}",
+ 'return nativeSubmit.apply(this,arguments);',
+ '};',
+ '}',
+ '})();',
+ ].join('');
+ const script = `