<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}
</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(){navigator.clipboard.writeText(window.location.href).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(){const sourceUrl=sessionStorage.getItem('sourceUrl')||'https://www.kunsnovel.pro.vn/';window.location.href=sourceUrl;sessionStorage.removeItem('sourceUrl')}
function redirectToPage(){window.history.back()}</script>

</body>
</html>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chapter Viewer</title>
<style>#contentTitle{font-weight:700;margin-bottom:12px;font-family:var(--custom-font-family)!important;font-size:var(--custom-font-size);text-align:var(--custom-text-align);color:var(--custom-text-color);line-height:var(--custom-line-height)}#loader{text-align:center}#chapterContent{display:none;white-space:pre-wrap}.content-block{display:none}.content-block[data-content]::before{content:attr(data-content);display:block;margin-bottom:12px}.nav-buttons{display:flex;justify-content:space-between;gap:10px;margin-top:20px;margin-bottom:35px}.nav-buttons 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}.password-input{text-align:center;margin-top:20px}.password-input label{font-weight:700}.password-input input{padding:12px;font-size:16px;border:1px solid var(--contentL);background:var(--contentB);border-radius:8px;width:80%;box-sizing:border-box;transition:border-color 0.3s,background-color 0.3s;color:var(--bodyC)}.password-input button{padding:8px 16px;margin-top:10px;background-color:var(--linkB);color:#fff;border:none;border-radius:5px}#error-message{color:var(--custom-text-color);margin-top:10px;display:none}</style>
</head>
<body>
<div id="loader">
    <p id="loader-text"></p>
</div>
    <div id="contentTitle"></div>
    <div id="chapterContent"></div>
  
  
    <div class="password-input" id="passwordDiv" style="display: none;">
        <input type="text" id="password" placeholder="Nhập mật khẩu..."/>
        <button id="unlockBtn">Xác nhận</button>
        <div id="error-message"></div>
    </div>

<div class="nav-buttons" style="display: none;">
    <button id="prevBtn">Trước</button>
    <button id="nextBtn">Tiếp</button>
</div>



<script>const apiBase='https://script.google.com/macros/s/AKfycbzaRD1EDPEcBctBHRJUSF3a3Sh3skJJOBwjE7oFU-FtZHsTk1bWcrCauJkXdnBDNyY0/exec';const urlParams=new URLSearchParams(window.location.search);const id=urlParams.get('id');let currentChapter=urlParams.get('chap');let currentPass=urlParams.get('pass');let chapters=[];if(!id){alert('Đường dẫn không chính xác, vui lòng quay về trang chủ.')}else{const storedChapters=sessionStorage.getItem(`chapters_${id}`);document.getElementById('loader').style.display='block';if(storedChapters){chapters=JSON.parse(storedChapters);initializeNavigation();fetchChapterContent(id,currentChapter,currentPass).finally(()=>{document.getElementById('loader').style.display='none'})}else{const chapterListUrl=`${apiBase}?id=${id}`;const chapterContentUrl=`${apiBase}?action=getChapterContent&id=${encodeURIComponent(id)}&chap=${encodeURIComponent(currentChapter)}&pass=${encodeURIComponent(currentPass)}`;Promise.all([fetch(chapterListUrl).then(response=>response.json()),fetch(chapterContentUrl).then(response=>response.text())]).then(([chapterList,encodedContent])=>{chapters=chapterList;sessionStorage.setItem(`chapters_${id}`,JSON.stringify(chapters));initializeNavigation();if(!encodedContent){showPasswordFieldWithError("An error occurred. Please try again.");return}
const decodedContent=decode(encodedContent);let parsedContent;try{parsedContent=JSON.parse(decodedContent)}catch(e){showPasswordFieldWithError("Failed to load chapter content. Please try again.");return}
const chapterData=parsedContent[0];if(!chapterData){showPasswordFieldWithError("No data available for this chapter.");return}
if(chapterData.status==='Locked'){if(chapterData.error){showPasswordFieldWithError("Incorrect password. Please try again.")}else{displayChapterContent({title:chapterData.chapter,content:chapterData.data})}}else{displayChapterContent({title:chapterData.chapter,content:chapterData.data})}}).catch(()=>{showPasswordFieldWithError("Failed to fetch data. Please try again.")}).finally(()=>{document.getElementById('loader').style.display='none'})}}
function decodeBase64(str){return atob(str)}
function decodeUnicode(str){return str.replace(/\\u[\dA-F]{4}/gi,match=>String.fromCharCode(parseInt(match.replace(/\\u/g,''),16)))}
function reverseString(str){return str.split('').reverse().join('')}
function shiftCharactersBack(str){return[...str].map(char=>String.fromCharCode(char.charCodeAt(0)-3)).join('')}
function decode(input){const base64Decoded=decodeBase64(input);const unicodeDecoded=decodeUnicode(base64Decoded);const reversed=reverseString(unicodeDecoded);const finalDecoded=shiftCharactersBack(reversed);return finalDecoded}
function fetchChapterContent(id,chap,pass){try{document.getElementById('loader').style.display='block';document.getElementById('chapterContent').style.display='none';document.querySelector('.nav-buttons').style.display='none';document.getElementById('contentTitle').style.display='none';document.getElementById('passwordDiv').style.display='none';document.getElementById('error-message').style.display='none';const url=`${apiBase}?action=getChapterContent&id=${encodeURIComponent(id)}&chap=${encodeURIComponent(chap)}&pass=${encodeURIComponent(pass)}`;urlParams.delete('pass');const newUrl=window.location.origin+window.location.pathname+'?'+urlParams.toString();history.replaceState(null,'',newUrl);fetch(url).then(response=>response.text()).then(encodedContent=>{if(!encodedContent){showPasswordFieldWithError("An error occurred. Please try again.");return}
const decodedContent=decode(encodedContent);let parsedContent;try{parsedContent=JSON.parse(decodedContent)}catch(e){showPasswordFieldWithError("Failed to load chapter content. Please try again.");return}
const chapterData=parsedContent[0];if(!chapterData){showPasswordFieldWithError("No data available for this chapter.");return}
if(chapterData.status==='Locked'){if(chapterData.error){showPasswordFieldWithError("Incorrect password. Please try again.")}else{displayChapterContent({title:chapterData.chapter,content:chapterData.data});document.getElementById('error-message').style.display='none'}}else{displayChapterContent({title:chapterData.chapter,content:chapterData.data})}}).catch(()=>{showPasswordFieldWithError("Mật khẩu không được nhập đúng, vui lòng cung cấp chính xác!")}).finally(()=>{document.getElementById('loader').style.display='none'})}catch(error){document.getElementById('loader').style.display='none'}}
function showPasswordFieldWithError(errorMessage){document.getElementById('passwordDiv').style.display='block';document.getElementById('chapterContent').style.display='none';document.querySelector('.nav-buttons').style.display='none';document.getElementById('contentTitle').style.display='none';document.getElementById('error-message').textContent=errorMessage;document.getElementById('error-message').style.display='block'}
function displayChapterContent(chapterData){const titleElement=document.getElementById('contentTitle');const contentElement=document.getElementById('chapterContent');titleElement.textContent=chapterData.title;const contentParts=chapterData.content.split('\n');contentElement.innerHTML='';contentParts.forEach((part)=>{const contentBlock=document.createElement('div');contentBlock.classList.add('content-block');contentBlock.setAttribute('data-content',part);contentElement.appendChild(contentBlock)});document.getElementById('chapterContent').style.display='block';document.querySelector('.nav-buttons').style.display='';const contentBlocks=document.querySelectorAll('.content-block');contentBlocks.forEach(block=>{block.style.display='block'});document.getElementById('contentTitle').style.display=''}
function initializeNavigation(){let currentIndex=chapters.findIndex(chapter=>chapter.chapter===currentChapter);function navigateToChapter(chapterName){currentChapter=chapterName;urlParams.set('chap',chapterName);urlParams.set('pass',currentPass||'');const newUrl=window.location.origin+window.location.pathname+'?'+urlParams.toString();history.replaceState(null,'',newUrl);currentIndex=chapters.findIndex(chapter=>chapter.chapter===currentChapter);fetchChapterContent(id,currentChapter,currentPass)}
document.getElementById('prevBtn').onclick=function(){if(currentIndex>0){const prevChapter=chapters[currentIndex-1];if(prevChapter.status==='Locked'){const userPass=prompt(`Chương trước đã bị khóa! Nếu sử dụng mật khẩu VIP, bạn sẽ bị trừ 100 đồng. Mật khẩu hiện tại bạn đang sử dụng là: ${currentPass || 'không có'}:`,currentPass||'');if(userPass!==null){currentPass=userPass;navigateToChapter(prevChapter.chapter)}}else{navigateToChapter(prevChapter.chapter)}}else{alert('Đây đã là chương đầu tiên rồi, bạn còn muốn văng đi đâu nữa!')}};document.getElementById('nextBtn').onclick=function(){if(currentIndex<chapters.length-1){const nextChapter=chapters[currentIndex+1];if(nextChapter.status==='Locked'){const userPass=prompt(`Chương sau vẫn bị khóa! Nếu sử dụng mật khẩu VIP, bạn sẽ bị trừ 100 đồng. Mật khẩu hiện tại bạn đang sử dụng là: ${currentPass || 'Không có'}:`,currentPass||'');if(userPass!==null){currentPass=userPass;navigateToChapter(nextChapter.chapter)}}else{navigateToChapter(nextChapter.chapter)}}else{alert('Chúc mừng bạn đã kiên trì đọc đến chương cuối cùng...')}}}
document.getElementById('unlockBtn').onclick=function(){const password=document.getElementById('password').value;if(password){currentPass=password;document.getElementById('loader').style.display='block';urlParams.set('pass',currentPass);const newUrl=window.location.origin+window.location.pathname+'?'+urlParams.toString();history.replaceState(null,'',newUrl);fetchChapterContent(id,currentChapter,currentPass).finally(()=>{document.getElementById('loader').style.display='none'})}else{document.getElementById('error-message').innerText='Vui lòng nhập mật khẩu!'}};window.addEventListener('load',function(){if(!currentChapter){document.getElementById('passwordDiv').style.display='none'}});window.addEventListener('beforeunload',function(){sessionStorage.removeItem(`chapters_${id}`)});const texts=["Đang lấy dữ liệu...","Nếu chương bị khóa...","Đừng lo lắng...","Cài VIP ngay...","100 đồng 1 chương...","Đồng giá mọi chương...","Đọc lì không hết...","Ủng hộ bé tác giả...","Đang bạc trắng đầu...","Tay gãy chân đau...","Mắt mờ lưng mỏi...","Tạo nên ngôn từ...","Sắp thấy rồi đây..."];let index=0;function changeText(){const loaderText=document.getElementById('loader-text');loaderText.textContent=texts[index];index=(index+1)%texts.length}
const intervalId=setInterval(changeText,900);function trackReadingHistory(){const urlParams=new URLSearchParams(window.location.search);const id=urlParams.get('id');const chap=urlParams.get('chap');if(id&&chap){const url=window.location.href;let readingHistory=JSON.parse(localStorage.getItem('readingHistory'))||{};readingHistory[id]={chapter:chap,url:url};localStorage.setItem('readingHistory',JSON.stringify(readingHistory))}}
trackReadingHistory();window.addEventListener('popstate',trackReadingHistory);window.addEventListener('hashchange',trackReadingHistory);(function(){const originalPushState=history.pushState;const originalReplaceState=history.replaceState;history.pushState=function(...args){originalPushState.apply(history,args);trackReadingHistory()};history.replaceState=function(...args){originalReplaceState.apply(history,args);trackReadingHistory()}})();</script>
</body>
</html>

