/* domucgiare: muc "Uu dai - giam gia" trang chu, lay tu /san-pham-khuyen-mai (v2) */ (function () { if (location.pathname !== '/' && location.pathname !== '/index.html') return; var anchor = document.querySelector('#content .home > .row > .banner-under-slideshow'); if (!anchor || document.getElementById('tvgg')) return; var css = [ '#tvgg{clear:both;margin:16px 0 6px;font-family:Arial,sans-serif}', '#tvgg .tvgg-w{background:linear-gradient(135deg,#fff6f2 0%,#fff 55%);border:1px solid #f3d6cc;border-radius:12px;padding:16px 16px 12px;box-shadow:0 2px 10px rgba(20,40,75,.06)}', '#tvgg .tvgg-h{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin-bottom:12px}', '#tvgg .tvgg-h2{margin:0;font-size:20px;line-height:1.25;font-weight:700;color:#14284b;text-transform:uppercase;display:flex;align-items:center;gap:8px}', '#tvgg .tvgg-tt{color:#e4342b}#tvgg .tvgg-h2 svg{flex:0 0 auto;color:#e4342b}', '#tvgg .tvgg-sub{margin:4px 0 0;color:#5a6577;font-size:13.5px;line-height:1.45}', '#tvgg .tvgg-all{display:inline-flex;align-items:center;gap:6px;background:#e4342b;color:#fff!important;font-weight:700;font-size:14px;padding:8px 14px;border-radius:20px;text-decoration:none!important;white-space:nowrap}', '#tvgg .tvgg-all:hover{background:#c4241c}', '#tvgg .tvgg-vp{position:relative}', '#tvgg .tvgg-row{display:flex;gap:12px;overflow-x:auto;scroll-snap-type:x mandatory;scroll-behavior:smooth;padding:2px 2px 10px;margin:0;list-style:none;-webkit-overflow-scrolling:touch;scrollbar-width:thin}', '#tvgg .tvgg-row::-webkit-scrollbar{height:6px}#tvgg .tvgg-row::-webkit-scrollbar-thumb{background:#e7c3b8;border-radius:3px}', '#tvgg .tvgg-c{flex:0 0 calc((100% - 48px)/5);min-width:0;scroll-snap-align:start;background:#fff;border:1px solid #eadfdb;border-radius:10px;overflow:hidden;display:flex;flex-direction:column;transition:box-shadow .2s,transform .2s}', '#tvgg .tvgg-c:hover{box-shadow:0 6px 16px rgba(20,40,75,.12);transform:translateY(-2px)}', '#tvgg .tvgg-im{position:relative;display:block;aspect-ratio:400/294;background:#f4f4f4}', '#tvgg .tvgg-im img{width:100%;height:100%;object-fit:cover;display:block}', '#tvgg .tvgg-bd{position:absolute;top:8px;left:8px;background:#e4342b;color:#fff;font-weight:700;font-size:13px;padding:3px 8px;border-radius:6px;box-shadow:0 2px 6px rgba(228,52,43,.35)}', '#tvgg .tvgg-tx{padding:10px 10px 12px;display:flex;flex-direction:column;gap:6px;flex:1}', '#tvgg .tvgg-t{font-size:13.5px;line-height:1.4;font-weight:700;color:#14284b!important;text-decoration:none!important;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;min-height:38px}', '#tvgg .tvgg-t:hover{color:#e4342b!important}', '#tvgg .tvgg-p{margin-top:auto;display:flex;align-items:baseline;gap:8px;flex-wrap:wrap}', '#tvgg .tvgg-n{color:#e4342b;font-weight:700;font-size:16px}', '#tvgg .tvgg-o{color:#8a93a3;font-size:12.5px;text-decoration:line-through}', '#tvgg .tvgg-s{font-size:12px;color:#1b7f3b;font-weight:700}', '#tvgg .tvgg-ar{position:absolute;top:calc(50% - 26px);width:36px;height:36px;border-radius:50%;border:0;background:#fff;color:#14284b;box-shadow:0 2px 8px rgba(0,0,0,.18);font-size:20px;line-height:36px;text-align:center;cursor:pointer;z-index:2;padding:0}', '#tvgg .tvgg-ar:hover{background:#14284b;color:#fff}', '#tvgg .tvgg-pv{left:-10px}#tvgg .tvgg-nx{right:-10px}', '#tvgg .tvgg-sk{flex:0 0 calc((100% - 48px)/5);height:260px;border-radius:10px;background:linear-gradient(90deg,#f3eeec 25%,#faf7f6 50%,#f3eeec 75%);background-size:200% 100%;animation:tvggsk 1.2s infinite}', '@keyframes tvggsk{0%{background-position:200% 0}100%{background-position:-200% 0}}', '#tvgg .tvgg-ft{margin:6px 0 0;font-size:12.5px;color:#5a6577}', '#tvgg .tvgg-ft a{color:#14284b;font-weight:700}', '@media (max-width:1199px){#tvgg .tvgg-c,#tvgg .tvgg-sk{flex-basis:calc((100% - 36px)/4)}}', '@media (max-width:767px){#tvgg{margin:12px 0 4px}#tvgg .tvgg-w{padding:12px 10px 8px;border-radius:10px}#tvgg .tvgg-h2{font-size:17px}#tvgg .tvgg-sub{font-size:13px}#tvgg .tvgg-all{font-size:13px;padding:7px 12px}#tvgg .tvgg-row{gap:10px}#tvgg .tvgg-c,#tvgg .tvgg-sk{flex-basis:44%}#tvgg .tvgg-ar{display:none}#tvgg .tvgg-n{font-size:15px}}' ].join(''); var st = document.createElement('style'); st.id = 'tvgg-css'; st.textContent = css; document.head.appendChild(st); var flame = '\x3csvg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true">\x3cpath fill="currentColor" d="M13.5 1s.7 2.6.7 4.6c0 1.9-1.3 3.5-3.2 3.5S7.6 7.5 7.6 5.6l.1-.6C5.6 7.5 4.3 10.7 4.3 14.2 4.3 18.5 7.8 22 12 22s7.7-3.5 7.7-7.8C19.7 9 17.2 4.4 13.5 1zM11.7 19c-1.6 0-2.9-1.3-2.9-2.8 0-1.4.9-2.4 2.5-2.7 1.6-.3 3.2-1.1 4.1-2.3.4 1.1.6 2.3.6 3.5 0 2.4-1.9 4.3-4.3 4.3z"/>\x3c/svg>'; var box = document.createElement('div'); box.id = 'tvgg'; box.className = 'col-xs-12 col-sm-12 col-md-12 col-lg-12'; box.setAttribute('aria-labelledby', 'tvgg-title'); var sk = ''; for (var s = 0; s < 5; s++) sk += '\x3cli class="tvgg-sk">\x3c/li>'; box.innerHTML = '\x3csection class="tvgg-w">' + '\x3cdiv class="tvgg-h">\x3cdiv>' + '\x3ch2 class="tvgg-h2" id="tvgg-title">' + flame + '\x3cspan>\x3cspan class="tvgg-tt">Xả kho giảm sốc\x3c/span>: máy in, linh kiện & dịch vụ sửa chữa\x3c/span>\x3c/h2>' + '\x3cp class="tvgg-sub">Giá xả kho có hạn – hàng tồn, máy trưng bày và dịch vụ đang giảm mạnh. Gọi hoặc nhắn Zalo để giữ hàng ngay.\x3c/p>' + '\x3c/div>\x3ca class="tvgg-all" href="/san-pham-khuyen-mai" title="Xem tất cả sản phẩm, dịch vụ khuyến mại">Săn ưu đãi ngay →\x3c/a>\x3c/div>' + '\x3cdiv class="tvgg-vp">\x3cul class="tvgg-row">' + sk + '\x3c/ul>\x3c/div>' + '\x3c/section>'; anchor.parentNode.insertBefore(box, anchor.nextSibling); function num(t) { var m = (t || '').replace(/[^\d]/g, ''); return m ? parseInt(m, 10) : 0; } function fmt(n) { return n.toLocaleString('vi-VN').replace(/,/g, '.') + 'đ'; } function esc(t) { return String(t || '').replace(/&/g, '&').replace(/"/g, '"').replace(/\x3c/g, '<').replace(/>/g, '>'); } function cap(t) { t = t.trim(); return t.charAt(0).toUpperCase() + t.slice(1); } function parse(html) { var d = new DOMParser().parseFromString(html, 'text/html'); var out = []; [].forEach.call(d.querySelectorAll('.c-product'), function (e) { var a = e.querySelector('.title-name a'); if (!a) return; var img = e.querySelector('.item_product_thumb img'); var o = num((e.querySelector('.price_old') || {}).textContent); var n = num((e.querySelector('.price .new, .price .color_red') || {}).textContent); out.push({ u: a.getAttribute('href'), t: cap(a.getAttribute('title') || a.textContent), i: img ? img.getAttribute('src') : '', o: o, n: n }); }); return out; } function render(list) { list = list.filter(function (x) { return x.u && x.i; }); if (!list.length) { box.style.display = 'none'; return; } list.forEach(function (x) { x.pc = (x.o > x.n && x.n > 0) ? Math.round((x.o - x.n) * 100 / x.o) : 0; }); list.sort(function (a, b) { return b.pc - a.pc; }); if (list[0].pc >= 10) { var tt = box.querySelector('.tvgg-tt'); if (tt) tt.textContent = 'Xả kho giảm sốc đến ' + list[0].pc + '%'; } var h = ''; list.forEach(function (x, k) { h += '\x3cli class="tvgg-c">' + '\x3ca class="tvgg-im" href="' + esc(x.u) + '" title="' + esc(x.t) + '">' + '\x3cimg src="' + esc(x.i) + '" alt="' + esc(x.t) + '" width="400" height="294" loading="lazy" decoding="async">' + (x.pc ? '\x3cspan class="tvgg-bd">-' + x.pc + '%\x3c/span>' : '') + '\x3c/a>\x3cdiv class="tvgg-tx">' + '\x3ca class="tvgg-t" href="' + esc(x.u) + '">' + esc(x.t) + '\x3c/a>' + '\x3cdiv class="tvgg-p">' + (x.n ? '\x3cspan class="tvgg-n">' + fmt(x.n) + '\x3c/span>' : '\x3cspan class="tvgg-n">Liên hệ\x3c/span>') + (x.pc ? '\x3cspan class="tvgg-o">' + fmt(x.o) + '\x3c/span>' : '') + '\x3c/div>' + (x.pc ? '\x3cspan class="tvgg-s">Tiết kiệm ' + fmt(x.o - x.n) + '\x3c/span>' : '') + '\x3c/div>\x3c/li>'; }); var vp = box.querySelector('.tvgg-vp'); vp.innerHTML = '\x3cbutton type="button" class="tvgg-ar tvgg-pv" aria-label="Xem ưu đãi trước">‹\x3c/button>' + '\x3cul class="tvgg-row">' + h + '\x3c/ul>' + '\x3cbutton type="button" class="tvgg-ar tvgg-nx" aria-label="Xem ưu đãi tiếp">›\x3c/button>'; var row = vp.querySelector('.tvgg-row'); function step() { var c = row.querySelector('.tvgg-c'); return c ? (c.offsetWidth + 12) * 2 : 400; } vp.querySelector('.tvgg-pv').onclick = function () { row.scrollLeft -= step(); }; vp.querySelector('.tvgg-nx').onclick = function () { row.scrollLeft += step(); }; var ld = { '@context': 'https://schema.org', '@type': 'ItemList', name: 'Ưu đãi giảm giá tại Máy In Mực In Thần Vũ', url: location.origin + '/san-pham-khuyen-mai', itemListElement: list.map(function (x, k) { return { '@type': 'ListItem', position: k + 1, name: x.t, url: location.origin + x.u }; }) }; var sc = document.createElement('script'); sc.type = 'application/ld+json'; sc.textContent = JSON.stringify(ld); document.head.appendChild(sc); } var KEY = 'tvggData2', cached = null; try { cached = JSON.parse(localStorage.getItem(KEY) || 'null'); } catch (e) {} if (cached && cached.d && (Date.now() - cached.at) < 30 * 60 * 1000) { render(cached.d); return; } fetch('/san-pham-khuyen-mai', { credentials: 'same-origin' }) .then(function (r) { return r.text(); }) .then(function (t) { var list = parse(t); try { localStorage.setItem(KEY, JSON.stringify({ at: Date.now(), d: list })); } catch (e) {} render(list); }) .catch(function () { if (cached && cached.d) render(cached.d); else box.style.display = 'none'; }); })();