Chaat GPT 100% working code. with some minimul errors


<!DOCTYPE html>
<html lang="hi">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="referrer" content="strict-origin-when-cross-origin">
    <title>Baithkee | Local News</title>
    
    <script src="https://accounts.google.com/gsi/client" async defer></script>

    <style>
        :root {
            --primary: #FF3B30;
            --dark: #1C1C1E;
            --gray: #8E8E93;
            --light: #F2F2F7;
            --white: #FFFFFF;
            --shadow: 0 4px 12px rgba(0,0,0,0.08);
        }

        body {
            margin: 0;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            background-color: var(--light);
            color: var(--dark);
            -webkit-tap-highlight-color: transparent;
        }

        /* Header Design */
        header {
            background: var(--dark);
            color: var(--white);
            padding: 15px 20px;
            position: sticky;
            top: 0;
            z-index: 1000;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }

        .logo { font-size: 22px; font-weight: 800; letter-spacing: -1px; }

        /* News Strips Design */
        #newsContainer { padding: 10px 0 100px 0; }

        .newsStrip {
            background: var(--white);
            margin: 8px 12px;
            padding: 16px;
            border-radius: 12px;
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            box-shadow: var(--shadow);
            transition: transform 0.2s;
        }

        .newsStrip:active { transform: scale(0.98); }

        .headlineText {
            font-size: 16px;
            font-weight: 600;
            line-height: 1.4;
            color: #2c3e50;
            padding-right: 10px;
        }

        .timeTag {
            font-size: 11px;
            color: var(--gray);
            white-space: nowrap;
            background: #f0f0f0;
            padding: 4px 8px;
            border-radius: 20px;
        }

        /* Floating Action Buttons */
        .fab {
            position: fixed;
            right: 20px;
            width: 60px;
            height: 60px;
            border-radius: 30px;
            border: none;
            color: white;
            font-size: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 6px 20px rgba(231, 76, 60, 0.3);
            z-index: 999;
            cursor: pointer;
        }

        #publishBtn { bottom: 30px; background: var(--primary); font-weight: bold; }
        #rangeBtn { bottom: 105px; background: #007AFF; font-size: 20px; }

        /* Modern Popups */
        .overlay {
            display: none;
            position: fixed;
            top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.6);
            backdrop-filter: blur(5px);
            z-index: 2000;
            align-items: flex-end;
        }

        .popup {
            background: var(--white);
            width: 100%;
            border-radius: 25px 25px 0 0;
            padding: 25px;
            box-sizing: border-box;
            max-height: 90vh;
            overflow-y: auto;
            animation: slideUp 0.3s ease-out;
        }

        @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

        .author-card {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .author-card img { width: 45px; height: 45px; border-radius: 50%; border: 2px solid var(--primary); }

        .news-content {
            font-size: 17px;
            line-height: 1.6;
            color: #333;
            margin-bottom: 25px;
            white-space: pre-wrap;
        }

        .stats-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: var(--light);
            padding: 12px;
            border-radius: 10px;
        }

        .view-count { font-weight: 700; color: #007AFF; font-size: 14px; }
        .report-link { color: var(--primary); font-size: 14px; font-weight: 600; text-decoration: none; }

        /* Form Design */
        .input-group { margin-bottom: 15px; }
        .input-group input, .input-group textarea {
            width: 100%; padding: 15px; border: 1.5px solid #E5E5EA;
            border-radius: 12px; font-size: 16px; box-sizing: border-box;
        }
        .input-group input:focus { border-color: var(--primary); outline: none; }
        .submit-news {
            background: var(--primary); color: white; border: none;
            width: 100%; padding: 18px; border-radius: 12px; font-size: 18px; font-weight: bold;
        }

    </style>
</head>
<body>

<header>
    <div class="logo">Baithkee</div>
    <div id="g_id_onload" 
         data-client_id="1046845791568-jc7e5qn4rqhkgqlupdi1ga7j74otrnth.apps.googleusercontent.com" 
         data-callback="handleCredentialResponse"
         data-auto_prompt="false"></div>
    <div class="g_id_signin" data-type="icon" data-shape="circle"></div>
</header>

<div id="newsContainer">
    </div>

<button id="rangeBtn" class="fab" onclick="changeRange()">📍</button>
<button id="publishBtn" class="fab" onclick="checkAuth()">+</button>

<div id="detailOverlay" class="overlay" onclick="closePopup(event, 'detailOverlay')">
    <div class="popup" onclick="event.stopPropagation()">
        <div class="author-card">
            <img id="pImg" src="">
            <div style="flex:1">
                <div id="pName" style="font-weight:700; font-size:16px;"></div>
                <div id="pTime" style="font-size:12px; color:var(--gray);"></div>
            </div>
            <div onclick="document.getElementById('detailOverlay').style.display='none'" style="font-size:24px; cursor:pointer;">✕</div>
        </div>
        <h2 id="pHeadline" style="margin-top:0; font-size:22px;"></h2>
        <div id="pContent" class="news-content"></div>
        <div class="stats-bar">
            <span id="pViews" class="view-count"></span>
            <span class="report-link" onclick="reportNews()">Report News</span>
        </div>
    </div>
</div>

<div id="publishOverlay" class="overlay" onclick="closePopup(event, 'publishOverlay')">
    <div class="popup" onclick="event.stopPropagation()">
        <h2 style="margin-top:0">Post News</h2>
        <div class="input-group">
            <input type="text" id="headInput" placeholder="Headline (Short & Clear)">
        </div>
        <div class="input-group">
            <textarea id="bodyInput" rows="6" placeholder="Write full news details..."></textarea>
        </div>
        <button class="submit-news" onclick="publishNews()">Publish Now</button>
        <p style="text-align:center; color:var(--gray); margin-top:15px;" onclick="document.getElementById('publishOverlay').style.display='none'">Cancel</p>
    </div>
</div>

<script>
    const API_URL = "https://script.google.com/macros/s/AKfycbzmlMtYRacBFBmZEps7JNtm-5954bPt88jtL0SQzAz-joDwlr6VfiidKxhfq67ZMFpz/exec"; 
    let userLoc = { lat: 0, lon: 0 };
    let userData = null;
    let selectedRange = 5;
    let currentNewsId = null;

    // Initialization
    window.onload = () => {
        navigator.geolocation.getCurrentPosition(pos => {
            userLoc = { lat: pos.coords.latitude, lon: pos.coords.longitude };
            fetchNews();
        }, () => {
            alert("Please enable Location to see local news.");
            fetchNews();
        });
    };

    // Fetch News from Backend
    async function fetchNews() {
        try {
            const res = await fetch(`${API_URL}?action=getNews&lat=${userLoc.lat}&lon=${userLoc.lon}&range=${selectedRange}`);
            const data = await res.json();
            const container = document.getElementById("newsContainer");
            container.innerHTML = "";

            data.forEach(item => {
                const strip = document.createElement("div");
                strip.className = "newsStrip";
                strip.innerHTML = `
                    <span class="headlineText">${item.headline}</span>
                    <span class="timeTag">${formatTime(item.time)}</span>
                `;
                strip.onclick = () => openDetail(item);
                container.appendChild(strip);
            });
        } catch (e) { console.log("Fetch Error", e); }
    }

    function formatTime(ts) {
        let diff = Math.floor((new Date().getTime() - ts) / 1000);
        if(diff < 60) return diff + "s ago";
        if(diff < 3600) return Math.floor(diff/60) + "m ago";
        return Math.floor(diff/3600) + "h ago";
    }

    function formatViews(v) {
        if (v >= 10000000) return (v/10000000).toFixed(1) + 'Cr';
        if (v >= 100000) return (v/100000).toFixed(1) + 'L';
        if (v >= 1000) return (v/1000).toFixed(1) + 'K';
        return v;
    }

    // Popup Logic
    function openDetail(item) {
        currentNewsId = item.id;
        document.getElementById("pImg").src = item.photo || "https://via.placeholder.com/45";
        document.getElementById("pName").innerText = item.username;
        document.getElementById("pTime").innerText = formatTime(item.time);
        document.getElementById("pHeadline").innerText = item.headline;
        document.getElementById("pContent").innerText = item.text;
        document.getElementById("pViews").innerText = formatViews(item.views) + " Views";
        document.getElementById("detailOverlay").style.display = "flex";
        
        // Add View to Backend
        fetch(`${API_URL}?action=addView&id=${item.id}`);
    }

    function closePopup(e, id) { if(e.target.id === id) document.getElementById(id).style.display = 'none'; }

    // Auth & Actions
    function handleCredentialResponse(response) {
        const payload = JSON.parse(atob(response.credential.split('.')[1]));
        userData = { name: payload.name, email: payload.email, photo: payload.picture };
        console.log("Logged In:", userData.name);
    }

    function checkAuth() {
        if(!userData) {
            alert("Login required to post news.");
            document.querySelector(".g_id_signin").click();
        } else {
            document.getElementById("publishOverlay").style.display = "flex";
        }
    }

    async function publishNews() {
        const head = document.getElementById("headInput").value;
        const body = document.getElementById("bodyInput").value;
        if(!head || !body) return alert("Please fill all fields");

        const postData = {
            action: "postNews",
            headline: head,
            text: body,
            username: userData.name,
            photo: userData.photo,
            email: userData.email,
            latitude: userLoc.lat,
            longitude: userLoc.lon
        };

        const res = await fetch(API_URL, { method: "POST", body: JSON.stringify(postData) });
        if(res.ok) {
            document.getElementById("publishOverlay").style.display = 'none';
            fetchNews();
        }
    }

    async function reportNews() {
        if(!userData) return alert("Login to report news");
        await fetch(`${API_URL}?action=report&id=${currentNewsId}&email=${userData.email}`);
        alert("News Reported. It will be removed if 5 reports received.");
        document.getElementById("detailOverlay").style.display = 'none';
        fetchNews();
    }

    function changeRange() {
        let r = prompt("Change range (in KM):", selectedRange);
        if(r) { selectedRange = r; fetchNews(); }
    }
</script>
</body>
</html>

इस ब्लॉग से लोकप्रिय पोस्ट

The History of the World – A Simple and Long Article for English Learners

High Level Advance Random English Words

1. The Art of Self-Discipline