(function () {
try {
/* main variables */
var debug = 0;
var variation_name = "";
function waitForElement(selector, trigger, delayInterval, delayTimeout) {
var interval = setInterval(function () {
if (
document &&
document.querySelector(selector) &&
document.querySelectorAll(selector).length > 0
) {
clearInterval(interval);
trigger();
}
}, delayInterval);
setTimeout(function () {
clearInterval(interval);
}, delayTimeout);
}
let tabData = {
"tab1": {
"link": "https://www.business.hsbc.com.sg/en-sg/business-banking?pid=accountopeningsignposting_control",
}
}
// INSTERTING NEW TAB BTN AND CHANGING RIGHT DIV DATA
function changeDataInPanel(tabNum) {
waitForElement('html body div[id*="useful-links-content"] > div[class*="useful-links__content-info"] > a span:last-of-type', function () {
// console.log(tabNum);
let tabSelector = 'tab' + tabNum;
// changing link
document.querySelector('html body div[id*="useful-links-content"] > div[class*="useful-links__content-info"] > a').href = tabData[tabSelector].link;
}, 50, 15000);
}
function mob() {
if (window.innerWidth < 768) {
if (document.querySelector('html body div[class*="useful-links__head"] div[class*="dropdown-list"]>button')) {
document.querySelector('html body div[class*="useful-links__head"] div[class*="dropdown-list"]>button').addEventListener("click", function () {
waitForElement('html body div[class*="useful-links__head"] div[class*="dropdown-list"]>button + ul', function () {
document.querySelectorAll('html body div[class*="useful-links__head"] div[class*="dropdown-list"]>button + ul>li').forEach((itm, i) => {
itm.addEventListener("click", function () {
if (i == 0) {
changeDataInPanel(i + 1);
}
});
})
}, 100, 15000);
});
}
}
}
function des() {
if (window.innerWidth > 767) {
setTimeout(() => {
document.querySelectorAll("html body .useful-links_tab-container > button").forEach((cta, i) => {
cta.addEventListener("click", function () {
if (i == 0) {
changeDataInPanel(i + 1);
}
});
})
}, 500);
}
}
waitForElement("html body", function () {
if (!document.body.classList.contains("eg-hsbc")) {
document.body.classList.add("eg-hsbc");
waitForElement('html body div[id*="useful-links-content"] > div[class*="useful-links__content-info"] > a', des, 50, 15000);
waitForElement('html body div[class*="useful-links__head"] div[class*="dropdown-list"]>button', mob, 50, 15000);
changeDataInPanel(1);
}
window.screen.orientation.addEventListener("change", function (e) {
document.body.classList.remove("eg-hsbc");
if (!document.body.classList.contains("eg-hsbc")) {
document.body.classList.add("eg-hsbc");
waitForElement('html body div[id*="useful-links-content"] > div[class*="useful-links__content-info"] > a', des, 50, 15000);
waitForElement('html body div[class*="useful-links__head"] div[class*="dropdown-list"]>button', mob, 50, 15000);
changeDataInPanel(1);
}
});
}, 50, 15000);
} catch (e) {
if (debug) console.log(e, "error in Test" + variation_name);
}
})();