<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Whituv Cloner</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #c26969;
            color: #333;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 80%;
            max-width: 1000px;
            margin: 50px auto;
            padding: 20px;
            background-color: white;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        header {
            text-align: center;
            margin-bottom: 30px;
        }

        header h1 {
            color: #007BFF;
        }

        h2 {
            color: #333;
        }

        .input-section, .output-section {
            margin-bottom: 30px;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-bottom: 15px;
        }

        button {
            padding: 10px 20px;
            font-size: 16px;
            color: white;
            background-color: #007BFF;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        .cloned-output {
            padding: 15px;
            background-color: #f0f0f0;
            border: 1px solid #ddd;
            border-radius: 5px;
            min-height: 100px;
        }

        .cloned-output img {
            max-width: 100%;
            margin-top: 10px;
        }

        .download-section {
            margin-top: 20px;
        }

        .download-btn {
            padding: 10px 20px;
            font-size: 16px;
            color: white;
            background-color: #4bba20;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        .download-btn:hover {
            background-color: #218838;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>Whituv Clone
                t.me/uvwhit</h1>
            <p>Clone metadata (title, description, images) and download HTML, CSS, and JS from any website!</p>
        </header>

        <section class="input-section">
            <h2>Enter Website URL</h2>
            <input type="text" id="urlInput" placeholder="Enter the URL to clone" />
            <button onclick="cloneWebsite()">Clone Website</button>
        </section>

        <section class="output-section">
            <h2>Cloned Website Content</h2>
            <div id="clonedContent"></div>
        </section>

        <section class="download-section" id="downloadSection" style="display: none;">
            <h3>Download Website Files</h3>
            <button class="download-btn" onclick="downloadHTML()">Download HTML</button>
            <button class="download-btn" onclick="downloadCSS()">Download CSS</button>
            <button class="download-btn" onclick="downloadJS()">Download JS</button>
        </section>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>

    <script>
        // Function to fetch website HTML and linked CSS/JS files through AllOrigins proxy
        async function cloneWebsite() {
            const url = document.getElementById('urlInput').value;
            const clonedContentArea = document.getElementById('clonedContent');
            const downloadSection = document.getElementById('downloadSection');

            if (url.trim() === "") {
                clonedContentArea.innerHTML = "<p style='color: red;'>Please enter a valid URL.</p>";
                return;
            }

            try {
                // Use AllOrigins proxy to bypass CORS restrictions
                const response = await fetch(`https://api.allorigins.win/get?url=${encodeURIComponent(url)}`);
                const data = await response.json();

                if (data && data.contents) {
                    const html = data.contents;
                    clonedContentArea.innerHTML = "<h3>Cloned Website HTML:</h3><pre>" + html.substring(0, 1000) + "...</pre>"; // Display part of the HTML

                    downloadSection.style.display = 'block'; // Show download options

                    // Fetch linked CSS and JS files using regular expressions
                    const doc = new DOMParser().parseFromString(html, 'text/html');
                    const cssLinks = Array.from(doc.querySelectorAll('link[rel="stylesheet"]')).map(link => link.href);
                    const jsScripts = Array.from(doc.querySelectorAll('script[src]')).map(script => script.src);

                    // Store resources for downloading later
                    window.siteResources = {
                        html,
                        cssLinks,
                        jsScripts
                    };
                } else {
                    clonedContentArea.innerHTML = "<p style='color: red;'>Unable to fetch website content. Please try again later.</p>";
                }
            } catch (error) {
                clonedContentArea.innerHTML = "<p style='color: red;'>Failed to fetch the website data. Please check the URL or try again later.</p>";
            }
        }

        // Function to download HTML file
        function downloadHTML() {
            const htmlBlob = new Blob([window.siteResources.html], { type: 'text/html' });
            saveAs(htmlBlob, 'UVindex.html');
        }

        // Function to download CSS files
        async function downloadCSS() {
            const cssPromises = window.siteResources.cssLinks.map(async (url) => {
                const response = await fetch(url);
                const css = await response.text();
                return css;
            });

            const cssFiles = await Promise.all(cssPromises);
            cssFiles.forEach((css, index) => {
                const cssBlob = new Blob([css], { type: 'text/css' });
                saveAs(cssBlob, `style${index + 1}.css`);
            });
        }

        // Function to download JS files
        async function downloadJS() {
            const jsPromises = window.siteResources.jsScripts.map(async (url) => {
                const response = await fetch(url);
                const js = await response.text();
                return js;
            });

            const jsFiles = await Promise.all(jsPromises);
            jsFiles.forEach((js, index) => {
                const jsBlob = new Blob([js], { type: 'application/javascript' });
                saveAs(jsBlob, `script${index + 1}.js`);
            });
        }
    </script>
</body>
</html>