From 68d2d55bf56400635d97f1417cc89c119f974a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Dvo=C5=99=C3=A1k?= <150935816+Dvorinka@users.noreply.github.com> Date: Wed, 21 May 2025 11:40:41 +0200 Subject: [PATCH] Add files via upload --- index.html | 85 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index f1b1824..ca1265f 100644 --- a/index.html +++ b/index.html @@ -185,20 +185,79 @@ }); }); - // Function to open Windows Explorer with a specific path using our integrated Go server + // Function to open Windows Explorer with a specific path using multiple methods for compatibility function openWindowsFolder(path) { - // Call our Go server to open the folder in Windows Explorer - fetch(`/open?path=${encodeURIComponent(path)}`) - .then(response => { - if (!response.ok) { - throw new Error('Failed to open folder'); - } - console.log('Folder opened successfully'); - }) - .catch(error => { - console.error('Error opening folder:', error); - alert('Could not open folder. Make sure the server is running.'); - }); + // Method 1: Try using ActiveX (works in Internet Explorer) + if (window.ActiveXObject !== undefined) { + try { + const shell = new ActiveXObject("Shell.Application"); + shell.Explore(path); + console.log('Folder opened via ActiveX'); + return; + } catch (e) { + console.log("ActiveX failed or not supported: " + e.message); + } + } + + // Method 2: Try using the file:// protocol + try { + // Format the path for the file:// protocol + const formattedPath = path.replace(/\\/g, '/'); // Replace backslashes with forward slashes + const fileUrl = 'file:///' + formattedPath; + + // Open in a new window + const newWindow = window.open(fileUrl, '_blank'); + + // Check if window was blocked by popup blocker + if (newWindow) { + console.log('Folder opened via file:// protocol'); + return; + } else { + console.log('Popup was blocked'); + } + } catch (e) { + console.log("file:// protocol failed: " + e.message); + } + + // Method 3: Fallback to server-side approach if available + try { + fetch(`/open?path=${encodeURIComponent(path)}`) + .then(response => { + if (!response.ok) { + throw new Error('Server method failed'); + } + console.log('Folder opened via server'); + }) + .catch(error => { + // If all methods fail, show instructions to the user + console.error('All methods failed:', error); + showFolderInstructions(path); + }); + } catch (e) { + // If fetch isn't available or fails immediately + showFolderInstructions(path); + } + } + + // Show instructions to the user when all automatic methods fail + function showFolderInstructions(path) { + const instructions = ` +
+

Otevření složky Windows

+

Automatické otevření složky selhalo. Zkuste jeden z následujících postupů:

+
    +
  1. Zkopírujte tuto cestu:
  2. +
  3. Otevřete Průzkumník Windows (Win+E)
  4. +
  5. Vložte cestu do adresního řádku a stiskněte Enter
  6. +
+ +
+ `; + + const modal = document.createElement('div'); + modal.style.cssText = 'position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000;'; + modal.innerHTML = `
${instructions}
`; + document.body.appendChild(modal); }