tawkToCustomTabParams

Insert User Details into the Custom Tab URLS

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         tawkToCustomTabParams
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Insert User Details into the Custom Tab URLS
// @author       Anthony van Orizande
// @match        https://dashboard.tawk.to/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var contactEmail = null;

    // Assume that jQuery is loaded by the Tawk.to client.
    // Activity loop to look for detail changes.
    setInterval(function () {
        $('div.chat-content-container').width('calc(50% - 10px)');
        $('div.chat-details-container.ui-resizable').width('calc(50% - 10px)');

        try {
            var $detailsForm = $('#details-form table tr');
            if (!$detailsForm) {
                $detailsForm = $('#conversation-details-container table tr');
            }

            // If we have a detail form then capture the details.
            if ($detailsForm && $detailsForm.length) {
                // Save the contact information.
                for(var i = 0; i < $detailsForm.length; i++) {
                    var fieldNameRaw = $detailsForm[i].firstChild.innerText;
                    var fieldName = (fieldNameRaw) ? String(fieldNameRaw).trim().toLowerCase(): null;
                    var fieldValueRaw = $detailsForm[i].lastChild.innerText;
                    var fieldValue = (fieldValueRaw) ? String(fieldValueRaw).trim() : null;
                    switch(fieldName) {
                        case 'email': contactEmail = fieldValue; break;
                    }
                }
            }
            else {
                // Chat Form
                var chatEmailRaw = $('input.visitor-email-input').attr('value');
                if (chatEmailRaw) {
                    contactEmail = String(chatEmailRaw).trim();
                }
            }

            // Update the Custom Tabs if any parameters found.
            var $customIFrames = $(".details-container .custom-view iframe");
            if ($customIFrames && $customIFrames.length) {
                // Assume that a new iFrame will be injected if a new ticket or user is opened.
                for(var j = 0; j < $customIFrames.length; j++) {
                    var $iframe = $customIFrames[j];
                    var iframeSrc = $iframe.src;
                    if (contactEmail && $iframe.src.indexOf("($email$)") > -1) {
                        iframeSrc = iframeSrc.replace("($email$)", contactEmail);
                    }

                    // Allow for otherwise invalid domain names by stripping 'https://tawk.to/' if found.
                    // A local "HTTP:" address is invalid.
                    // e.g. INVALID "http://localhost/dbFront/default.aspx?k=ew4dsjguxxtx94u1hy4qiu1ejw&t=clients&s=($email$)"
                    // So we prefix it with "https://tawk.to/" which makes it look valid to the Tawk.to UI.
                    // e.g. VALID "https://tawk.to/http://localhost/dbFront/default.aspx?k=ew4dsjguxxtx94u1hy4qiu1ejw&t=clients&s=($email$)"
                    // At runtime this script will strip the "https://tawk.to/"
                    iframeSrc = iframeSrc.replace('https://tawk.to/', '');

                    // Make the final update to the iFrame Source.
                    if ($iframe.src != iframeSrc) {
                        $iframe.src = iframeSrc;
                    }
                }
            }
        }
        catch(ex)
        {
            console.error('Custom Tabs Error: ' + (typeof ex == 'string') ? ex : ex.message);
        }
    }, 100);
})();