<style>.brdCmb,.pTtl.aTtl.sml,.headC,.mobM.bl-hide-title.bl-hide-description.section,.fotC, .mainL {display:none}.pEnt{margin-top:0!important;margin-bottom:0!important;padding-top:0!important;padding-bottom:0!important}
  .pFoot {
    margin-bottom: 35px; /* Điều chỉnh giá trị khoảng cách theo yêu cầu */
}

</style>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Font, Alignment, and Color Selector</title>
      <!-- Noto Serif -->
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif&display=swap" rel="stylesheet">

    <!-- Quicksand -->
    <link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">

    <!-- Asap -->
    <link href="https://fonts.googleapis.com/css2?family=Asap&display=swap" rel="stylesheet">

    <!-- Farsan -->
    <link href="https://fonts.googleapis.com/css2?family=Farsan&display=swap" rel="stylesheet">

    <!-- Open Sans -->
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">

    <!-- Cabin Condensed -->
    <link href="https://fonts.googleapis.com/css2?family=Cabin+Condensed&display=swap" rel="stylesheet">

    <!-- Source Serif Pro -->
    <link href="https://fonts.googleapis.com/css2?family=Source+Serif+Pro&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Lora:wght@400;500;700&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Merriweather&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Literata&display=swap" rel="stylesheet">
      <link href="https://fonts.googleapis.com/css2?family=Playfair Display&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Cormorant&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Bai+Jamjuree&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Kanit&display=swap" rel="stylesheet">

<style>.mainN,.iAd.lgT,.iUs.lgT,.iAd.drK,.widget.LinkList.navS{background-color:var(--custom-background-color)}.content-block[data-content]::before{content:attr(data-content);white-space:pre-line;display:block;margin-bottom:12px;font-family:var(--custom-font-family);font-size:var(--custom-font-size);text-align:var(--custom-text-align)!important;color:var(--custom-text-color);line-height:var(--custom-line-height)}.l{color:var(--custom-text-color)!important}#loader{font-family:var(--custom-font-family);color:var(--custom-text-color)}.font-settings{display:none;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background-color:#fff;padding:20px;box-shadow:0 2px 10px rgb(0 0 0 / .1);z-index:1000;width:300px;max-width:90%;border-radius:30px}.font-settings label,.font-settings select,.font-settings input,.font-settings button{display:block;width:100%;margin:6px 0;color:#000}.nav-buttons-fake{display:flex;justify-content:space-between;gap:10px;margin-bottom:0}.nav-buttons-fake button{display:flex;align-items:center;justify-content:center;padding:10px 20px;font-size:16px;cursor:pointer;border:none;border-radius:25px;background-color:var(--linkB);color:#fff;flex-grow:1;width:auto;margin-bottom:20px}.font-settings button{background-color:var(--linkB);color:#fff;border:none;padding:10px;cursor:pointer;border-radius:5px}#toggleSettings{align-items:center;justify-content:center;margin:0 auto;background-color:var(--linkB);color:#fff;border:none;padding:10px 20px;cursor:pointer;border-radius:25px;margin-bottom:20px}select,input{padding:12px;font-size:16px;border:1px solid var(--contentL);background:#fff;border-radius:8px;width:100%;box-sizing:border-box;color:var(--bodyC)}</style>
</head>
<body>

    <div class="mainN">
        <div id="contentContainer"></div>
    </div>
  
<div class="nav-buttons-fake">
  <button id="toggleSettings">
