"use strict";
var __awaiter=(this&&this.__awaiter)||function (thisArg, _arguments, P, generator){
function adopt(value){ return value instanceof P ? value:new P(function (resolve){ resolve(value); });}
return new (P||(P=Promise))(function (resolve, reject){
function fulfilled(value){ try { step(generator.next(value)); } catch (e){ reject(e); }}
function rejected(value){ try { step(generator["throw"](value)); } catch (e){ reject(e); }}
function step(result){ result.done ? resolve(result.value):adopt(result.value).then(fulfilled, rejected); }
step((generator=generator.apply(thisArg, _arguments||[])).next());
});
};
class QuizEducateToolkit {
constructor(){
this._blockContextMenu=null;
this.initCopyLink();
this.initAdBlock();
this.initFbIab();
this.initGoogleForm();
}
onReady(fn){
if(document.readyState!=='loading'){
fn();
}else{
document.addEventListener('DOMContentLoaded', fn);
}}
initCopyLink(){
var _a;
if(!((_a=window.qeCopyData)===null||_a===void 0 ? void 0:_a.enabled))
return;
document.addEventListener('copy', (e)=> {
var _a, _b, _c, _d;
const activeTag=(_a=document.activeElement)===null||_a===void 0 ? void 0:_a.tagName.toLowerCase();
if(activeTag==='input'||activeTag==='textarea'||((_b=document.activeElement)===null||_b===void 0 ? void 0:_b.isContentEditable)){
return;
}
const rawText=((_c=window.getSelection())===null||_c===void 0 ? void 0:_c.toString())||'';
const cleanText=rawText.replace(/[\s\u200B-\u200D\uFEFF]/g, '');
const d=window.qeCopyData;
if(!d)
return;
let minLength=parseInt(d.min_length, 10);
if(isNaN(minLength))
minLength=5;
if(cleanText.length===0||cleanText.length < minLength)
return;
const parts=[];
if(d.header||rawText)
parts.push(`${d.header}${rawText}`);
if(d.footer)
parts.push(d.footer);
if(d.label||d.url)
parts.push(`${d.label}${d.url}`);
if(d.hash)
parts.push(d.hash);
const newText=parts.join('\n');
(_d=e.clipboardData)===null||_d===void 0 ? void 0:_d.setData('text/plain', newText);
e.preventDefault();
});
}
initAdBlock(){
var _a;
if(!((_a=window.qeProtectData)===null||_a===void 0 ? void 0:_a.enabled)){
return;
}
window.addEventListener('load', ()=> {
this.detectAdBlock();
});
this.onReady(()=> {
const innerDiv=document.querySelector('.innerDiv');
if(innerDiv){
innerDiv.style.setProperty('height', 'auto', 'important');
}});
}
detectAdBlock(){
return __awaiter(this, void 0, void 0, function* (){
const isDivTestSuccessful=this.performDivTest();
if(isDivTestSuccessful){
this.constructAdBlockModal();
return;
}
const isAdvScriptTestSuccessful=yield this.performAdvScriptTest();
if(isAdvScriptTestSuccessful){
this.constructAdBlockModal();
}
this.cleanAdBlockDocument();
});
}
performDivTest(){
const adClasses=["ad", "ads", "adsbox", "doubleclick", "ad-placement", "ad-placeholder", "adbadge", "BannerAd"];
const checkElm=document.createElement("div");
checkElm.setAttribute("id", "qeCheckElm");
for (const item of adClasses){
checkElm.classList.add(item);
}
document.body.appendChild(checkElm);
const getProperty=window.getComputedStyle(checkElm).getPropertyValue("display");
return getProperty==='none';
}
performAdvScriptTest(){
const REQUEST_URL='https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
const REQUEST_CONFIG={
method: 'HEAD',
mode: 'no-cors'
};
return new Promise((resolve)=> {
if(navigator.onLine===false){
resolve(false);
return;
}
fetch(REQUEST_URL, REQUEST_CONFIG)
.then((response)=> {
if(response.redirected){
resolve(true);
}
else if(response.status===404){
resolve(false);
}else{
resolve(false);
}})
.catch(()=> {
resolve(true);
});
});
}
cleanAdBlockDocument(){
const checkElm=document.querySelector("#qeCheckElm");
if(checkElm)
checkElm.remove();
}
allowDevToolsAccess(enable){
const body=document.body;
if(enable){
if(this._blockContextMenu){
body.removeEventListener('contextmenu', this._blockContextMenu, true);
this._blockContextMenu=null;
}
document.onkeydown=null;
}else{
this._blockContextMenu=(e)=> e.preventDefault();
body.addEventListener('contextmenu', this._blockContextMenu, true);
const ctrlShiftKey=(e, keyCode)=> e.ctrlKey&&e.shiftKey&&e.keyCode===keyCode.charCodeAt(0);
document.onkeydown=(e)=> {
if(e.keyCode===123 ||
ctrlShiftKey(e, "I") ||
ctrlShiftKey(e, "J") ||
ctrlShiftKey(e, "C") ||
(e.ctrlKey&&e.keyCode==="U".charCodeAt(0))){
return false;
}};}}
constructAdBlockModal(){
const d=window.qeProtectData;
if(!d||!d.enabled)
return;
if(document.getElementById("qeShieldModal"))
return;
let lang=(navigator.language||navigator.userLanguage||'').substring(0, 2).toLowerCase();
if(lang!=='th'){
lang='en';
}
const titleText=(lang==='th' ? d.titleText_th:d.titleText_en)||"AdBlock Detected!";
const descText=(lang==='th' ? d.descText_th:d.descText_en)||"Please disable AdBlock.";
const btnText=(lang==='th' ? d.btnText_th:d.btnText_en)||"I've disabled AdBlock";
const screenOneHelpText=(lang==='th' ? d.screenOneHelpText_th:d.screenOneHelpText_en)||"How do I disable my adblocker?";
const screenTwoHelpText=(lang==='th' ? d.screenTwoHelpText_th:d.screenTwoHelpText_en)||"Okay, I understand!";
const screenTwoTitle=(lang==='th' ? d.screenTwoTitle_th:d.screenTwoTitle_en)||"To fix on this site:";
const screenTwoSteps=(lang==='th' ? d.screenTwoSteps_th:d.screenTwoSteps_en)||[];
const stepsStr=screenTwoSteps.reduce((acc, curr)=> acc + `<li>${curr}</li>`, "");
const handIcon=`<svg width="80" height="80" viewBox="0 0 24 24" role="img" xmlns="http://www.w3.org/2000/svg"><title>Icon</title><path d="M7.775 0a1.8 1.8 0 0 0-1.273.527L.528 6.503A1.8 1.8 0 0 0 0 7.775v8.45c0 .478.19.936.528 1.274l5.974 5.974A1.8 1.8 0 0 0 7.775 24h8.45a1.8 1.8 0 0 0 1.273-.527l5.975-5.974A1.8 1.8 0 0 0 24 16.225v-8.45a1.8 1.8 0 0 0-.527-1.272L17.498.527A1.8 1.8 0 0 0 16.225 0zm4.427 3c1.02 0 .958 1.108.958 1.108v6.784s-.009.218.16.218c.188 0 .175-.226.175-.226l-.002-5.63s-.05-.986.959-.986c1.01 0 .97.983.97.983v7.621s.014.158.141.158c.127 0 .944-2.122.944-2.122s.451-1.497 2.576-1.1c.038.008-.167.688-.167.688l-2.283 6.556S15.69 20.7 11.714 20.7c-5.044 0-4.808-5.407-4.814-5.405V7.562s-.016-.99.897-.99c.858 0 .849.99.849.99l.007 3.583s-.004.172.167.172c.16 0 .141-.172.141-.172l.01-5.926s-.055-1.162.966-1.162c1.04 0 .983 1.142.983 1.142v5.611s-.005.204.152.204c.168 0 .154-.206.154-.206l.01-6.693S11.18 3 12.202 3Z"/></svg>`;
const closeIcon=`<svg width="24" height="24" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" style="cursor: pointer;"><path fill="currentColor" d="M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 393.664L407.936 353.6a38.4 38.4 0 1 0-54.336 54.336L457.664 512 353.6 616.064a38.4 38.4 0 1 0 54.336 54.336L512 566.336 616.064 670.4a38.4 38.4 0 1 0 54.336-54.336L566.336 512 670.4 407.936a38.4 38.4 0 1 0-54.336-54.336L512 457.664z"/></svg>`;
const alertModal=`
<div class="qemodal">
<div class="qemodal-wrapper">
<div class="qemodal-content">
${d.showCloseIcon ? `<div class="close-icon" id="closeIcon" style="position: absolute; top: 16px; right: 16px; width: 24px; height: 24px; color: ${d.helpTextColor||'#22099E'};">${closeIcon}</div>`:''}
<div class="screen-one" id="screenOne">
<div class="qemodal-head">
<div class="icon">${handIcon}</div>
<div class="heading">${titleText}</div>
</div>
<div class="qemodal-body">
<p>${descText}</p>
</div>
<div class="qemodal-footer">
<button type="button" class="btn">${btnText}</button>
<div class="help-text">${screenOneHelpText}</div>
</div>
</div>
<div class="screen-two" id="screenTwo">
<div class="qemodal-head">
<div class="heading">${screenTwoTitle}</div>
</div>
<div class="screen-two-grid">
<div class="grid-left">
<div class="extension-icon"></div>
</div>
<div class="grid-right">
<div class="qemodal-body">
<ul>${stepsStr}</ul>
</div>
</div>
</div>
<div class="abdmodal-footer">
<div class="help-text">${screenTwoHelpText}</div>
</div>
</div>
</div>
</div>
</div>
`;
const modalWrap=document.createElement("div");
modalWrap.setAttribute("id", "qeShieldModal");
modalWrap.classList.add("qe-shield-wrap");
modalWrap.innerHTML=alertModal;
modalWrap.style.setProperty("--popup-background", d.popupBackgroundColor||"#ffffff");
modalWrap.style.setProperty("--popup-backdrop-color", d.popupBackdropColor||"rgba(15, 23, 42, 0.7)");
modalWrap.style.setProperty("--icon-color", d.iconColor||"#dc2626");
modalWrap.style.setProperty("--btn-color", d.btnColor||"#ffffff");
modalWrap.style.setProperty("--btn-background-color", d.btnBackgroundColor||"#dc2626");
modalWrap.style.setProperty("--title-color", d.titleColor||"#0f172a");
modalWrap.style.setProperty("--desc-color", d.descColor||"#475569");
modalWrap.style.setProperty("--help-text-color", d.helpTextColor||"#dc2626");
modalWrap.style.setProperty("--steps-color", d.screenTwoStepsColor||"#475569");
document.body.appendChild(modalWrap);
if(d.secureMode){
this.allowDevToolsAccess(false);
}
const modal=modalWrap.querySelector(".qemodal");
const modalContent=modalWrap.querySelector(".qemodal .qemodal-content");
const maxW=d.popupMaxWidth ? `${d.popupMaxWidth}px`:"500px";
const borderR=d.popupBorderRadius ? `${d.popupBorderRadius}px`:"16px";
if(modalContent){
modalContent.style.setProperty("border-radius", borderR, "important");
}
setTimeout(()=> {
if(modal&&modalContent){
modal.style.cssText="z-index: 99999; opacity: 1; visibility: visible;";
modalContent.style.cssText=`transform: scale(1); max-width: ${maxW}; border-radius: ${borderR};`;
document.body.style.overflowY="hidden";
}}, 500);
modalWrap.addEventListener("click", (e)=> {
const target=e.target;
if(target.classList.contains("help-text")){
modalWrap.classList.toggle("screen-two-active");
}
if(target.classList.contains("btn")){
location.reload();
}
if(target.classList.contains("close-icon")||target.closest(".close-icon")){
modal.style.cssText="opacity: 0; visibility: hidden;";
modalContent.style.cssText=`transform: scale(0); max-width: ${maxW};`;
document.body.style.overflowY="initial";
if(d.secureMode){
this.allowDevToolsAccess(true);
}}
});
}
initFbIab(){
const d=window.qeFbData;
if(!d||!d.enabled)
return;
this.onReady(()=> {
requestAnimationFrame(()=> {
var _a;
const ua=navigator.userAgent||navigator.vendor||window.opera;
if(!/FBAN|FBAV|FB_IAB|Messenger/i.test(ua))
return;
const overlay=document.createElement('div');
overlay.id='fb-iab-paywall-overlay';
overlay.style.touchAction='none';
const banner=document.createElement('div');
banner.id='fb-iab-paywall-banner';
if(d.bg_color)
banner.style.setProperty('--fb-iab-bg', d.bg_color);
if(d.text_color)
banner.style.setProperty('--fb-iab-text', d.text_color);
if(d.accent_color)
banner.style.setProperty('--fb-iab-accent', d.accent_color);
const currentUrl=window.location.href;
const intentUrl=/android/i.test(ua)
? `intent://${currentUrl.replace(/^https?:\/\//, '')}#Intent;scheme=https;package=com.android.chrome;end`
: currentUrl;
banner.innerHTML=`
<button id="fb-iab-close-btn" aria-label="Close">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</button>
<div class="fb-iab-icon-container">
<svg class="fb-iab-icon" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="8" x2="12" y2="12"></line>
<line x1="12" y1="16" x2="12.01" y2="16"></line>
</svg>
</div>
<h3 id="fb-iab-head"></h3>
<p id="fb-iab-body"></p>
<a id="fb-iab-link" target="_blank" rel="noopener noreferrer">
<button id="fb-iab-btn" class="main-btn"></button>
</a>
<div class="fb-iab-footer-note">เพื่อการแสดงผลและใช้งานที่สมบูรณ์ที่สุด</div>
`;
banner.querySelector('#fb-iab-head').textContent=d.head;
banner.querySelector('#fb-iab-body').textContent=d.body;
banner.querySelector('#fb-iab-btn').textContent=d.btn;
banner.querySelector('#fb-iab-link').href=intentUrl;
document.body.append(overlay, banner);
document.body.style.overflow='hidden';
(_a=document.getElementById('fb-iab-close-btn'))===null||_a===void 0 ? void 0:_a.addEventListener('click', ()=> {
banner.remove();
overlay.remove();
document.body.style.overflow='';
});
});
});
}
initGoogleForm(){
const d=window.qeGformData;
if(!d||!d.enabled)
return;
this.onReady(()=> {
document.querySelectorAll('a[data-t^="gf_"]').forEach((btn)=> {
const targetId=btn.getAttribute('data-t');
if(!targetId)
return;
const targetDiv=document.getElementById(targetId);
if(targetDiv){
const parent=btn.closest('.wp-block-buttons')||btn.closest('.wp-block-button')||btn.parentElement;
if(parent&&parent.parentNode){
parent.parentNode.insertBefore(targetDiv, parent.nextSibling);
}
btn.addEventListener('click', function (e){
e.preventDefault();
targetDiv.classList.toggle('active');
const isActive=targetDiv.classList.contains('active');
if(isActive){
if(!this.hasAttribute('data-original')){
this.setAttribute('data-original', this.innerHTML);
}
this.textContent=d.hide;
}else{
const originalHtml=this.getAttribute('data-original');
if(originalHtml){
this.innerHTML=originalHtml;
}else{
this.textContent=d.show;
}}
});
}});
});
}}
new QuizEducateToolkit();