// Main Live Chat const mainLiveChatDiv = document.createElement('div') mainLiveChatDiv.className = "mainLiveChatDiv" let currentWhatsappScript = document.currentScript; let domainName = currentWhatsappScript.getAttribute("src").split('/MfIatXueATJr')[0] // For the Shadow Root const bodyElement = mainLiveChatDiv.attachShadow({ mode: 'open' }); let appearance = mainLiveChatDiv.getAttribute('appearance'); // Will Add the Styles file. var link = document.createElement("link"); link.rel = "stylesheet"; link.type = "text/css"; link.href = `${domainName}/build/assets/libs/whatsapp/whatsapp.css`; // will add the Bootstrap Styles var BootstrapStyles = document.createElement("link"); BootstrapStyles.rel = "stylesheet"; BootstrapStyles.type = "text/css"; BootstrapStyles.href = `${domainName}/build/assets/libs/bootstrap/css/bootstrap.min.css`; bodyElement.appendChild(BootstrapStyles); link.onload = function () { var nowDragginginprogress = 'notinprocess'; // popupicon draggable code start function dragElement(elmnt, restrictHorizontal = false) { var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; elmnt.style.position = "fixed"; // Ensure draggable icon is absolute elmnt.onmousedown = dragMouseDown; function dragMouseDown(e) { e = e || window.event; e.preventDefault(); pos3 = e.clientX; pos4 = e.clientY; nowDragginginprogress = 'notinprocess'; document.onmouseup = closeDragElement; document.onmousemove = elementDrag; } function elementDrag(e) { nowDragginginprogress = 'inprogress'; e = e || window.event; e.preventDefault(); pos1 = pos3 - e.clientX; pos2 = pos4 - e.clientY; pos3 = e.clientX; pos4 = e.clientY; if (restrictHorizontal) { elmnt.style.setProperty('inset-block-start', `${e.clientY}px`); } else { elmnt.style.top = (elmnt.offsetTop - pos2) + "px"; elmnt.style.left = (elmnt.offsetLeft - pos1) + "px"; } } function closeDragElement() { document.onmouseup = null; document.onmousemove = null; } } const response = async (postData) => { const res = await fetch(`${domainName}/api/getAppearanceData`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json, text/javascript, */*; q=0.01', }, body: JSON.stringify(postData), }); if (!res.ok) { throw new Error(`HTTP error! Status: ${res.status}`); } const final = await res.json(); return final; }; (async () => { try { const data = await response(); if(data.error){ return ; } let customIcon = data.wtsCustomIcon; const color = data.wtsBgColorSolid != null ? data.wtsBgColorSolid : data.wtsBgColorGradient; const isGradient = color != null ? color.startsWith('linear-gradient') : null; const match = color != null ? color.match(/rgb\([^)]+\)/) : null; const firstRgb = match ? match[0] : null; const startTextClr = data.startChatBtnClr; let whatsappNumber = data.phoneNumber != null ? data.phoneNumber : '1234567892'; function getWhatsAppLink(whatsappNumber) { if (window.innerWidth < 992) { return `whatsapp://send?phone=${whatsappNumber}`; } else { return `https://wa.me/${whatsappNumber}`; } } const chatDiv = document.createElement('div'); chatDiv.className = 'chat-container' chatDiv.innerHTML = `

Hello, Welcome !

I have reviewed the website and have some questions I would like to address.
Powered by

SPRUKO