<svg class='line' viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M11.0175 19C10.6601 19 10.3552 18.7347 10.297 18.373C10.2434 18.0804 10.038 17.8413 9.76171 17.75C9.53658 17.6707 9.31645 17.5772 9.10261 17.47C8.84815 17.3365 8.54289 17.3565 8.30701 17.522C8.02156 17.7325 7.62943 17.6999 7.38076 17.445L6.41356 16.453C6.15326 16.186 6.11944 15.7651 6.33361 15.458C6.49878 15.2105 6.52257 14.8914 6.39601 14.621C6.31262 14.4332 6.23906 14.2409 6.17566 14.045C6.08485 13.7363 5.8342 13.5051 5.52533 13.445C5.15287 13.384 4.8779 13.0559 4.87501 12.669V11.428C4.87303 10.9821 5.18705 10.6007 5.61601 10.528C5.94143 10.4645 6.21316 10.2359 6.33751 9.921C6.37456 9.83233 6.41356 9.74433 6.45451 9.657C6.61989 9.33044 6.59705 8.93711 6.39503 8.633C6.1424 8.27288 6.18119 7.77809 6.48668 7.464L7.19746 6.735C7.54802 6.37532 8.1009 6.32877 8.50396 6.625L8.52638 6.641C8.82735 6.84876 9.21033 6.88639 9.54428 6.741C9.90155 6.60911 10.1649 6.29424 10.2375 5.912L10.2473 5.878C10.3275 5.37197 10.7536 5.00021 11.2535 5H12.1115C12.6248 4.99976 13.0629 5.38057 13.1469 5.9L13.1625 5.97C13.2314 6.33617 13.4811 6.63922 13.8216 6.77C14.1498 6.91447 14.5272 6.87674 14.822 6.67L14.8707 6.634C15.2842 6.32834 15.8528 6.37535 16.2133 6.745L16.8675 7.417C17.1954 7.75516 17.2366 8.28693 16.965 8.674C16.7522 8.99752 16.7251 9.41325 16.8938 9.763L16.9358 9.863C17.0724 10.2045 17.3681 10.452 17.7216 10.521C18.1837 10.5983 18.5235 11.0069 18.525 11.487V12.6C18.5249 13.0234 18.2263 13.3846 17.8191 13.454C17.4842 13.5199 17.2114 13.7686 17.1083 14.102C17.0628 14.2353 17.0121 14.3687 16.9562 14.502C16.8261 14.795 16.855 15.1364 17.0323 15.402C17.2662 15.7358 17.2299 16.1943 16.9465 16.485L16.0388 17.417C15.7792 17.6832 15.3698 17.7175 15.0716 17.498C14.8226 17.3235 14.5001 17.3043 14.2331 17.448C14.0428 17.5447 13.8475 17.6305 13.6481 17.705C13.3692 17.8037 13.1636 18.0485 13.1099 18.346C13.053 18.7203 12.7401 18.9972 12.3708 19H11.0175Z" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M13.9747 12C13.9747 13.2885 12.9563 14.333 11.7 14.333C10.4437 14.333 9.42533 13.2885 9.42533 12C9.42533 10.7115 10.4437 9.66699 11.7 9.66699C12.9563 9.66699 13.9747 10.7115 13.9747 12Z" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>
  </button>
<button id="linkButton" onclick="redirectToPage()">
  <svg class='line' viewBox="0 -0.5 25 25" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M18.867 15.8321L18.873 10.0391L14.75 5.92908C13.5057 4.69031 11.4942 4.69031 10.25 5.92908L6.13599 10.0291V15.8291C6.1393 17.5833 7.56377 19.0028 9.31799 19.0001H15.685C17.438 19.0029 18.862 17.5851 18.867 15.8321Z" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M14 11.365C13.9846 12.1896 13.3064 12.8471 12.4817 12.8369C11.657 12.8267 10.9952 12.1526 11.0003 11.3279C11.0053 10.5031 11.6752 9.83718 12.5 9.83704C12.9015 9.84073 13.2852 10.0038 13.5665 10.2904C13.8478 10.5769 14.0037 10.9635 14 11.365V11.365Z" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M19.63 5.76314C19.6306 5.34892 19.2953 5.01267 18.8811 5.01209C18.4668 5.0115 18.1306 5.34682 18.13 5.76103L19.63 5.76314ZM18.874 10.0391L18.124 10.038C18.1237 10.2377 18.2031 10.4293 18.3445 10.5702L18.874 10.0391ZM19.9705 12.1912C20.2638 12.4837 20.7387 12.4829 21.0311 12.1896C21.3236 11.8963 21.3229 11.4214 21.0295 11.1289L19.9705 12.1912ZM6.66552 10.5602C6.95886 10.2678 6.95959 9.79291 6.66714 9.49957C6.3747 9.20623 5.89982 9.2055 5.60648 9.49794L6.66552 10.5602ZM3.97048 11.1289C3.67714 11.4214 3.67641 11.8963 3.96886 12.1896C4.2613 12.4829 4.73618 12.4837 5.02952 12.1912L3.97048 11.1289ZM10.5 15.1971C10.0858 15.1971 9.75 15.5329 9.75 15.9471C9.75 16.3613 10.0858 16.6971 10.5 16.6971V15.1971ZM14.5 16.6971C14.9142 16.6971 15.25 16.3613 15.25 15.9471C15.25 15.5329 14.9142 15.1971 14.5 15.1971V16.6971ZM18.13 5.76103L18.124 10.038L19.624 10.0401L19.63 5.76314L18.13 5.76103ZM18.3445 10.5702L19.9705 12.1912L21.0295 11.1289L19.4035 9.50794L18.3445 10.5702ZM5.60648 9.49794L3.97048 11.1289L5.02952 12.1912L6.66552 10.5602L5.60648 9.49794ZM10.5 16.6971H14.5V15.1971H10.5V16.6971Z" fill="#fff"></path> </g></svg>
  </button>
  <button id="copyUrlButton" onclick="copyCurrentUrl()">
