Category: Prompts

  • K-Scrubber

    Here is the prompt, code and working deployment of K-Scrubber that helps you removing unwanted characters from text.

    The “K-Scrubber” Project Prompt
    Objective
    : Create a high-end, single-page web utility called “K-Scrubber.” The tool allows users to paste text, specify characters to remove, and receive a “cleaned” version where those characters are replaced by a single space, ensuring no double-spaces remain.

    1. Design & UI Requirements
    Visual
    Style: Modern “Glassmorphism” or “Apple-esque” minimalism. Use a soft background gradient (e.g., #e0eafc to #cfdef3).
    The Card: A centered, semi-transparent white glass container with a subtle backdrop-filter: blur(10px) and a soft 0 20px 50px rgba(0,0,0,0.1) shadow.
    Typography: Use “Inter” or “Poppins” (system-font fallback). Headings should be bold and dark (#2d3436), body text should be clear.
    Interactions: * Buttons should have a subtle scale effect (transform: scale(0.98)) when clicked.

    Use a primary accent color like Indigo (#6366f1) for the action button.
    Include a “Copy to Clipboard” button that shows a “Copied!” tooltip or toast notification.

    2. Functional Logic (The “Brain”)
    The JavaScript must follow these specific steps in order:

    Capture Inputs: Take the string from inputText and the string from targetChars.
    Escape Special Characters: Automatically escape any special regex characters (like ., *, ?) entered in the targetChars field to prevent script errors.
    The Replacement Logic:

    Step A: Use a global Regular Expression to find all instances of targetChars and replace them with a standard space ( ).
    Step B: Use the regex /\s+/g to find any sequence of multiple whitespace characters (spaces, tabs, newlines) and replace them with a single space.
    Step C: Apply .trim() to ensure the final string doesn’t start or end with an unnecessary space.
    Real-time Option: (Optional but preferred) Add a toggle to “Clean as I type.”
    3. Layout Structure
    Header:
    Small “K” logo and the title “K-Scrubber.”
    Main Input: A large, auto-expanding textarea.
    Control Row:A text input for “Characters to Scrub” and a “Clean Text” button.
    Output Area:A read-only textarea with a different background color (e.g., very light indigo) to distinguish it.
    Footer: A “Characters Removed” counter to show the user how much “junk” was scrubbed.
    4. Technical Constraints
    Single File:
    Provide everything in one index.html file (HTML5, CSS3, Vanilla JS).
    Responsive: Must look perfect on mobile devices and ultrawide monitors alike.
    Clean Code:Use semantic HTML and well-commented JavaScript.

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta charset="UTF-8">

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

    <title>K-Scrubber | Premium Text Utility</title>

    <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🇰</text></svg>">

    <link rel="preconnect" href="https://fonts.googleapis.com">

    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">



    <style>

    :root {

    --primary: #6366f1;

    --primary-hover: #4f46e5;

    --bg-gradient: linear-gradient(135deg, #e0eafc 0%, #cfdef3 100%);

    --glass-bg: rgba(255, 255, 255, 0.7);

    --text-main: #1f2937;

    --text-muted: #6b7280;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    }



    * {

    margin: 0;

    padding: 0;

    box-sizing: border-box;

    font-family: 'Inter', sans-serif;

    }



    body {

    min-height: 100vh;

    background: var(--bg-gradient);

    display: flex;

    align-items: center;

    justify-content: center;

    padding: 20px;

    }



    .glass-card {

    background: var(--glass-bg);

    backdrop-filter: blur(12px);

    -webkit-backdrop-filter: blur(12px);

    border: 1px solid rgba(255, 255, 255, 0.3);

    border-radius: 24px;

    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);

    width: 100%;

    max-width: 700px;

    padding: 40px;

    animation: fadeIn 0.8s ease-out;

    }



    @keyframes fadeIn {

    from { opacity: 0; transform: translateY(20px); }

    to { opacity: 1; transform: translateY(0); }

    }



    header {

    text-align: center;

    margin-bottom: 32px;

    }



    .logo {

    font-size: 2.5rem;

    margin-bottom: 8px;

    display: inline-block;

    }



    h1 {

    font-weight: 700;

    color: var(--text-main);

    letter-spacing: -0.025em;

    font-size: 1.8rem;

    }



    .input-wrapper {

    margin-bottom: 24px;

    }



    label {

    display: block;

    font-size: 0.875rem;

    font-weight: 600;

    color: var(--text-main);

    margin-bottom: 8px;

    margin-left: 4px;

    }



    textarea {

    width: 100%;

    border-radius: 16px;

    border: 1px solid rgba(0,0,0,0.1);

    padding: 16px;

    font-size: 1rem;

    background: rgba(255, 255, 255, 0.5);

    resize: vertical;

    transition: var(--transition);

    color: var(--text-main);

    }



    textarea:focus {

    outline: none;

    border-color: var(--primary);

    background: #fff;

    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);

    }



    .controls {

    display: grid;

    grid-template-columns: 1fr 1fr;

    gap: 16px;

    margin-bottom: 24px;

    }



    input[type="text"] {

    width: 100%;

    padding: 14px 18px;

    border-radius: 12px;

    border: 1px solid rgba(0,0,0,0.1);

    background: rgba(255, 255, 255, 0.5);

    font-size: 1rem;

    transition: var(--transition);

    }



    input[type="text"]:focus {

    outline: none;

    border-color: var(--primary);

    background: #fff;

    }



    button {

    background: var(--primary);

    color: white;

    border: none;

    padding: 14px 24px;

    border-radius: 12px;

    font-weight: 600;

    font-size: 1rem;

    cursor: pointer;

    transition: var(--transition);

    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);

    }



    button:hover {

    background: var(--primary-hover);

    transform: translateY(-1px);

    box-shadow: 0 6px 15px rgba(99, 102, 241, 0.3);

    }



    button:active {

    transform: scale(0.98);

    }



    .output-container {

    position: relative;

    }



    .output-area {

    background: rgba(99, 102, 241, 0.05);

    border: 1px dashed var(--primary);

    color: var(--text-main);

    font-weight: 400;

    }



    .copy-btn {

    position: absolute;

    top: 40px;

    right: 12px;

    padding: 6px 12px;

    font-size: 0.75rem;

    background: rgba(255, 255, 255, 0.8);

    color: var(--primary);

    border: 1px solid var(--primary);

    box-shadow: none;

    }



    footer {

    margin-top: 24px;

    display: flex;

    justify-content: space-between;

    align-items: center;

    font-size: 0.8rem;

    color: var(--text-muted);

    padding-top: 16px;

    border-top: 1px solid rgba(0,0,0,0.05);

    }



    .badge {

    background: #fff;

    padding: 4px 10px;

    border-radius: 20px;

    font-weight: 600;

    color: var(--primary);

    border: 1px solid rgba(99, 102, 241, 0.2);

    }



    @media (max-width: 600px) {

    .controls { grid-template-columns: 1fr; }

    .glass-card { padding: 24px; }

    }

    </style>

    </head>

    <body>



    <div class="glass-card">

    <header>

    <div class="logo">🇰</div>

    <h1>K-Scrubber</h1>

    </header>



    <div class="input-wrapper">

    <label for="input">Source Text</label>

    <textarea id="input" rows="5" placeholder="Paste your messy text here..."></textarea>

    </div>



    <div class="controls">

    <div>

    <label for="chars">Characters to Scrub</label>

    <input type="text" id="chars" placeholder="e.g. @#$%*">

    </div>

    <div style="display: flex; align-items: flex-end;">

    <button style="width: 100%;" onclick="processText()">Cleanse Text</button>

    </div>

    </div>



    <div class="input-wrapper output-container">

    <label for="output">Cleaned Result</label>

    <button class="copy-btn" onclick="copyResult()">Copy</button>

    <textarea id="output" rows="5" class="output-area" readonly placeholder="Your clean text will appear here..."></textarea>

    </div>



    <footer>

    <span>Status: <strong id="status" style="color: #10b981;">Ready</strong></span>

    <span>Removed: <span class="badge" id="count">0</span> chars</span>

    </footer>

    </div>



    <script>

    function processText() {

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

    const charsToTarget = document.getElementById('chars').value;

    const outputEl = document.getElementById('output');

    const countEl = document.getElementById('count');



    if (!charsToTarget) {

    outputEl.value = inputVal;

    return;

    }



    // Logic Pass 1: Escape special regex characters in the 'scrub' list

    const escaped = charsToTarget.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

    const targetRegex = new RegExp(`[${escaped}]`, 'g');



    // Pass 2: Calculate how many characters are being removed

    const matches = inputVal.match(targetRegex);

    const removalCount = matches ? matches.length : 0;



    // Logic Pass 3: The Replacement Sequence

    // A. Replace target chars with a space

    // B. Replace any sequence of whitespace (\s+) with a single space

    // C. Trim ends

    const result = inputVal

    .replace(targetRegex, ' ')

    .replace(/\s+/g, ' ')

    .trim();



    // UI Updates

    outputEl.value = result;

    countEl.innerText = removalCount;



    // Visual feedback

    const btn = document.querySelector('button');

    btn.innerText = "Cleaned!";

    setTimeout(() => { btn.innerText = "Cleanse Text"; }, 1500);

    }



    async function copyResult() {

    const output = document.getElementById('output');

    const copyBtn = document.querySelector('.copy-btn');



    if (!output.value) return;



    try {

    await navigator.clipboard.writeText(output.value);

    const originalText = copyBtn.innerText;

    copyBtn.innerText = "Copied!";

    copyBtn.style.background = "#6366f1";

    copyBtn.style.color = "white";



    setTimeout(() => {

    copyBtn.innerText = originalText;

    copyBtn.style.background = "rgba(255, 255, 255, 0.8)";

    copyBtn.style.color = "var(--primary)";

    }, 2000);

    } catch (err) {

    console.error('Failed to copy: ', err);

    }

    }



    // Real-time listener for the character count while typing in input

    document.getElementById('input').addEventListener('input', () => {

    document.getElementById('status').innerText = "Working";

    document.getElementById('status').style.color = "var(--primary)";

    });

    </script>

    </body>

    </html>