Loan XuânChương 14
$(“img”).on(“error”, function () {
$(this).attr(‘src’, ‘/images/no-image.jpg’);
});
// window.show_ads = 1;
var isMobile = (window.innerWidth {
if (document.querySelector(‘.feedback-container.show’)) {
return;
}
if (document.querySelector(‘.modal.show’)) {
return;
}
if (document.querySelector(‘.stop-pull-to-refresh-when-open.show’)) {
return;
}
await swCLEARCACHE();
setTimeout(() => {
window.location.reload();
}, 200);
}
});
}
if((!window.jwtInfo?.vip_to || window.jwtInfo?.vip_to <=0) && (!window.jwtInfo?.ads_hidden || window.jwtInfo?.ads_hidden <=0)){
let srcipt_as = document.createElement('script');
srcipt_as.src = "/js/as.js?v=20260602_1";
srcipt_as.setAttribute('id', 'js_as');
if(!document.getElementById('js_as')){
srcipt_as.setAttribute('data-no-instant', '');
document.getElementById('ads_xuyen_trang_bottom').appendChild(srcipt_as);
}
}
var autoPlayEndedHandler;
function handleAutoPlay(player, videoKey) {
autoPlayEndedHandler = () => {
let nextChapter = $(‘.chapter-next’).attr(‘href’);
localStorage.removeItem(videoKey);
location.href = nextChapter;
};
player.on(‘ended’, autoPlayEndedHandler);
}
$(window).resize(function() {
if (this.resizeTO) clearTimeout(this.resizeTO);
this.resizeTO = setTimeout(() => {
if ($(window).width() !== this.prevWidth) {
$(this).trigger(‘resizeEnd’);
this.prevWidth = $(window).width();
}
}, 500);
});
function renderCanvas({ content, fontSize, fontFamily, lineHeightPercent }) {
if (!content) return;
// Tạo container và canvas
const canvas = $(”);
const dpr = window.devicePixelRatio || 1; // Đảm bảo chất lượng cao hơn
// const dpr = 1; // Đảm bảo chất lượng cao hơn
// Lấy kích thước container
const canvasWidth = Math.floor($(‘.content-chapter>article’).width());
canvas.attr(‘width’, canvasWidth * dpr);
canvas.css({
width: `${canvasWidth}px`,
height: ‘auto’, // Chiều cao sẽ tự điều chỉnh
});
// Thiết lập context
const ctx = $(canvas)[0].getContext(‘2d’);
ctx.scale(dpr, dpr);
ctx.font = `${fontSize}px ${fontFamily}`;
ctx.fillStyle = ‘#212529’;
ctx.textAlign = “left”; // Căn lề trái
ctx.textBaseline = ‘top’;
// Tính lineHeight
const baseLineHeight = fontSize;
const lineHeight = (baseLineHeight * lineHeightPercent) / 100;
// Thêm khoảng trắng top giống thẻ
const topPadding = lineHeight * 0.3; // 30% lineHeight làm padding trên
// Hàm xử lý văn bản
function processText(content) {
const parser = new DOMParser();
const doc = parser.parseFromString(content, ‘text/html’);
const nodes = doc.body.childNodes;
const parts = [];
nodes.forEach((node) => {
if (node.nodeType === Node.TEXT_NODE) {
const splitText = node.textContent.split(//);
splitText.forEach((part, index) => {
parts.push({ text: part.trim(), bold: false });
if (index {
const words = text.split(‘ ‘);
words.forEach((word) => {
if (word === ‘n’) {
context.fillText(currentLine.trim(), x, currentY);
currentLine = ”;
currentY += lineHeight;
} else {
const testLine = currentLine + word + ‘ ‘;
context.font = `${italic ? ‘italic ‘ : ”}${bold ? ‘bold ‘ : ”}${fontSize}px ${fontFamily}`;
const testWidth = context.measureText(testLine).width;
if (testWidth > maxWidth && currentLine) {
context.fillText(currentLine.trim(), x, currentY);
currentLine = word + ‘ ‘;
currentY += lineHeight;
} else {
currentLine = testLine;
}
}
});
});
if (currentLine) {
context.fillText(currentLine.trim(), x, currentY);
currentY += lineHeight;
}
return currentY; // Trả về vị trí Y cuối cùng sau khi render xong
}
// Xử lý văn bản để tính chính xác chiều cao
let yPosition = topPadding;
const lines = content.split(‘n’);
let totalHeight = yPosition;
lines.forEach((line) => {
const parts = processText(line);
totalHeight = wrapTextWithFormatting(ctx, parts, 0, yPosition, canvasWidth, lineHeight);
yPosition = totalHeight;
});
// Cập nhật chiều cao canvas chính xác
canvas.attr(‘height’, totalHeight * dpr);
canvas.css(‘height’, `${totalHeight}px`);
// Render lại với đúng chiều cao mới
const updatedCtx = $(canvas)[0].getContext(‘2d’);
updatedCtx.scale(dpr, dpr);
updatedCtx.fillStyle = ‘#212529’;
updatedCtx.textAlign = ‘left’;
updatedCtx.textBaseline = ‘top’;
yPosition = topPadding;
lines.forEach((line) => {
const parts = processText(line);
yPosition = wrapTextWithFormatting(updatedCtx, parts, 0, yPosition, canvasWidth, lineHeight);
});
return canvas;
}
$(window).bind(‘resizeEnd’, function() {
if ($(‘.content-chapter>article’).length > 0) {
window.callSeeMoreContentChapter();
}
});
function handleRenderCanvas(chapterContent) {
const contentChapterArticle = $(‘.content-chapter>article’);
contentChapterArticle.empty();
const fontFamilyId = window.getCookie(‘font_chapter’);
const fontSize = window.getCookie(‘font_size_chapter’);
const lineHeight = window.getCookie(‘line_height_chapter’);
const targetFontConfig = window.objConfigFont.find(item => item.name == fontFamilyId);
const tempDiv = $(‘
const paragraphs = tempDiv.find(‘p’);
let parts = [];
if (paragraphs.length == 0) {
contentChapterArticle.html(chapterContent);
return;
}
if (paragraphs.length > 5) {
parts = chapterContent.split(‘n’).filter(item => item.trim() !== ”);
} else {
const singleParagraph = paragraphs.last().html();
parts = singleParagraph.split(//i)
.filter(item => item.trim() !== ”)
.map(item => {
item = item.trim();
if (!item.startsWith(‘<p') || !item.endsWith('')) {
return `
${item}`;
}
return item;
});
}
let startIndex = Math.floor(Math.random() * (parts.length – 5));
let selectedParagraphs = Array.from(parts).slice(startIndex, startIndex + 5);
let content = decodeHtmlEntities(selectedParagraphs);
content = content.join(‘n’);
if (typeof content === ‘string’) {
let canvasContainer = renderCanvas({
content,
fontSize: fontSize || ($(window).width() <= 992 ? 20 : 16),
fontFamily: targetFontConfig?.value || "'Roboto Condensed', sans-serif",
lineHeightPercent: lineHeight || ($(window).width() {
contentChapterArticle.append(item)
})
}else{
alert(‘Có lỗi hiện nội dung chương’)
contentChapterArticle.html(chapterContent);
}
}
function decodeHtmlEntities(text) {
if (!text) {
return [];
}
const parser = new DOMParser();
const doc = parser.parseFromString(text, ‘text/html’);
let result = [];
let currentContent = “”;
// Duyệt qua tất cả các node con
doc.body.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE && !node.textContent.trim()) {
return; // Bỏ qua node trống
}
if (node.nodeName.toLowerCase() === “p”) {
// Thêm nội dung của
vào đoạn hiện tại
currentContent += (node.innerHTML || node.textContent) + “n”;
} else {
// Gặp thẻ khác, lưu đoạn hiện tại và thêm thẻ này vào mảng
if (currentContent.trim()) {
result.push(currentContent.trim());
currentContent = “”; // Reset đoạn hiện tại
}
if (node.outerHTML) {
result.push(node.outerHTML.trim()); // Thêm thẻ nguyên vẹn
}
}
});
// Đẩy đoạn cuối cùng vào mảng nếu còn
if (currentContent.trim()) {
result.push(currentContent.trim());
}
return result;
}
window.callSeeMoreContentChapter = function (type = 1) {
$(“#btn-see-more-chapter”).text(“Đang kiểm tra trạng thái…”);
let chapterContent = $(‘.chapter-content .content-chapter>article’);
if(!chapterContent.length){
chapterContent = $(‘.chapter-content .content-chapter’);
}
let story_id = $(“#cmt_story_id”).val();
let chapter_id = $(“#cmt_chapter_id”).val();
myAjax(“post”, “/api/chapter/get-chapter-content”, {
story_id: story_id,
chapter_id: chapter_id,
},
function (res) {
try {
$(“#loadingItem”).removeClass(“d-flex”);
chapterContent.html(res?.cont);
// handleRenderCanvas(res?.cont);
if (res?.audio_path) {
$(“.box-chapter-audio”).fadeOut(100, function() {
$(this).html(`Nghe audio
`).fadeIn(100);
setTimeout(function () {
var audio = document.getElementById(“myAudio”);
if(audio){
audio.addEventListener(“play”, function () {
myAjax(“post”, “/api/chapter/action/nghe_audio”, {
“story_id”: story_id,
“chapter_id”: chapter_id
});
});
}
},1)
});
}
} catch (e) {
alert(“Có lỗi hiển thị nội dung chương”);
}
if (type == 2) { // audio
// if (!$(‘.audio-content’).length) {
// chapterContent.append(‘
// }
if ($(‘.audio-plyr’).length) {
var audioKey = `audio_story_${story_id}_chapter_${chapter_id}`;
let player = {};
try {
player = new Plyr(‘.audio-plyr’);
} catch (e) {
location.reload();
}
let savedTime = localStorage.getItem(audioKey);
if (savedTime) {
player.once(‘loadedmetadata’, () => {
player.currentTime = parseFloat(savedTime);
});
}
player.on(‘timeupdate’, event => {
var currentTime = player.currentTime;
localStorage.setItem(audioKey, currentTime);
});
let isAutoPlay = localStorage.getItem(‘audio_auto_play’);
if (isAutoPlay==1) {
$(‘.audio-plyr’).prop(‘autoplay’, true);
handleAutoPlay(player, audioKey);
}
}
} else if (type == 3) { // video
// if (!$(‘.video-content’).length) {
// chapterContent.append(‘
// }
if ($(‘.video-plyr’).length) {
let videoKey = `video_story_${story_id}_chapter_${chapter_id}`;
let player = {};
try {
player = new Plyr(‘.video-plyr’);
} catch (e) {
location.reload();
}
let savedTime = localStorage.getItem(videoKey);
if (savedTime) {
player.once(‘loadedmetadata’, () => {
player.currentTime = parseFloat(savedTime);
});
}
player.on(‘timeupdate’, event => {
var currentTime = player.currentTime;
localStorage.setItem(videoKey, currentTime);
});
let isAutoPlay = localStorage.getItem(‘video_auto_play’);
if (isAutoPlay==1) {
$(‘.video-plyr’).prop(‘autoplay’, true);
handleAutoPlay(player, videoKey);
}
}
}
},
function (res) {
$(“#loadingItem”).removeClass(“d-flex”);
let msg = res?.responseJSON?.cont || res?.responseJSON?.message;
if (msg) {
$(“#btn-see-more-chapter”).text(msg)
} else {
$(“#btn-see-more-chapter”).text(“Có lỗi không xác định”)
}
})
};
$(document).delegate(“#btn-see-more-chapter”, “click”, debounce(function (e) {
e.preventDefault();
window.callSeeMoreContentChapter();
}, 300));
InstantClick.init(‘mousedown’)
function handleCredentialResponse(response) {
let token = response.credential;
myAjax(‘post’, ‘/api/login/google’, {
token: token
}, function (res) {
handleSocialLogin(res)
},
function (error) {
if (error?.responseJSON?.msg) {
Swal.fire({
position: ‘center’,
icon: ‘error’,
title: error?.responseJSON?.msg,
showConfirmButton: false,
timer: 2000
})
}
});
}
window.onload = function () {
if (!getCookie(‘token’)) {
google.accounts.id.initialize({
client_id: “450977676294-pmln91u90rnnmsa8775n79fsa3l14tpa.apps.googleusercontent.com”,
callback: handleCredentialResponse
});
google.accounts.id.prompt();
}
};
function credentialGGConnect(response) {
let token = response.credential;
myAjax(‘put’, “/api/profile/connect-social/google”, {token},
function(res){
window.TruyenFull.profile = res.profile
localStorage.setItem(“profile”, JSON.stringify(window.TruyenFull.profile));
location.reload();
},
function(err){
if (err?.responseJSON?.msg) {
Swal.fire({
position: ‘center’,
icon: ‘error’,
title: err?.responseJSON?.msg,
showConfirmButton: false,
timer: 2000
})
}
} )
}
function handleSocialLogin(res) {
setCookie(“token”, res.token, 30);
localStorage.setItem(“profile”, JSON.stringify(res.data?.profile));
localStorage.setItem(“bookmark”, JSON.stringify(res.data?.bookmark));
localStorage.setItem(“purchasedStory”, JSON.stringify(res.data?.purchasedStory));
localStorage.setItem(“purchasedChapters”, JSON.stringify(res.data?.purchasedChapters));
let params = new URLSearchParams(location.search);
let back_to = params.get(“back”);
if (back_to) {
location.href = back_to;
} else {
location.reload();
// location.href = “/profile”
}
}
var editor_config = {
path_absolute: “/”,
selector: “textarea.tinymce_content”,
language: ‘vi’,
statusbar: false,
plugins: [
“advlist autolink lists link image charmap print preview hr anchor pagebreak”,
“searchreplace wordcount visualblocks visualchars code fullscreen”,
“insertdatetime media nonbreaking save table contextmenu directionality”,
“emoticons template paste textcolor colorpicker textpattern”
],
toolbar: “insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent “,
menu: {
file: {
title: ‘File’,
items: ”
},
edit: {
title: ‘Edit’,
items: ‘ cut copy paste pastetext | selectall | searchreplace’
},
view: {
title: ‘View’,
items: ‘preview fullscreen | showcomments’
},
insert: {
title: ‘Insert’,
items: ‘ charmap emoticons hr | anchor tableofcontents | insertdatetime’
},
format: {
title: ‘Format’,
items: ‘bold italic underline strikethrough superscript subscript’
},
tools: {
title: ‘Tools’,
items: ‘wordcount’
},
table: {
title: ‘Table’,
items: ”
},
help: {
title: ‘Help’,
items: ”
}
},
setup: function (editor) {
editor.on(‘paste’, function (event) {
const clipboardData = event.clipboardData || event.originalEvent.clipboardData;
if (clipboardData && clipboardData.items) {
for (let i = 0; i { //nếu bỏ đi thì mỗi lần chuyển trang sẽ có chỗ đựoc thay trước khi dữ liệu đc truyền vào
tinymce.init(editor_config);
}, 100);
});
$(function () {
$(“[data-swiper]”).each(function () {
try {
let options = $(this).attr(“data-swiper”);
options = JSON.parse(options);
if (options) {
new Swiper(this, options);
}
} catch (err) {
console.error(“Check swiper options”, err);
}
});
});
$(function () {
$(“[data-swiper]”).each(function () {
try {
let options = $(this).attr(“data-swiper”);
options = JSON.parse(options);
if (options) {
new Swiper(this, options);
}
} catch (err) {
console.error(“Check swiper options”, err);
}
});
});
$(function () {
$(“[data-swiper]”).each(function () {
try {
let options = $(this).attr(“data-swiper”);
options = JSON.parse(options);
if (options) {
new Swiper(this, options);
}
} catch (err) {
console.error(“Check swiper options”, err);
}
});
});
var langChapters = “Chương”
(function() {
function applyChapterSettings() {
var font = window.getCookie(‘font_chapter’);
var fontSize = window.getCookie(‘font_size_chapter’);
var lineHeight = window.getCookie(‘line_height_chapter’);
var style = ”;
if (font || fontSize || lineHeight) {
style += ‘.chapter-content .content-chapter article, .chapter-content .content-chapter article p, .chapter-content .content-chapter article div {‘;
if (font) {
var fontMap = {
‘roboto’: “‘Roboto Condensed’, sans-serif”,
‘mooli’: “‘Mooli’, sans-serif”,
‘patrick_hand’: “‘Patrick Hand’, cursive”
};
if (fontMap[font]) style += ‘font-family: ‘ + fontMap[font] + ‘ !important;’;
}
if (fontSize) style += ‘font-size: ‘ + fontSize + ‘px !important;’;
if (lineHeight) style += ‘line-height: ‘ + lineHeight + ‘% !important;’;
style += ‘}’;
var styleTag = document.getElementById(‘client-chapter-settings’);
if (!styleTag) {
styleTag = document.createElement(‘style’);
styleTag.id = ‘client-chapter-settings’;
document.head.appendChild(styleTag);
}
styleTag.innerHTML = style;
}
}
applyChapterSettings();
if (typeof InstantClick !== ‘undefined’) {
InstantClick.on(‘change’, applyChapterSettings);
}
})();
if (getCookie(‘token’)) {
$(‘.btn-bookmark’).removeClass(‘d-none’);
myAjax(“post”, “/api/story-reading”, {
“story_id”: “137”,
“chapter_id”: “10542”
}, function(res) {
// if (res?.contents && res?.contents?.cont) {
// $(“.content-chapter>article”).html(”);
// handleRenderCanvas(res?.contents?.cont);
// if (res?.contents && res?.contents?.audio_path) {
// $(“.box-chapter-audio”).fadeOut(100, function() {
// $(this).html(`Nghe audio
//
`).fadeIn(100);
// setTimeout(function () {
// var audio = document.getElementById(“myAudio”);
// if(audio){
// audio.addEventListener(“play”, function () {
// myAjax(“post”, “/api/chapter/action/nghe_audio”, {
// “story_id”: “137”,
// “chapter_id”: “10542”
// });
// });
// }
// },1)
// });
// }
// }
}, function(err) {
console.log(err)
});
$(“.box-chapter-audio”).removeClass(‘d-none’)
} else {
$(“.box-chapter-audio”).remove()
}
$(function() {
var elementGroupSeeMore = $(“.group-see-more”);
var typePayStory = elementGroupSeeMore.attr(‘data-type-pay-story’);
var typePayChapter = elementGroupSeeMore.attr(‘data-type-pay-chapter’);
var typeIsLoginChapter = elementGroupSeeMore.attr(‘data-type-is-login-chapter’);
// var apiCalled = false;
var bookmark = JSON.parse(localStorage.getItem(“bookmark”));
var btnXemThemHtml =``;
var btnDangNhapHtml =`Đăng nhập để xem tiếp`;
$(‘.btn-bookmark’).addClass(‘btn-info’);
$(‘.btn-bookmark’).text(‘Lưu bookmark’);
if (bookmark?.length > 0) {
bookmark.map((item) => {
if (item.chapter_id == $(“.btn-bookmark”).attr(“data-chapter-id”)) {
$(‘.btn-bookmark’).removeClass(‘btn-info’);
$(‘.btn-bookmark’).addClass(‘btn-danger btn-delete-bookmark’);
$(‘.btn-bookmark’).text(‘Xóa bookmark’);
$(‘.btn-bookmark’).removeClass(‘btn-bookmark’)
}
})
}
// xong
if (typeIsLoginChapter != 1) {
// xử lý logic login
if (typePayStory != 0 || typePayChapter != 0) {
if (!getCookie(‘token’)) {
elementGroupSeeMore.html(btnDangNhapHtml)
} else {
window.callSeeMoreContentChapter(1);
}
}
} else {
if (!getCookie(‘token’)) {
elementGroupSeeMore.html(btnDangNhapHtml)
} else {
if (typePayStory == 0 && typePayChapter == 0) {
elementGroupSeeMore.html(btnXemThemHtml)
} else {
// truyện mất tiền, check trả phí
window.callSeeMoreContentChapter(1);
}
}
}
});
$(function() {
var historyChapterReading = JSON.parse(localStorage.getItem(‘historyChapterReading’)) ?? [];
if (historyChapterReading.length > 10) {
historyChapterReading = [];
return localStorage.setItem(‘historyChapterReading’, JSON.stringify(historyChapterReading))
}
if (historyChapterReading.length >= 0) {
let tim = historyChapterReading.findIndex((item) => item.story_id == “137”);
if (tim === -1) {
if (historyChapterReading.length === 10) {
historyChapterReading.pop()
}
historyChapterReading.push({
story_id: “137”,
story_name: “Loan Xuân – Hy Quân”,
story_link: “/truyen/” + “loan-xuan-hy-quan”,
chapter_number: “14”,
chapter_link: “/truyen/loan-xuan-hy-quan/” +
“chuong-14”,
time: Date.now(),
})
} else {
historyChapterReading[tim] = {
story_id: “137”,
story_name: “Loan Xuân – Hy Quân”,
story_link: “/truyen/” + “loan-xuan-hy-quan”,
chapter_number: “14”,
chapter_link: “/truyen/loan-xuan-hy-quan/” +
“chuong-14”,
time: Date.now(),
}
}
historyChapterReading = historyChapterReading.sort(function(a, b) {
return b.time – a.time;
});
return localStorage.setItem(‘historyChapterReading’, JSON.stringify(historyChapterReading))
}
});
{
“@context”: “https://schema.org/”,
“@type”: “BreadcrumbList”,
“itemListElement”: [{
“@type”: “ListItem”,
“position”: 1,
“name”: “Đọc Truyện”,
“item”: “https://etruyen.net”
},{
“@type”: “ListItem”,
“position”: 2,
“name”: “Loan Xuân – Hy Quân”,
“item”: “https://etruyen.net/truyen/loan-xuan-hy-quan”
},{
“@type”: “ListItem”,
“position”: 3,
“name”: “Chương 14”,
“item”: “https://etruyen.net/truyen/loan-xuan-hy-quan/chuong-13”
}]
}
/* googleoff: all */
if(localStorage.getItem(“access_login”)){
setCookie(“token”, localStorage.getItem(“access_login”), 30);
localStorage.removeItem(“access_login”);
}
var access_login = getCookie(“token”);
$(window).on(‘load’, function () {
checkAccessLogin()
});
InstantClick.on(‘change’, function () {
checkAccessLogin();
if (window.FB) {
window.FB.XFBML.parse()
}
});
function checkAccessLogin() {
const urlAllow = [“profile”, “gio-hang”];
const urlLogin = [“dang-nhap”, “dang-ky”];
if (!location.href.includes(`profile`)) {
clearInterval(window.TruyenFull.initIntervalTransaction);
}
if (!access_login) {
urlAllow.map((item) => {
if (location.href.includes(`${item}`)) {
location.href = “/dang-nhap”
}
})
} else {
urlLogin.map((item) => {
if (location.href.includes(`${item}`)) {
location.href = “/profile”
}
})
}
// if (window.location.href != “https://etruyen.net/”) {
// clearInterval(window.TruyenFull.initIntervalSelectStoriesHot)
// } else {
// clearInterval(window.TruyenFull.initIntervalSelectStoriesHot);
// window.TruyenFull.initIntervalSelectStoriesHot = setInterval(window.initIntervalSelectStoriesHot, 60000);
// }
}
$(function () {
if (access_login) {
$(“.hasLogin”).removeClass(“d-none”);
$(‘.shopping-cart’).removeClass(“d-none”);
var profile = window.TruyenFull.profile || {};
if (profile) {
if (profile.name) {
$(“.user-name-top”).text(profile.name);
}else{
$(“.user-name-top”).text(“Tài khoản”);
}
if (profile.avatar) {
var avatarUrl = profile.avatar;
if (!avatarUrl.startsWith(‘http’)) {
avatarUrl = window.TruyenFull.cdnUrl + ‘/’ + avatarUrl;
}
$(“.user-avatar-top”).attr(“src”, avatarUrl).removeClass(“d-none”);
}
}else{
$(“.user-name-top”).text(“Tài khoản”);
}
$(document).on(“click”, “.logout”, function () {
removeCookie(“token”);
localStorage.removeItem(“access_login”);
localStorage.removeItem(“profile”);
localStorage.removeItem(“bookmark”);
localStorage.removeItem(“purchasedStory”);
localStorage.removeItem(“purchasedChapters”);
$.ajax({
type: “get”,
url: “https://etruyen.net/dang-xuat?user_id=” + window?.TruyenFull?.profile?.id,
dataType: “json”,
success: function (response) {
location.reload()
}
});
});
$(“.checkout-to-dich-gia”).attr(‘href’, “https://etruyen.net/dang-truyen/dashboard?token=”)
} else {
$(“.yetLogin”).removeClass(“d-none”);
let params = new URLSearchParams(location.search);
let back_to = params.get(“back”);
if (back_to) {
$(“.checkout-to-dich-gia”).attr(‘href’, “/dang-nhap?back=” + back_to)
} else {
$(“.checkout-to-dich-gia”).attr(‘href’, “/dang-nhap?back=” + location.href)
}
}
});
/* googleon: all */
/* googleoff: all */
if (window.TruyenFull.profile?.id) {
let updateTimeActiveCustomer = ()=>{
myAjax(“post”, “https://etruyen.net/api/ping”, {
playerId: window.TruyenFull.plugins.one_signal.one_signal_user_id,
check_as: (window.jwtInfo?.vip_to {
location.href = “/dang-nhap”;
})
}else{
location.reload();
}
// location.href = “/”
}else if(res?.meta?.token){
setCookie(“token”, res?.meta?.token, 30);
location.reload();
}
}, function (err) {
// console.log(“err”,err)
})
}
updateTimeActiveCustomer();
setInterval(updateTimeActiveCustomer, 60000);
if (window.EventSource) {
const sseUrl = “/api/auth/sse-session”;
const sseSource = new EventSource(sseUrl);
sseSource.onmessage = function(event) {
try {
const data = JSON.parse(event.data);
if (data.status === ‘session_expired’) {
sseSource.close();
if (window.Swal) {
removeCookie(“token”);
localStorage.removeItem(“profile”);
localStorage.removeItem(“bookmark”);
localStorage.removeItem(“purchasedStory”);
localStorage.removeItem(“purchasedChapters”);
Swal.fire({
title: ‘Thông báo!’,
text: data.message || ‘Tài khoản của bạn đã được đăng nhập trên một thiết bị khác.’,
icon: ‘warning’,
confirmButtonText: ‘Đồng ý’,
allowOutsideClick: false,
allowEscapeKey: false,
timer: 3000
}).then(() => {
location.href = “/dang-nhap”;
})
} else {
removeCookie(“token”);
localStorage.removeItem(“profile”);
localStorage.removeItem(“bookmark”);
localStorage.removeItem(“purchasedStory”);
localStorage.removeItem(“purchasedChapters”);
alert(data.message || ‘Tài khoản của bạn đã được đăng nhập trên một thiết bị khác.’);
location.href = “/dang-nhap”;
}
}
} catch (e) {
console.error(“SSE parse error”, e);
}
};
sseSource.onerror = function(err) {
console.error(“SSE Session Error”, err);
};
}
}
/* googleon: all */




















Mới nhất
Cũ nhất