Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.7 kB
3
Indexable
Never
(function() {
    try {
        /* main variables */
        var debug = 0;
        var variation_name = "";
        var $;
        /* all Pure helper functions */

        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);
        }

        function live(selector, event, callback, context) {
            /****Helper Functions****/
            // helper for enabling IE 8 event bindings
            function addEvent(el, type, handler) {
                if (el.attachEvent) el.attachEvent("on" + type, handler);
                else el.addEventListener(type, handler);
            }
            // matches polyfill
            this.Element &&
                (function(ElementPrototype) {
                    ElementPrototype.matches =
                        ElementPrototype.matches ||
                        ElementPrototype.matchesSelector ||
                        ElementPrototype.webkitMatchesSelector ||
                        ElementPrototype.msMatchesSelector ||
                        function(selector) {
                            var node = this,
                                nodes = (node.parentNode || node.document).querySelectorAll(selector),
                                i = -1;
                            while (nodes[++i] && nodes[i] != node);
                            return !!nodes[i];
                        };
                })(Element.prototype);
            // live binding helper using matchesSelector
            function live(selector, event, callback, context) {
                addEvent(context || document, event, function(e) {
                    var found,
                        el = e.target || e.srcElement;
                    while (el && el.matches && el !== context && !(found = el.matches(selector))) el = el.parentElement;
                    if (found) callback.call(el, e);
                });
            }
            live(selector, event, callback, context);
        }


        const eg_icon = `
        <div display="inline-flex" class="Box-sc-qbwqq9-0 Icon__IconWrapper-sc-y4p3lz-0 kIynDD Icon collection-card__title-icon___3Orz0" data-testid="Icon-ChevronRight" data-trackid="Icon-ChevronRight@1.5.0"><svg font-size="m" class="Box-sc-y5ctq9-0 SvgIcon__SvgIconBox-sc-1vnlbss-0 gZsoYO SvgIcon" focusable="false" viewBox="0 0 18 18" color="#333" aria-hidden="true" role="presentation" data-testid="ChevronRightIcon" data-id="Icon" opacity="1" fill="#fff"><path d="M4.196 17l7.998-8-7.998-8h1.696l8 8-8 8z"></path><path fill="none" d="M0 18V0h18v18z"></path></svg></div>`

        const div = document.querySelector("#main div:nth-child(2) > div > a > div:nth-child(3)");

        const eg_theme = document.querySelector("#main div:nth-child(2) > div > a > div:nth-child(3) > div");

        const eg_title = document.querySelector("#main div:nth-child(2) > div > a > div:nth-child(3) > h3")

        const eg_para = `
        <p class="egPar">
        Keen on banking with us?</br>
        Find out more about our account opening process and everything you need to get started
        </p>`;

        eg_title.insertAdjacentHTML("afterend" , eg_para);


        /* Variation Init */
        function init() {

            updateContent();

            live("#main div:nth-child(2) > div > a > div:nth-child(3) > div", 'click', () => {
                updateContent();
            })
        };

        function updateContent() {
            if (div.innerHTML.indexOf("Managing Cash Flow") !== -1) {
                eg_theme.style.display = "none";
                eg_title.innerHTML = `<h3>Opening an HSBC Business account ${eg_icon}</h3>`;
                div.parentElement.href = "https://www.business.hsbc.com.sg/en-sg/business-banking/business-account-opening-process";

                eg_para.insertAdjacentHTML("afterend" , eg_title)
            } else {
                console.log(false)
            }
        }

        /* Initialize variation */
        waitForElement('#main div:nth-child(2) > div > a > div:nth-child(3) > h3', init, 50, 15000);
    } catch (e) {
        if (debug) console.log(e, "error in Test" + variation_name);
    }
})();