"; for(var i=0; i <= data["result"].length-1; i++ ){ var checked = (data["result"][i]["subscribed"] == "yes")? "checked" : ""; html += ""; } $("#channelsSubsChans").append(html); $("#channelsSubsForm button").removeAttr("disabled").text("Save Subscriptions"); }); } if("" == "1"){ $("#channelsSubsForm button").removeAttr("disabled").text("Save Subscriptions"); } } function smpush_endpoint_refresh(oldtoken, newtoken) { var devicetype = smpush_browser(); var req = new XMLHttpRequest(); req.onreadystatechange = function() { if (req.readyState == XMLHttpRequest.DONE) { smart_push_smio_inner_setCookie("smart_push_device_token", newtoken, 30); if(window.opener){ window.opener.postMessage(["subscription", newtoken, devicetype], "*"); } } }; req.open("POST", "https://smartiolabs.com/projects/push/api/refresh_device/"); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send("appid=105982770&device_token="+oldtoken+"&device_type="+devicetype+"&refresh_device_token="+newtoken); return false; } function smpush_endpoint_subscribe(subscriptionId) { if(subscriptionId == ""){ smpushDestroyOverlay(); return false; } var firstSubscription = false; if(smart_push_smio_getCookie("smart_push_device_token") == ""){ firstSubscription = true; } smart_push_smio_inner_setCookie("smart_push_device_token", subscriptionId, 30); if(window.opener){ window.opener.postMessage(["subscription", subscriptionId, devicetype], "*"); } smpush_success_got_token(subscriptionId); if("" == "1"){ navigator.serviceWorker.ready.then(function(registration) { registration.showNotification("", { icon: "https://smartiolabs.com/projects/push/media/settings/9d485408c8e928ef9681d294511913fc.png", body: "", tag: "", data: {"target": ""} }); }); self.addEventListener("notificationclick", function (event) { event.notification.close(); event.waitUntil(clients.matchAll({ type: "window" }).then(function (clientList) { for (var i = 0; i < clientList.length; i++) { var client = clientList[i]; if (client.url === event.notification.data.target && "focus" in client) { return client.focus(); } } if (clients.openWindow) { return clients.openWindow(event.notification.data.target); } })); }); } if("" == "0" && ("noform" == "noform" || "" == "nativeoptin" || "" == "icon" || "" == "tooltip")){ document.getElementById("smpushSubmitSignupForm").click(); } else if("" == "1" && smpush_empty_form()){ document.getElementById("smpushSubmitSignupForm").click(); } else if("" == "1" && ! firstSubscription){ smpushLoadSubscription(); } } function smpush_empty_form(subscriptionId) { if("" == "0" && $("#smpush_embed_form input[type='text']").length == 0 && $("#smpush_embed_form input[type='checkbox']").length == 0 && "" == "0"){ return true; } return false; } function smpush_endpoint_unsubscribe(subscriptionId) { var http = new XMLHttpRequest(); var url = "https://smartiolabs.com/projects/push/api/save_device/"; var params = "device_token="+subscriptionId+"&device_type="+devicetype+"&active=0&appid=105982770"; http.open("POST", url, true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.send(params); http.onreadystatechange = function() { if (http.status == 200) { smpushCloseForm(); } else{ smpushDebugWriter(http.status); smpushDebugWriter(http.readyState); smpushDebugWriter(http.responseText); smpushCloseForm(); } } } function smpush_bootstrap_init(){ if(document.getElementById("smart_push_device_type")){ document.getElementById("smart_push_device_type").value = devicetype; } smpushOldDesktopPush(); let hash = location.hash.slice(1); if(hash != "" && "1" == "1"){ smart_push_smio_inner_setCookie("smart_push_device_token", hash, 30); } if("" == "1"){ smpushDebugWriter("user GPS location status", ""); smpush_get_gps(); } if("" == "0" && "1" == "1"){ smpushUpdateFormField("smart_push_device_token", smart_push_smio_getCookie("smart_push_device_token")); smpushUpdateFormField("smart_push_device_type", smpush_browser()); smpush_success_got_token(smart_push_smio_getCookie("smart_push_device_token")); smpushLoadSubscription(); return false; } if(smpushCheckNewsletterParam()){ smpushLoadSubscription(); return false; } if("" == "0" && smart_push_smio_getCookie("smart_push_device_token") != ""){ smpushUpdateFormField("smart_push_device_token", smart_push_smio_getCookie("smart_push_device_token")); smpushUpdateFormField("smart_push_device_type", smpush_browser()); smpush_success_got_token(smart_push_smio_getCookie("smart_push_device_token")); return true; } var pushSupported = false; if("safari" in window && "pushNotification" in window.safari){ pushSupported = true; } if (typeof(ServiceWorkerRegistration) != "undefined" && ("showNotification" in ServiceWorkerRegistration.prototype) && ("PushManager" in window)) { pushSupported = true; } if(! pushSupported){ smpushDebugWriter("Browser not support push notification"); return false; } if("1" == "1"){ return true; } else{ return false; } } function smpush_get_gps(){ if (! navigator.geolocation) { smpushDebugWriter("Geolocation is not supported for this Browser/OS."); return; } smpushDebugWriter("Trying get user GPS location."); var geoSuccess = function(startPos) { smpushDebugWriter("Successful got location", startPos.coords); if(document.getElementById("smpush_latitude") && smart_push_smio_getCookie("smart_push_geo_gps") == ""){ document.getElementById("smpush_latitude").value = startPos.coords.latitude; document.getElementById("smpush_longitude").value = startPos.coords.longitude; smart_push_smio_inner_setCookie("smart_push_geo_gps", "true", (1/24)); if(smart_push_smio_getCookie("smart_push_device_token") != "" && document.getElementById("smpushSubmitSignupForm")){ document.getElementById("smpushRefreshGPS").value = 1; smpush_save_form(); } } }; var geoError = function(error) { smpushDebugWriter("Error occurred. Error code: " + error.code); /*0: unknown error, 1: permission denied, 2: position unavailable (error response from location provider), 3: timed out*/ }; navigator.geolocation.getCurrentPosition(geoSuccess); } function smpush_browser() { if (navigator.userAgent.indexOf(' OPR/') >= 0) { return "opera"; } if (navigator.userAgent.indexOf('Edge') >= 0) { return "edge"; } if (navigator.userAgent.match(/chrome/i)) { return "chrome"; } if (navigator.userAgent.match(/SamsungBrowser/i)) { return "samsung"; } if (navigator.userAgent.match(/firefox/i)) { return "firefox"; } if ("safari" in window) { return "safari"; } return ""; } function spns_test_browser(){ if("safari" in window && "pushNotification" in window.safari){ return true; } if (typeof(ServiceWorkerRegistration) != "undefined" && ("showNotification" in ServiceWorkerRegistration.prototype)) { return true; } if(Notification.permission === "denied"){ return false; } return false; } function smpushSaveTag(tagname, value) { var subscriptionId = smart_push_smio_getCookie("smart_push_device_token"); var smpushDeviceType = smpush_browser(); if(subscriptionId == ""){smpushDebugWriter("push service is not activated yet");return false;} if(smpushDeviceType == ""){smpushDebugWriter("push service is not activated yet");return false;} var params = "?device_token="+subscriptionId; params += "&device_type="+smpushDeviceType; params += "&active=1"; params += "&smart_token_version=2"; params += "&appid=105982770"; params += "&"+tagname+"="+value; var url = "https://smartiolabs.com/projects/push/api/save_device/" + params; smpush_jsonp(url, function(data) { return true; }); } function smpushAddToSegment(segment) { var subscriptionId = smart_push_smio_getCookie("smart_push_device_token"); var subscribedSegments = smart_push_smio_getCookie("smart_push_addedto_segments"); var smpushDeviceType = smpush_browser(); var storeSegment = segment.replace(",", " "); smpushDebugWriter("Adding the subscriber to segment"); smpushDebugWriter(subscriptionId); smpushDebugWriter(smpushDeviceType); if(subscriptionId == ""){smpushDebugWriter("push service is not activated yet");return false;} if(smpushDeviceType == ""){smpushDebugWriter("push service is not activated yet");return false;} if(subscribedSegments != ""){ subscribedSegments = subscribedSegments.split(","); if(subscribedSegments.includes(storeSegment)){ smpushDebugWriter("already subscribed in this segment"); return false; } } else { subscribedSegments = []; } var params = "?device_token="+subscriptionId; params += "&device_type="+smpushDeviceType; params += "&active=1"; params += "&smart_token_version=2"; params += "&appid=105982770"; params += "&channel_title="+segment; var url = "https://smartiolabs.com/projects/push/api/channel_subscribe/" + params; smpush_jsonp(url, function(data) { if(data.respond > 0){ smpushDebugWriter("Added successfully to segment: " + segment); subscribedSegments.push(storeSegment); smart_push_smio_inner_setCookie("smart_push_addedto_segments", subscribedSegments.join(","), 365); } return true; }); } function smpushUpdateFormField(name, value) { if(document.getElementById(name)){ document.getElementById(name).value = value; } } function smpushUrlB64ToUint8Array(base64String) { const padding = "=".repeat((4 - base64String.length % 4) % 4); const base64 = (base64String + padding) .replace(/\-/g, "+") .replace(/_/g, "/"); const rawData = window.atob(base64); const outputArray = new Uint8Array(rawData.length); for (let i = 0; i < rawData.length; ++i) { outputArray[i] = rawData.charCodeAt(i); } return outputArray; } function smart_push_smio_inner_setCookie(cname, cvalue, exdays) { if(parseInt(exdays) == -1 || exdays == "-1"){ var expires = "expires=Thu, 01 Jan 1970 00:00:01 GMT"; } else{ var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toUTCString(); } if("" == "0" && "1" == "1"){ document.cookie = cname + "=" + cvalue + "; " + expires + "; domain=; path=; SameSite=None; Secure"; } else{ document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/; SameSite=None; Secure"; } if(document.getElementById(cname)){ document.getElementById(cname).value = cvalue; } } function smpushIsBase64(str) { try { return btoa(atob(str)) == str; } catch (err) { return false; } } function smpush_jsonp(url, callback) { var callbackName = "jsonp_callback_" + Math.round(100000 * Math.random()); window[callbackName] = function(data) { delete window[callbackName]; document.body.removeChild(script); callback(data); }; var script = document.createElement("script"); script.src = url + (url.indexOf("?") >= 0 ? "&" : "?") + "callback=" + callbackName; document.body.appendChild(script); } function smart_push_smio_getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(";"); for(var i=0; iSubscription terminated successfully
"); setTimeout(function(){ smpushCloseForm(); }, 3000); }, "json"); } function smpushCheckNewsletterParam(){ var url = new URL(window.location.href); var email = url.searchParams.get("email"); if(! email || email == ""){ return false; } else{ return email; } } function smart_push_destroy_popup(){ if(smart_push_smio_getCookie("smart_push_device_token") != "" && document.getElementById("smart_push_gdpr_icon")){ document.getElementById("smart_push_gdpr_icon").removeEventListener("click", smpush_gdpr_event); smpush_gdpr_event = function() { smart_push_open_account_page(); }; document.getElementById("smart_push_gdpr_icon").addEventListener("click", smpush_gdpr_event); if(typeof document.querySelector("#smart_push_gdpr_icon")._smio_tippy != "undefined"){ document.querySelector("#smart_push_gdpr_icon")._smio_tippy.set({content: ""}); } } else if(smart_push_smio_getCookie("smart_push_device_token") == "" && document.getElementById("smart_push_gdpr_icon")){ document.getElementById("smart_push_gdpr_icon").removeEventListener("click", smpush_gdpr_event); smpush_gdpr_event = function() { smart_push_build_popup(); }; document.getElementById("smart_push_gdpr_icon").addEventListener("click", smpush_gdpr_event); if(typeof document.querySelector("#smart_push_gdpr_icon")._smio_tippy != "undefined"){ document.querySelector("#smart_push_gdpr_icon")._smio_tippy.set({content: "Subscribe with us"}); } } if(smart_push_smio_getCookie("smart_push_device_token") == "" && "" == "1"){ document.getElementById("smart_push_smio_note").innerHTML = ""; return; } if(document.getElementById("smart_push_smio_overlay")){ document.getElementById("smart_push_smio_overlay").style.opacity = "0"; document.getElementById("smart_push_smio_overlay").style.display = "none"; } if(document.getElementById("smart_push_smio_window")){ document.getElementById("smart_push_smio_window").style.display = "none"; } smart_push_destroy_arrows(); } function smart_push_destroy_arrows(){ if(document.getElementById("smart_push_arrow_top")){ document.getElementById("smart_push_arrow_top").style.display = "none"; } if(document.getElementById("smart_push_arrow_left")){ document.getElementById("smart_push_arrow_left").style.display = "none"; } if(document.getElementById("smart_push_arrow_bottom")){ document.getElementById("smart_push_arrow_bottom").style.display = "none"; } } function smpushLoadSubscription(){ if(smpushCheckNewsletterParam()){ var subscriptionId = smpushCheckNewsletterParam(); var subs_device_type = "email"; } else if(smart_push_smio_getCookie("smart_push_device_token") == ""){ return false; } else{ var subscriptionId = smart_push_smio_getCookie("smart_push_device_token"); var subs_device_type = smpush_browser(); } document.getElementById("smio_overlay").style.display = "block"; $.ajax({ method: "POST", url: "https://smartiolabs.com/projects/push/api/get_subscription/", dataType: "json", data: { device_token: subscriptionId, device_type: subs_device_type, appid: 105982770 } }) .fail(function(jqXHR, textStatus) { smpushDebugWriter(jqXHR); smpushDebugWriter(textStatus); }) .done(function(data) { if(data["respond"] == 0){ document.getElementById("smio_overlay").style.display = "none"; return; } $("#smpush_form_deletesubsbtn").show(); if(document.getElementById("smpush_form_deletesubsbtn")){ document.getElementById("smpush_form_deletesubsbtn").addEventListener("click", function(){ if(confirm("Are you sure that you want to delete your subscription and account permanently ?")){ smpushDeleteSubscription(); } }); } if($("input[name='newsletteremail']").length){ $("input[name='newsletteremail']").val(data["result"]["email"]); } if(data["result"]["fbmsn_uid"]){ $("input[name='fbmsn_uid']").val(data["result"]["fbmsn_uid"]); } $("input[name*='addinfo[']").each(function(index) { var fieldkey = $(this).attr("name").replace("addinfo[","").replace("]",""); var fieldvalue = data["result"][fieldkey]; $(this).val(fieldvalue); }); $("input[name='channels[]']").each(function(index) { if($.inArray($(this).val(), data["result"]["chids"]) != -1){ $(this).attr("checked","checked"); } }); document.getElementById("smio_overlay").style.display = "none"; }); }