<svg class='line' viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M9.61109 12.4L10.8183 18.5355C11.0462 19.6939 12.6026 19.9244 13.1565 18.8818L19.0211 7.84263C19.248 7.41555 19.2006 6.94354 18.9737 6.58417M9.61109 12.4L5.22642 8.15534C4.41653 7.37131 4.97155 6 6.09877 6H17.9135C18.3758 6 18.7568 6.24061 18.9737 6.58417M9.61109 12.4L18.9737 6.58417M19.0555 6.53333L18.9737 6.58417" stroke="#fff" stroke-width="2"></path> </g></svg>
  </button>
</div>


<div id="fontSettings" class="font-settings">
      <div style="text-align: center; margin-bottom: 10px; font-size: 20px; color: black;"><b>TÙY CHỈNH</b></div>
    <label for="fontFamily">Phông chữ</label>
<select id="fontFamily">
    <option value="Lora">Lora</option>
    <option value="Merriweather">Merriweather</option>
    <option value="Playfair Display">Playfair Display</option>
    <option value="Literata">Literata</option>
    <option value="Noto Serif">Noto Serif</option>
    <option value="Quicksand">Quicksand</option>
    <option value="Asap">Asap</option>
    <option value="Farsan">Farsan</option>
    <option value="Open Sans">Open Sans</option>
    <option value="Cabin Condensed">Cabin Condensed</option>
    <option value="Source Serif Pro">Source Serif Pro</option>
    <!-- Thêm các phông chữ hỗ trợ tiếng Việt khác -->
    <option value="Cormorant">Cormorant</option>
    <option value="Bai Jamjuree">Bai Jamjuree</option>
    <option value="Kanit">Kanit</option>
</select>


<label for="fontSize">Cỡ chữ</label>
<select id="fontSize">
      <option value="14">14</option>
    <option value="16">16</option>
    <option value="18">18</option>
    <option value="20">20</option>
    <option value="22">22</option>
    <option value="24">24</option>
    <option value="26">26</option>
    <option value="28">28</option>
    <option value="30">30</option>
</select>

      
      <label for="lineHeight">Giãn dòng</label>
<select id="lineHeight">
    <option value="1">1</option>
    <option value="1.15">1.15</option>
    <option value="1.5">1.5</option>
    <option value="1.75">1.75</option>
    <option value="2">2</option>
</select>

        <label for="textAlign">Căn lề</label>
        <select id="textAlign">
            <option value="left">Lề trái</option>
            <option value="center">Căn giữa</option>
            <option value="right">Lề phải</option>
            <option value="justify">Đều hai bên</option>
        </select>

        <label for="colorScheme">Màu nền</label>
        <select id="colorScheme">
            <option value="#5B3A29,#F5DEB3">Vàng da</option>
            <option value="#5B3A29,#DAA520">Vàng đậm</option>
            <option value="#000000,#FFF5F7">Hồng nhạt</option>
            <option value="#000000,#F0FFFF">Xanh nhạt</option>
            <option value="#000000,#D3D3D3">Xám nhạt</option>
<option value="#F0F0F0,#1E1E1E">Đen trắng</option>
          <option value="#000000,#FFFFFF">Trắng đen</option>
        </select>

<div class="nav-buttons-fake">
      <button id="closeSettings">Đóng</button>
    <button id="resetSettings">Gốc</button>
      <button id="applySettings">Lưu</button>
</div>

    </div>

