HTML Tool Generator Code

 HTML (index.html)



<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>HTML Tool Generator</title>

    <link rel="stylesheet" href="styles.css">

</head>

<body>

    <div id="container">

        <h1>HTML Tool Generator</h1>

        <textarea id="toolInput" rows="3" placeholder="Describe your tool idea..."></textarea>

        <button id="generateBtn">Generate Code</button>

        <div id="result"></div>

        <button class="copy-btn" id="copyBtn" style="display: none;">Copy Code</button>

    </div>

    <script src="script.js"></script>

</body>

</html>


CSS (styles.css)


body {

    font-family: Arial, sans-serif;

    margin: 0;

    padding: 0;

    background: #f4f4f9;

}


#container {

    max-width: 800px;

    margin: 20px auto;

    padding: 20px;

    background: white;

    border-radius: 8px;

    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

}


textarea {

    width: 100%;

    padding: 10px;

    border: 1px solid #ddd;

    border-radius: 5px;

    margin-bottom: 10px;

}


button {

    padding: 10px 20px;

    background: #4e54c8;

    color: white;

    border: none;

    border-radius: 5px;

    cursor: pointer;

    transition: background 0.3s ease, transform 0.2s ease;

}


button:hover {

    background: #8f94fb;

    transform: scale(1.05);

}


button:active {

    transform: scale(0.98);

}


#result {

    margin-top: 20px;

    padding: 10px;

    background: #f8f9fa;

    border: 1px dashed #ccc;

    white-space: pre-wrap;

    font-family: monospace;

}


.copy-btn {

    margin-top: 10px;

    padding: 10px;

    background: #28a745;

    color: white;

    border: none;

    border-radius: 5px;

    cursor: pointer;

    transition: transform 0.2s ease, background 0.3s ease;

}


.copy-btn:hover {

    background: #218838;

    transform: scale(1.05);

}


.copy-btn:active {

    transform: scale(0.98);

}


/* Responsiveness */

@media (max-width: 768px) {

    #container {

        width: 90%;

    }

}


@media (max-width: 480px) {

    #container {

        width: 100%;

    }

}



JavaScript (script.js) 


const API_KEY = ""; // Replace with your OpenAI API key


document.getElementById('generateBtn').addEventListener('click', async () => {

    const input = document.getElementById('toolInput').value;

    if (!input) {

        alert('Please provide a tool description.');

        return;

    }


    document.getElementById('result').innerText = "Generating...";

    document.getElementById('copyBtn').style.display = "none";


    try {

        const response = await fetch('https://api.openai.com/v1/chat/completions', {

            method: 'POST',

            headers: {

                'Content-Type': 'application/json',

                'Authorization': `Bearer ${API_KEY}`

            },

            body: JSON.stringify({

                model: "gpt-4",

                messages: [{ role: "user", content: input }]

            })

        });


        const data = await response.json();

        const code = data.choices[0].message.content;


        document.getElementById('result').innerText = code;

        document.getElementById('copyBtn').style.display = "block";

    } catch (error) {

        alert('An error occurred. Please check your API key or try again later.');

        console.error(error);

    }

});


// Copy code to clipboard

document.getElementById('copyBtn').addEventListener('click', () => {

    const code = document.getElementById('result').innerText;

    navigator.clipboard.writeText(code).then(() => {

        alert('Code copied to clipboard!');

    });

});



Complete responsive code is here!

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>HTML Tool Generator</title>

    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">

    <style>

        body {

            font-family: Arial, sans-serif;

            margin: 0;

            padding: 0;

            background: #f4f4f9;

        }


        #container {

            max-width: 800px;

            margin: 20px auto;

            padding: 20px;

            background: white;

            border-radius: 8px;

            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

        }


        textarea {

            width: 100%;

            padding: 10px;

            border: 1px solid #ddd;

            border-radius: 5px;

            margin-bottom: 10px;

        }


        button {

            padding: 10px 20px;

            background: #4e54c8;

            color: white;

            border: none;

            border-radius: 5px;

            cursor: pointer;

            transition: background 0.3s ease, transform 0.2s ease;

        }


        button:hover {

            background: #8f94fb;

            transform: scale(1.05);

        }


        button:active {

            transform: scale(0.98);

        }


        #result {

            margin-top: 20px;

            padding: 10px;

            background: #f8f9fa;

            border: 1px dashed #ccc;

            white-space: pre-wrap;

            font-family: monospace;

        }


        .copy-btn {

            margin-top: 10px;

            padding: 10px;

            background: #28a745;

            color: white;

            border: none;

            border-radius: 5px;

            cursor: pointer;

            transition: transform 0.2s ease, background 0.3s ease;

        }


        .copy-btn:hover {

            background: #218838;

            transform: scale(1.05);

        }


        .copy-btn:active {

            transform: scale(0.98);

        }


        /* Responsiveness */

        @media (max-width: 768px) {

            #container {

                width: 90%;

            }

        }


        @media (max-width: 480px) {

            #container {

                width: 100%;

            }

        }

    </style>

</head>

<body>

    <div id="container">

        <h1>HTML Tool Generator</h1>

        <textarea id="toolInput" rows="3" placeholder="Describe your tool idea..."></textarea>

        <button id="generateBtn">Generate Code</button>

        <div id="result"></div>

        <button class="copy-btn" id="copyBtn" style="display: none;">Copy Code</button>

    </div>


    <script>

        const API_KEY = ""; // Replace with your OpenAI API key


        document.getElementById('generateBtn').addEventListener('click', async () => {

            const input = document.getElementById('toolInput').value;

            if (!input) {

                alert('Please provide a tool description.');

                return;

            }


            document.getElementById('result').innerText = "Generating...";

            document.getElementById('copyBtn').style.display = "none";


            try {

                const response = await fetch('https://api.openai.com/v1/chat/completions', {

                    method: 'POST',

                    headers: {

                        'Content-Type': 'application/json',

                        'Authorization': `Bearer ${API_KEY}`

                    },

                    body: JSON.stringify({

                        model: "gpt-4",

                        messages: [{ role: "user", content: input }]

                    })

                });


                const data = await response.json();

                const code = data.choices[0].message.content;


                document.getElementById('result').innerText = code;

                document.getElementById('copyBtn').style.display = "block";

            } catch (error) {

                alert('An error occurred. Please check your API key or try again later.');

                console.error(error);

            }

        });


        // Copy code to clipboard

        document.getElementById('copyBtn').addEventListener('click', () => {

            const code = document.getElementById('result').innerText;

            navigator.clipboard.writeText(code).then(() => {

                alert('Code copied to clipboard!');

            });

        });

    </script>

</body>

</html>


WhatsApp Share Button Share on WhatsApp

Post a Comment

0 Comments
Post a Comment (0)
To Top