`; bodyElement.appendChild(chatDiv); const values = firstRgb?.match(/\d+/g).join(', '); if(values != null){ bodyElement.querySelector('.chat-container').style.setProperty('--border-color',values) bodyElement.querySelector('.chat-container').style.setProperty('--primary-rgb',values) }else{ bodyElement.querySelector('.chat-container').style.setProperty('--border-color','28, 176, 50') } const iconDiv = document.createElement('div') // iconDiv.href = `javascript:void(0);` iconDiv.id = "icon" // iconDiv.target="_blank" if(data.icon_layout_image == "layout-1.png"){ bodyElement.querySelector('.chat-container').classList.remove('verticalLayout'); iconDiv.className = "social-wp-hr-icon chatPopup" if (isGradient) { iconDiv.style.backgroundImage = color; } else { iconDiv.style.backgroundColor = color; } iconDiv.innerHTML = ` ${customIcon != null ? `icon` : ` `} ${data.icon_lable} ` bodyElement.querySelector('.chat-container').style.border ='3px solid ' + firstRgb; bodyElement.querySelector('.startChatBtn').style.background = color; } else if(data.icon_layout_image == "layout-2.png"){ bodyElement.querySelector('.chat-container').classList.add('verticalLayout'); iconDiv.className = "social-wp-vr-icon chatPopup" if (isGradient) { iconDiv.style.backgroundImage = color; } else { iconDiv.style.backgroundColor = color; } iconDiv.innerHTML=` ${data.icon_lable} ${customIcon != null ? `icon`:` `} ` bodyElement.querySelector('.startChatBtn').style.background = color; bodyElement.querySelector('.chat-container').style.border ='3px solid ' + firstRgb; }else if(data.icon_layout_image == "layout-3.png"){ bodyElement.querySelector('.chat-container').classList.remove('verticalLayout'); iconDiv.className = "social-wp-icon chat-icon chatPopup" iconDiv.innerHTML = ` icon ${data.icon_lable} ` bodyElement.querySelector('.chat-container').style.border = '3px solid rgba(var(--primary-rgb), 0.8)'; bodyElement.querySelector('.startChatBtn').style.background = 'rgb(56 167 120)'; }else{ bodyElement.querySelector('.chat-container').classList.remove('verticalLayout'); iconDiv.className = "social-wp-sm-icon chat-icon chatPopup" iconDiv.innerHTML = ` icon ${data.icon_lable} ` bodyElement.querySelector('.chat-container').style.border = '3px solid rgba(var(--primary-rgb), 0.8)'; bodyElement.querySelector('.startChatBtn').style.background = 'rgb(56 167 120)'; } bodyElement.appendChild(iconDiv); if (isGradient) { if(color != null ){ bodyElement.querySelector('.startChatBtn').style.backgroundImage = color; bodyElement.querySelector('.chat-container').style.border = '3px solid ' + firstRgb; } // else{ // bodyElement.querySelector('.startChatBtn').style.backgroundImage = 'ragb(28, 176, 50)'; // bodyElement.querySelector('.chat-container').style.border = '3px solid rgb(28, 176, 50)'; // } } else { if(color != null){ bodyElement.querySelector('.startChatBtn').style.backgroundImage = color; bodyElement.querySelector('.chat-container').style.border = '3px solid '+ data.wtsBgColorSolid; } // else{ // bodyElement.querySelector('.startChatBtn').style.backgroundImage = 'rgb(28, 176, 50)'; // bodyElement.querySelector('.chat-container').style.border = '3px solid rbg(28, 176, 50)'; // } } if(data.icon_draggable == 'on'){ if(data.icon_layout_image == 'layout-2.png'){ dragElement(iconDiv, true); } else{ dragElement(iconDiv); } }else{ iconDiv.style.position = "fixed" } bodyElement.querySelector('.chatPopup').onclick =()=>{ if (nowDragginginprogress != 'inprogress'){ bodyElement.querySelector('.whatsappLink').addEventListener('click', (event) => { event.preventDefault(); // prevent default link behavior window.open(getWhatsAppLink(whatsappNumber), '_blank'); });; } } // position if it is left if(data.icon_position == "left"){ bodyElement.querySelector('.chatPopup').classList.add('rtl'); bodyElement.querySelector('.chat-container').classList.add('rtl'); bodyElement.querySelector('.chat-icon-text').classList.add('rtl'); mainLiveChatDiv.setAttribute('appearance', 'left'); appearance = "left"; } else{ mainLiveChatDiv.setAttribute('appearance', 'right'); appearance = "right"; } window.addEventListener('resize', function() { const whatsappLink = bodyElement.querySelector('#icon'); if (whatsappLink) { whatsappLink.setAttribute('href', getWhatsAppLink(data.phoneNumber)); whatsappLink.setAttribute('target', '_blank'); } }) //chat-popup// function toggleChatContainer() { const chatContainer = bodyElement.querySelector('.chat-container'); const mainIcon = bodyElement.querySelector('.main-icon'); const isOpen = chatContainer.classList.toggle('open'); } const chatPopupButton = bodyElement.querySelector('.chatPopup'); chatPopupButton.addEventListener('click', toggleChatContainer); } catch (error) { console.error('Error fetching data:', error); } })(); // To getting the Country Name function getCountryName(countryCode) { const countryMapping = { "BD": "Bangladesh", "BE": "Belgium", "BF": "Burkina Faso", "BG": "Bulgaria", "BA": "Bosnia and Herzegovina", "BB": "Barbados", "WF": "Wallis and Futuna", "BL": "Saint Barthelemy", "BM": "Bermuda", "BN": "Brunei", "BO": "Bolivia", "BH": "Bahrain", "BI": "Burundi", "BJ": "Benin", "BT": "Bhutan", "JM": "Jamaica", "BV": "Bouvet Island", "BW": "Botswana", "WS": "Samoa", "BQ": "Bonaire, Saint Eustatius and Saba ", "BR": "Brazil", "BS": "Bahamas", "JE": "Jersey", "BY": "Belarus", "BZ": "Belize", "RU": "Russia", "RW": "Rwanda", "RS": "Serbia", "TL": "East Timor", "RE": "Reunion", "TM": "Turkmenistan", "TJ": "Tajikistan", "RO": "Romania", "TK": "Tokelau", "GW": "Guinea-Bissau", "GU": "Guam", "GT": "Guatemala", "GS": "South Georgia and the South Sandwich Islands", "GR": "Greece", "GQ": "Equatorial Guinea", "GP": "Guadeloupe", "JP": "Japan", "GY": "Guyana", "GG": "Guernsey", "GF": "French Guiana", "GE": "Georgia", "GD": "Grenada", "GB": "United Kingdom", "GA": "Gabon", "SV": "El Salvador", "GN": "Guinea", "GM": "Gambia", "GL": "Greenland", "GI": "Gibraltar", "GH": "Ghana", "OM": "Oman", "TN": "Tunisia", "JO": "Jordan", "HR": "Croatia", "HT": "Haiti", "HU": "Hungary", "HK": "Hong Kong", "HN": "Honduras", "HM": "Heard Island and McDonald Islands", "VE": "Venezuela", "PR": "Puerto Rico", "PS": "Palestinian Territory", "PW": "Palau", "PT": "Portugal", "SJ": "Svalbard and Jan Mayen", "PY": "Paraguay", "IQ": "Iraq", "PA": "Panama", "PF": "French Polynesia", "PG": "Papua New Guinea", "PE": "Peru", "PK": "Pakistan", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PM": "Saint Pierre and Miquelon", "ZM": "Zambia", "EH": "Western Sahara", "EE": "Estonia", "EG": "Egypt", "ZA": "South Africa", "EC": "Ecuador", "IT": "Italy", "VN": "Vietnam", "SB": "Solomon Islands", "ET": "Ethiopia", "SO": "Somalia", "ZW": "Zimbabwe", "SA": "Saudi Arabia", "ES": "Spain", "ER": "Eritrea", "ME": "Montenegro", "MD": "Moldova", "MG": "Madagascar", "MF": "Saint Martin", "MA": "Morocco", "MC": "Monaco", "UZ": "Uzbekistan", "MM": "Myanmar", "ML": "Mali", "MO": "Macao", "MN": "Mongolia", "MH": "Marshall Islands", "MK": "Macedonia", "MU": "Mauritius", "MT": "Malta", "MW": "Malawi", "MV": "Maldives", "MQ": "Martinique", "MP": "Northern Mariana Islands", "MS": "Montserrat", "MR": "Mauritania", "IM": "Isle of Man", "UG": "Uganda", "TZ": "Tanzania", "MY": "Malaysia", "MX": "Mexico", "IL": "Israel", "FR": "France", "IO": "British Indian Ocean Territory", "SH": "Saint Helena", "FI": "Finland", "FJ": "Fiji", "FK": "Falkland Islands", "FM": "Micronesia", "FO": "Faroe Islands", "NI": "Nicaragua", "NL": "Netherlands", "NO": "Norway", "NA": "Namibia", "VU": "Vanuatu", "NC": "New Caledonia", "NE": "Niger", "NF": "Norfolk Island", "NG": "Nigeria", "NZ": "New Zealand", "NP": "Nepal", "NR": "Nauru", "NU": "Niue", "CK": "Cook Islands", "XK": "Kosovo", "CI": "Ivory Coast", "CH": "Switzerland", "CO": "Colombia", "CN": "China", "CM": "Cameroon", "CL": "Chile", "CC": "Cocos Islands", "CA": "Canada", "CG": "Republic of the Congo", "CF": "Central African Republic", "CD": "Democratic Republic of the Congo", "CZ": "Czech Republic", "CY": "Cyprus", "CX": "Christmas Island", "CR": "Costa Rica", "CW": "Curacao", "CV": "Cape Verde", "CU": "Cuba", "SZ": "Swaziland", "SY": "Syria", "SX": "Sint Maarten", "KG": "Kyrgyzstan", "KE": "Kenya", "SS": "South Sudan", "SR": "Suriname", "KI": "Kiribati", "KH": "Cambodia", "KN": "Saint Kitts and Nevis", "KM": "Comoros", "ST": "Sao Tome and Principe", "SK": "Slovakia", "KR": "South Korea", "SI": "Slovenia", "KP": "North Korea", "KW": "Kuwait", "SN": "Senegal", "SM": "San Marino", "SL": "Sierra Leone", "SC": "Seychelles", "KZ": "Kazakhstan", "KY": "Cayman Islands", "SG": "Singapore", "SE": "Sweden", "SD": "Sudan", "DO": "Dominican Republic", "DM": "Dominica", "DJ": "Djibouti", "DK": "Denmark", "VG": "British Virgin Islands", "DE": "Germany", "YE": "Yemen", "DZ": "Algeria", "US": "United States", "UY": "Uruguay", "YT": "Mayotte", "UM": "United States Minor Outlying Islands", "LB": "Lebanon", "LC": "Saint Lucia", "LA": "Laos", "TV": "Tuvalu", "TW": "Taiwan", "TT": "Trinidad and Tobago", "TR": "Turkey", "LK": "Sri Lanka", "LI": "Liechtenstein", "LV": "Latvia", "TO": "Tonga", "LT": "Lithuania", "LU": "Luxembourg", "LR": "Liberia", "LS": "Lesotho", "TH": "Thailand", "TF": "French Southern Territories", "TG": "Togo", "TD": "Chad", "TC": "Turks and Caicos Islands", "LY": "Libya", "VA": "Vatican", "VC": "Saint Vincent and the Grenadines", "AE": "United Arab Emirates", "AD": "Andorra", "AG": "Antigua and Barbuda", "AF": "Afghanistan", "AI": "Anguilla", "VI": "U.S. Virgin Islands", "IS": "Iceland", "IR": "Iran", "AM": "Armenia", "AL": "Albania", "AO": "Angola", "AQ": "Antarctica", "AS": "American Samoa", "AR": "Argentina", "AU": "Australia", "AT": "Austria", "AW": "Aruba", "IN": "India", "AX": "Aland Islands", "AZ": "Azerbaijan", "IE": "Ireland", "ID": "Indonesia", "UA": "Ukraine", "QA": "Qatar", "MZ": "Mozambique" }; return countryMapping[countryCode?.toUpperCase()] || 'Unknown Country'; } function fetchBrowserDetails() { const userAgent = navigator.userAgent; let browserName = "Unknown"; if (userAgent.match(/Firefox\/\d+/)) { browserName = "Firefox"; } else if (userAgent.match(/Edg\/\d+/)) { browserName = "Microsoft Edge"; } else if (userAgent.match(/Chrome\/\d+/)) { browserName = "Chrome"; } else if (userAgent.match(/Safari\/\d+/) && !userAgent.match(/Chrome\/\d+/)) { browserName = "Safari"; } else if (userAgent.match(/MSIE \d+/) || userAgent.match(/Trident.*rv:\d+/)) { browserName = "Internet Explorer"; } return browserName; } async function postData(postdata){ const url = `${domainName}/api/livevisitors`; let data = await fetch(url, { method: "POST", headers: { 'Content-Type': 'application/json', 'Accept': 'application/json, text/javascript, */*; q=0.01', }, body: JSON.stringify(postdata), }).then(response => response.text()) return data; } if (!localStorage.getItem("LiveChatVisitor") ) { fetch('https://ipinfo.io/json') .then(response => response.json()) .then(data => { let custipdata; let returndata; custipdata = { "ipaddress": data.ip, "countrycode": data.country, "country": getCountryName(data.country), "loginurl": domainName, "browserinfo": fetchBrowserDetails(), }; returndata = postData(custipdata); returndata.then((resData) => { let updatedData = JSON.parse(resData); localStorage.setItem("LiveChatVisitor", updatedData?.liveVisitors?.visitor_unique_id); }); }) .catch(error => console.error('Error:', error)); } else if (localStorage.getItem("LiveChatVisitor")) { fetch('https://ipinfo.io/json') .then(response => response.json()) .then(data => { let custipdata let returndata custipdata = { "visitorId": localStorage.getItem("LiveChatVisitor"), "ipaddress": data.ip, "countrycode": data.country, "country": getCountryName(data.country), "loginurl": location.href, "browserinfo": fetchBrowserDetails(), } returndata = postData(custipdata); returndata.then((resData) => { let updatedData = JSON.parse(resData); localStorage.setItem("LiveChatVisitor", updatedData?.liveVisitors?.visitor_unique_id); }); }) .catch(error => { console.error('Error fetching IP details:', error); }); } } bodyElement.appendChild(link); // To add the Main Live Chat Div document.body.appendChild(mainLiveChatDiv);