// =========[ DEFINING SCRIPT ]=========
run_page();
function run_page() {
let offer_path = window.location.pathname;
let url_arr = offer_path.split("/");
let last_url = url_arr[url_arr.length - 1];
switch (last_url) {
case "tq":
console.log("TQ Script Run");
//{TQ SCRIPT}
break;
default:
console.log("LP Script Run");
view().then(function() {
post_view();
});
break;
}
}
// =========[ DEFAULT SCRIPT ]=========
/* The Scripts that need to have to work*/
// ======= CODE TO STRICT NUMBER ONLY =======
$(document).ready(function() {
$('.msisdn').on('input', function() {
var c = this.selectionStart,
r = /[^0-9\u0660-\u0669]/g,
v = $(this).val();
if (r.test(v)) {
$(this).val(v.replace(r, ''));
c--;
}
this.setSelectionRange(c, c);
});
});
//DEFAULT CODE!!
function check_url_telco() {
let url_string = window.location.href
let url = new URL(url_string);
let telco = url.searchParams.get("telco");
console.warn("Checking URL Telco : " + telco);
return telco;
}
function get_lang() {
let url_string = window.location.href
let url = new URL(url_string);
return url.searchParams.get("lang");
}
function get_tracking_id() {
var result;
// IF GLOBAL TRACKING EXIST
if (typeof window.tracking_id !== "undefined" || window.tracking_id != null) {
console.warn("Getting Global Tracking ID : " + window.tracking_id);
result = window.tracking_id;
} else {
let url_string = window.location.href
let url = new URL(url_string);
console.warn("Getting URL Tracking ID : " + url.searchParams.get("tracking_id"));
result = url.searchParams.get("tracking_id");
}
return result;
}
function get_transaction_id() {
var result;
// IF GLOBAL TRANSACTION EXIST
if (typeof window.transaction_id !== "undefined" || window.transaction_id != null) {
console.warn("Getting Global Transaction ID : " + window.transaction_id);
result = window.transaction_id;
} else {
let url_string = window.location.href
let url = new URL(url_string);
console.warn("Getting URL Transaction ID : " + url.searchParams.get("t_id"));
if (url.searchParams.get("t_id") == null || url.searchParams.get("t_id") == "") {
console.warn("t_id invalid : " + url.searchParams.get("t_id"));
}
result = url.searchParams.get("t_id");
}
return result;
}
function get_msisdn_url() {
let url_string = window.location.href
let url = new URL(url_string);
return url.searchParams.get("msisdn");
}
function create_lead() {
var xhttp = new XMLHttpRequest();
var api_url = "https://prod.api.puretechglobal.net/lp/api";
var params = {
//------- standardize param----------//
tracking_id: get_tracking_id(),
country: window.country,
gateway: window.gateway,
telco: window.telco,
shortcode: window.sc,
keyword: window.kw,
msisdn: window.msisdn, //some gateway API using param name "phone" ,so "phone" is supported!
create_lead_only: true, //true mean call only create_lead , wont call Gateway API
flow: window.flow //pass the flow example ,ussd , pin_request to execute Gateway API Call
};
console.warn("Creating Lead");
console.log(params);
return new Promise((resolve, reject) => {
xhttp.onreadystatechange = (e) => {
if (xhttp.readyState !== 4) {
return;
}
if (xhttp.status === 200) {
console.log("SUCCESS", xhttp.responseText);
resolve(JSON.parse(xhttp.responseText));
} else {
console.warn("request_error");
reject(e)
}
};
xhttp.open("POST", api_url);
xhttp.send(JSON.stringify(params))
});
}
function get_msisdn() {
var msisdn = $("#msisdn").val();
var check = 0;
if (typeof input !== "undefined") {
check = 1;
}
let arNumberToen = function(str) {
if (typeof str === "string") {
for (var i = 0; i < 10; i++) {
str = str.replace(arabicNumbers[i], i);
}
}
return str;
};
var arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
msisdn = arNumberToen(msisdn);
var country_code = "60";
if (msisdn == null || msisdn == "") {
return "-";
} else {
console.warn("Phone number : " + country_code + msisdn);
return country_code + msisdn;
}
}
function view() {
let api_url = "https://prod.api.puretechglobal.net/lp/view/v2";
let url_string = window.location.href
let url = new URL(url_string);
let tracking_data = Object.fromEntries(new URLSearchParams(url.search));
tracking_data["lp_path"] = window.location.pathname;
tracking_data["blocking_id"] = ("; " + document.cookie).split(`; blocking_id=`).pop().split(";")[0];
//[[ view_tracking_addon ]]
let jqxhr = $.ajax({
type: "POST",
url: api_url,
data: tracking_data
});
return new Promise((resolve, reject) => {
jqxhr.done(function(result) {
if (result.status == "ok") {
if (result.data) {
let url_string = window.location.href
let url = new URL(url_string);
var lang = url.searchParams.get("lang");
console.log("searchparamsresultlang: " + lang);
let templang = lang;
params = new URLSearchParams(result.data);
window.history.replaceState(null, null, window.location.pathname + "?" + params);
console.log("below is params from view js");
console.log(params);
//global tracking and transaction id
window.tracking_id = params.get("tracking_id");
window.transaction_id = (params.get("t_id")) ? params.get("t_id") : params.get("transaction_id");
console.warn("Global Tracking ID : " + window.tracking_id);
console.warn("Global Transaction ID : " + window.transaction_id);
//find if the url already have lang in url params
if (templang) {
console.log("got existing language from url : " + templang);
let url_string = window.location.href
let url = new URL(url_string);
url.searchParams.set("lang", templang);
window.history.replaceState(null, null, url.search);
}
//[[ view_add_script ]]
}
if (result.cookies) {
for (var key in result.cookies) {
if (result.cookies.hasOwnProperty(key)) {
document.cookie = key + "=" + result.cookies[key] + "; expires=Sun, 1 Jan 2090 00:00:00 UTC; path=/"
}
}
}
var event = new Event("custom_event_after_view");
document.dispatchEvent(event);
} else if (result.status == "redirect") {
window.location.replace(result.data.url);
}
resolve(result);
});
jqxhr.fail(function(result) {
console.warn("View API Error");
reject(result);
});
});
}
function post_view() {
// If there is MSISDN input => do not enable the button.
let msisdn_input = document.getElementById('msisdn');
if (!msisdn_input) {
$('.button').removeClass('disabled_btn').prop('disabled', false);
}
}
// =========[ FUNCTIONAL SCRIPT ]=========
function rotator() {
// 0 -> 06 = 1st Week
// 7 -> 13 = 2nd Week
const rotation = {
0: {
shortcode: "36518",
keyword: "done"
},
1: {
shortcode: "36218",
keyword: "hunt"
},
2: {
shortcode: "36518",
keyword: "shot"
},
3: {
shortcode: "36318",
keyword: "relax"
},
4: {
shortcode: "36918",
keyword: "watch"
},
5: {
shortcode: "36718",
keyword: "mov"
},
6: {
shortcode: "36218",
keyword: "hit"
},
7: {
shortcode: "36718",
keyword: "movie"
},
8: {
shortcode: "36318",
keyword: "kiss"
},
9: {
shortcode: "36918",
keyword: "need"
},
10: {
shortcode: "36718",
keyword: "vid"
},
11: {
shortcode: "36218",
keyword: "pick"
},
12: {
shortcode: "36518",
keyword: "dig"
},
13: {
shortcode: "36318",
keyword: "keep"
}
};
const startDate = new Date('2025-01-05'); // The start of Week 1
const currentDate = getUTC8();
const daysPassed = Math.floor((currentDate.getTime() - startDate.getTime()) / (1000 * 3600 * 24));
const currentIndex = Math.abs(daysPassed % (Object.keys(rotation).length));
return response = {
keyword: rotation[currentIndex].keyword,
shortcode: rotation[currentIndex].shortcode
};
}
function getUTC8() {
const now = new Date();
const utc8Date = now.toLocaleString('en-US', {
timeZone: 'Asia/Kuala_Lumpur'
});
const newDate = new Date(utc8Date);
return newDate;
}
function getKeyword() {
return rotator().keyword;
}
function getShortcode() {
return rotator().shortcode;
}
function submit_request() {
window.telco = "maxis";
window.gateway = "maxis";
window.sc = "33789";
window.kw = "pplayreg1";
// window.sc = getShortcode();
// window.kw = getKeyword();
window.flow = "c2sms";
window.country = "malaysia";
window.msisdn = get_msisdn();
create_lead().then(function(res) {
$("#button-loading").show();
// ====== FLOW ======
switch (window.telco) {
case "maxis":
c2sms_maxis(window.msisdn, window.telco, window.sc, window.kw);
break;
}
}).catch(function() {
$("#button-loading").hide();
alert("Create Lead Failed! Please Check");
});
}
function c2sms_maxis(msisdn, telco, shortcode, keyword) {
// let smshead = 36718;
// let smsbody = "ON VID " + get_transaction_id();
let smshead = shortcode;
let smsbody = `ON ${keyword.toUpperCase()} ` + get_transaction_id();
$("#button-loading").show();
setTimeout(function() {
jQuery(document).ready(function() {
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/ig)) {
$("#c2sms").attr("href", function() {
console.warn("IOS SMS");
return $(this).attr("href").replace("sms:?body=", "sms:" + smshead + "&body=" + smsbody)
});
} else {
$("#c2sms").attr("href", function() {
console.warn("Android SMS");
return $(this).attr("href").replace("sms:?body=", "sms:" + smshead + "?body=" + smsbody)
});
}
$("#button-loading").hide();
var hyperlink_c2sms = document.getElementById("c2sms");
hyperlink_c2sms.click();
});
//[[ c2sms_maxis_add_script ]]
}, 1200)
}
// =========[ SETTING SCRIPT ]=========
//[[ setting script ]]
// =========[ DESIGN SCRIPT ]=========
//[[ design script ]]
// =========[ LANGUAGE SCRIPT ]=========
// ===== GETTING LANGUAGE ====
let url_string = window.location.href;
let url = new URL(url_string);
let defaultLang = "en";
var lang = (url.searchParams.get("lang") == "null" || url.searchParams.get("lang") == null || url.searchParams.get("lang") != defaultLang) ? "en" : url.searchParams.get("lang");
console.log(lang);
$(document).ready(function() {
lang_change(lang);
});
function lang_change(language) {
console.log("changing language to " + language);
let url_string = window.location.href
let url = new URL(url_string);
let keyword = getKeyword().toUpperCase();
let shortcode = getShortcode().toUpperCase();
url.searchParams.set("lang", language);
window.history.replaceState(null, null, url.search);
switch (language) {
case "en":
console.log('processing en');
$("html").attr("class", "");
$(".dt-use-en-only").hide();
$(".nav_Website").html("");
$(".nav_Copyright").html("");
$(".ae_tnc").html("");
$(".bannerTitle").html("");
$(".instructions").html("
Click on the button below to continue.
"); $(".button").html("Continue"); $(".txt_msisdn_error").html(""); $(".txt_request_error").html(""); $(".txt_pin_request_error").html(""); $(".txt_pin_verify_error").html(""); $(".txt_no_service_error").html(""); $(".txt_checkbox_error").html(""); $(".txt_hlr_error").html(""); $(".button_tnc").html("Terms and Conditions"); $(".tnc").html(`This is a funny video clip subscription service, please visit http://my.394.grabmobi.com to access your premium contents. On subscribing to this service, subscription would be renewed automatically until you unsubscribe. You will be charged RM1.00/SMS, 1 SMS weekly. You can unsubscribe from this service anytime. To unsubscribe from this service, send STOP PPLAYREG1 to 33789. To use this service, you must be more than 18 years old and must have received permission from your guardian or parents who is authorized to pay your mobile bills. This service allows for mobile 3G/4G user. Regular mobile network charges. Helpline: +603-79550555 (local rate), 9am-6pm Monday to Friday (excluded Public Holiday). Email: admin@powerplay.com.my. Content Service Provider: Power Play Sdn Bhd`); $(".tq_text_maxis").html(""); break; } }