<script>document.addEventListener("DOMContentLoaded",function(){const fontFamilySelector=document.getElementById('fontFamily');const fontSizeInput=document.getElementById('fontSize');const textAlignSelector=document.getElementById('textAlign');const colorSchemeSelector=document.getElementById('colorScheme');const lineHeightSelector=document.getElementById('lineHeight');const applyButton=document.getElementById('applySettings');const savedFont=localStorage.getItem('custom-font-family')||'Merriweather';const savedFontSize=localStorage.getItem('custom-font-size')||'16px';const savedTextAlign=localStorage.getItem('custom-text-align')||'justify';const savedColorScheme=localStorage.getItem('custom-color-scheme')||'#000,#fff';const savedLineHeight=localStorage.getItem('custom-line-height')||'1.5';const[savedTextColor,savedBackgroundColor]=savedColorScheme.split(',');document.documentElement.style.setProperty('--custom-font-family',savedFont);document.documentElement.style.setProperty('--custom-font-size',savedFontSize);document.documentElement.style.setProperty('--custom-text-align',savedTextAlign);document.documentElement.style.setProperty('--custom-text-color',savedTextColor);document.documentElement.style.setProperty('--custom-background-color',savedBackgroundColor);document.documentElement.style.setProperty('--custom-line-height',savedLineHeight);fontFamilySelector.value=savedFont.replace(/['"]/g,'');fontSizeInput.value=parseInt(savedFontSize,10);textAlignSelector.value=savedTextAlign;colorSchemeSelector.value=savedColorScheme;lineHeightSelector.value=savedLineHeight;function applyFontSettings(font,size,align,colorScheme,lineHeight){const[textColor,backgroundColor]=colorScheme.split(',');document.documentElement.style.setProperty('--custom-font-family',`'${font}'`);document.documentElement.style.setProperty('--custom-font-size',`${size}px`);document.documentElement.style.setProperty('--custom-text-align',align);document.documentElement.style.setProperty('--custom-text-color',textColor);document.documentElement.style.setProperty('--custom-background-color',backgroundColor);document.documentElement.style.setProperty('--custom-line-height',lineHeight);localStorage.setItem('custom-font-family',font);localStorage.setItem('custom-font-size',`${size}px`);localStorage.setItem('custom-text-align',align);localStorage.setItem('custom-color-scheme',colorScheme);localStorage.setItem('custom-line-height',lineHeight)}
applyButton.addEventListener('click',function(){const selectedFont=fontFamilySelector.value;const fontSize=fontSizeInput.value;const textAlign=textAlignSelector.value;const colorScheme=colorSchemeSelector.value;const lineHeight=lineHeightSelector.value;applyFontSettings(selectedFont,fontSize,textAlign,colorScheme,lineHeight)})});const resetButton=document.getElementById('resetSettings');resetButton.addEventListener('click',function(){localStorage.clear();location.reload()});const toggleSettingsButton=document.getElementById('toggleSettings');const fontSettings=document.getElementById('fontSettings');toggleSettingsButton.addEventListener('click',(e)=>{fontSettings.style.display=fontSettings.style.display==='none'||fontSettings.style.display===''?'block':'none';e.stopPropagation()});document.addEventListener('click',(e)=>{if(!fontSettings.contains(e.target)&&e.target!==toggleSettingsButton){fontSettings.style.display='none'}});function copyCurrentUrl(){let currentUrl=window.location.href;currentUrl=currentUrl.replace(/([&?])m=[01]/,'');if(currentUrl.includes('?')&&currentUrl.endsWith('?')){currentUrl=currentUrl.slice(0,-1)}
navigator.clipboard.writeText(currentUrl).then(()=>alert('Đường dẫn chương đã được lưu vào bộ nhớ tạm.')).catch(err=>console.error('Lỗi sao chép URL: ',err))}
document.getElementById('closeSettings').addEventListener('click',()=>{document.getElementById('fontSettings').style.display='none'});function redirectToPage() {
    window.location.href = 'https://www.kunsnovel.pro.vn/p/oneshot.html';
}
</script>

</body>
</html>



<!DOCTYPE html>
<html lang="vi">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        /* Add the loading message style */
        #loading-message {
            text-align: center;
            font-family: var(--custom-font-family) !important;
            color: var(--custom-text-color) !important;
            display: none;
          	margin-top: 30px;
          	margin-bottom: 40px;
        }

        .info-container {
            margin-bottom: 20px;
            text-align: center;
            font-family: var(--custom-font-family) !important;
            font-size: var(--custom-font-size);
            color: var(--custom-text-color);
            line-height: var(--custom-line-height); /* Ensuring line height is adjusted */
        }
        .cover {
            max-width: 150px; /* Giảm kích thước tối đa */
            margin: 0 auto 10px; /* Giữ căn giữa và khoảng cách bên dưới */
            margin-top: 20px; /* Giữ căn giữa và khoảng cách bên dưới */
        }
        .cover img {
            width: 100%; /* Chiều rộng theo phần tử cha */
            height: auto; /* Tự động điều chỉnh chiều cao */
            object-fit: cover; /* Giữ nội dung trong khung mà không méo */
            border-radius: 8px; /* Bo góc */
            aspect-ratio: 2 / 3; /* Giữ tỷ lệ 2:3 */
        }
        .details {
            text-align: center;
            font-family: var(--custom-font-family) !important;
            font-size: var(--custom-font-size);
            color: var(--custom-text-color);
            line-height: var(--custom-line-height); /* Ensuring line height is adjusted */
        }
        .details h2, .s1 {
            margin-top: 2px;
            margin-bottom: 0;
            font-family: var(--custom-font-family) !important;
            font-size: var(--custom-font-size) !important;
            color: var(--custom-text-color) !important;
            line-height: var(--custom-line-height); /* Ensuring line height is adjusted */
        }
        .details p {
            margin: 10px 0;
        }
        .content-block[data-content]::before {
            content: attr(data-content);
            display: block;
            margin-bottom: 12px;
            margin-top: 12px;
        }
        .genre-label {
            display: inline-block;
            padding: 2px 6px;
            margin: 5px;
            font-family: var(--custom-font-family);
            background: var(--custom-text-color);
            color: var(--custom-background-color);
            line-height: var(--custom-line-height); /* Ensuring line height is adjusted */
        }
        .alert.info {
            text-align: justify;
        }
        .related-posts {
            display: block; /* Hiển thị dưới dạng block để mỗi thẻ a đứng trên một dòng */
            margin-top: 10px;
        }
        .post-title {
            display: block; /* Đảm bảo mỗi link chiếm một dòng */
            margin-bottom: 5px; /* Thêm khoảng cách giữa các link */
            text-decoration: none; /* Bỏ gạch chân */
            color: #007bff; /* Màu sắc cho liên kết */
        }
        .post-title:hover {
            text-decoration: underline; /* Hiệu ứng hover */
        }
      	.pRelate, a.post-title, .alert.outline {
            font-family: var(--custom-font-family) !important;
            font-size: var(--custom-font-size) !important;
            color: var(--custom-text-color) !important;
            line-height: var(--custom-line-height) !important;
        }
      	b {             font-family: var(--custom-font-family) !important;
            font-size: var(--custom-font-size) !important;
          line-height: var(--custom-line-height) !important; }
      .pRelate {
    font-style: italic;
}

    </style>
</head>
<body>
    <!-- Thông báo Loading -->
    <div id="loading-message">Loading...</div>

    <div class="info-container" id="info-container" style="display: none;">
        <div class="cover" id="cover"></div>
        <div class="details" id="details"></div>
    </div>
  
  <div class='alert outline' style="display: none;"></div>

    <div class="introduction-container" id="introduction" style="display: none;">
        <blockquote class="s1">
            <p id="intro-text" style="text-align: justify;"></p>
            <span id="author-name"></span>
        </blockquote>
    </div>
  
    <div id="chapterContent">
        <h3 id="contentTitle"></h3>
        <div id="contentText"></div>
    </div>
  
	      <div class='pRelate' style="display: none;">
        Thử đọc tác phẩm khác nè:
        <div class="related-posts">
            <!-- Các liên kết gợi ý sẽ được thêm vào đây từ API -->
        </div>
    </div>

<script>
document.addEventListener('DOMContentLoaded', function () {
    const isValidHash = (hash) => /^#[^#]*-.*$/.test(hash);

    function getValidHash() {
        const hash = window.location.hash;
        if (isValidHash(hash)) {
            localStorage.setItem('lastTabName', hash); // Lưu hash hợp lệ vào localStorage
            return hash;
        } else {
            return localStorage.getItem('lastTabName') || ''; // Lấy từ localStorage nếu hash không hợp lệ
        }
    }

    function fetchData(url) {
        document.getElementById('loading-message').style.display = 'block';
        document.getElementById("info-container").style.display = 'none';
        document.getElementById("introduction").style.display = 'none';
        document.getElementById("chapterContent").style.display = 'none';
        document.querySelector('.alert.outline').style.display = 'none';
        document.querySelector('.pRelate').style.display = 'none';

        fetch(url)
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                return response.json();
            })
            .then(data => {
                if (data.error) {
                    document.getElementById("details").innerHTML = `<p>${data.error}</p>`;
                    return;
                }

                updateUI(data); // Hiển thị dữ liệu
            })
            .catch(error => {
                console.error("Error fetching data:", error);
                document.getElementById("details").innerHTML = "<p>Đã xảy ra lỗi khi tải dữ liệu. Vui lòng thử lại sau.</p>";
            });
    }

 function updateUI(data) {
    const story = data;
    const formattedIntroduction = `<span style="font-family: var(--custom-font-family) !important;">${(story['Giới thiệu'] || "").replace(/\n\n/g, '<br>')}</span>`;
    const genres = story['Thể loại'] ? story['Thể loại'].split(',') : ['Không rõ'];
    const rawTime = story['Thời gian'] || '';
    let formattedTime = 'Không xác định';
    if (rawTime) {
        const date = new Date(rawTime);
        if (!isNaN(date)) {
            formattedTime = date.toLocaleString('vi-VN', {
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit',
                day: '2-digit',
                month: '2-digit',
                year: 'numeric'
            });
        }
    }

    document.getElementById("cover").innerHTML = `<img src="${story['Url bìa'] || ''}" alt="${story['Tác phẩm'] || 'Không có tiêu đề'}">`;
    document.getElementById("details").innerHTML = `
        <h2 style="font-family: var(--custom-font-family) !important;">${story['Tác phẩm'] || 'Không có tiêu đề'}</h2>
        <p style="font-family: var(--custom-font-family) !important;">
            <strong>Tác giả:</strong> ${story['Tác giả'] || 'Không rõ'} |
            <strong>Lượt xem: </strong>${story['Lượt xem'] || '0'} |
            <strong>Thời gian:</strong> ${formattedTime}
        </p>
        <p style="font-family: var(--custom-font-family) !important;">
            ${genres.map(genre => `<span class="genre-label">${genre.trim()}</span>`).join(' ')}
        </p>
    `;
    document.getElementById("intro-text").innerHTML = formattedIntroduction || "Không có giới thiệu.";
    document.getElementById("author-name").innerHTML = story['Tác giả'] || '';

    const message = story['Lời nhắn'] || 'Không có';
    const alertElement = document.querySelector(".alert.outline");

    if (message === 'Không có') {
        alertElement.style.display = 'none';
    } else {
        alertElement.innerHTML = `<b>★ Lời nhắn:</b> ${message}`;
        alertElement.style.textAlign = "justify";
        alertElement.style.display = 'block';
    }

    displayContent({ content: story['Nội dung'] || '' });

    if (story['Gợi ý'] && Array.isArray(story['Gợi ý'])) {
        const relatedPostsContainer = document.querySelector('.related-posts');
        relatedPostsContainer.innerHTML = '';
        story['Gợi ý'].forEach(post => {
            const postLink = document.createElement('a');
            postLink.href = "javascript:void(0);";
            postLink.classList.add('post-title');
            postLink.setAttribute('data-tab', post);
            postLink.innerHTML = post;

            postLink.addEventListener('click', function () {
                const newTabName = post;

                // Loại bỏ phần query string (?...) trong URL
                const cleanURL = window.location.origin + window.location.pathname;

                // Thay đổi URL với hash mới
                window.location.replace(`${cleanURL}${newTabName}`);
            });

            relatedPostsContainer.appendChild(postLink);
        });
    }

    document.getElementById('loading-message').style.display = 'none';
    document.getElementById("info-container").style.display = 'block';
    document.getElementById("introduction").style.display = 'block';
    document.getElementById("chapterContent").style.display = 'block';
    document.querySelector('.pRelate').style.display = '';
}


    function displayContent(content) {
        document.getElementById('contentText').innerHTML = '';
        const paragraphs = content.content.split('\n').filter(p => p.trim().length > 0);
        paragraphs.forEach(paragraph => {
            const formattedParagraph = paragraph.trim();
            const contentElement = document.createElement('div');
            contentElement.classList.add('content-block');
            contentElement.setAttribute('data-content', formattedParagraph);
            document.getElementById('contentText').appendChild(contentElement);
        });
    }

    function handleHashChange() {
        const validHash = getValidHash();
        if (validHash) {
            const apiUrl = `https://script.google.com/macros/s/AKfycbxhFe6QjOSovP3SyCQQnEy0PP1jicOBY_p4nqJqfDr0Tc1af-lyji9cHcCWbRYbHol9/exec?title=${encodeURIComponent(validHash)}`;
            fetchData(apiUrl);
        }
    }

    // Lần đầu tiên tải trang
    handleHashChange();

    // Theo dõi thay đổi của hash
    window.addEventListener('hashchange', handleHashChange);
});

</script>

</body>
</html>