PageSourceSearch

https://data.travelchinaguide.com/js/v1/tcg-tawk-chat.js

js travelchinaguide.com collected 2026-10-02 02:45:19 UTC 7,603 bytes, 211 lines download raw bytes

1(function () {
2    var TcgTawkPendingOpen = false;
3    var TcgTawkPendingTimer = null;
4    var TcgTawkFinishTimer = null;
5    var TcgTawkOpenTimeout = null;
6    var TcgTawkLauncherKeepHidden = false;
7    var TcgTawkLauncherObserver = null;
8    var TcgTawkStateTimer = null;
9
10    window.Tawk_API = window.Tawk_API || {};
11
12    function setTcgChatButtonVisible(visible) {
13        var btn = document.querySelector(".tcg-chat-now-btn");
14        if (btn) btn.style.display = visible ? "block" : "none";
15    }
16
17    function setTcgChatButtonLoading(loading) {
18        var btn = document.querySelector(".tcg-chat-now-btn");
19        if (btn) btn.classList.toggle("is-loading", loading);
20    }
21
22    function clearTcgTawkPendingTimer() {
23        if (TcgTawkPendingTimer) clearTimeout(TcgTawkPendingTimer);
24        TcgTawkPendingTimer = null;
25    }
26
27    function clearTcgTawkFinishTimer() {
28        if (TcgTawkFinishTimer) clearTimeout(TcgTawkFinishTimer);
29        TcgTawkFinishTimer = null;
30    }
31
32    function clearTcgTawkOpenTimeout() {
33        if (TcgTawkOpenTimeout) clearTimeout(TcgTawkOpenTimeout);
34        TcgTawkOpenTimeout = null;
35    }
36
37    function eachTcgTawkFixedElement(callback) {
38        var nodes = document.body.getElementsByTagName("*");
39        for (var i = 0; i < nodes.length; i++) {
40            var node = nodes[i];
41            if (node.classList && node.classList.contains("tcg-chat-now-btn")) continue;
42            var style = window.getComputedStyle(node);
43            if (style.position !== "fixed") continue;
44            var rect = node.getBoundingClientRect();
45            if (rect.right < window.innerWidth - 180 || rect.bottom < window.innerHeight - 180) continue;
46            callback(node, rect);
47        }
48    }
49
50    function setTcgTawkLauncherVisible(visible) {
51        eachTcgTawkFixedElement(function (node, rect) {
52            var zIndex = parseInt(window.getComputedStyle(node).zIndex, 10);
53            var isTawkLikeNode = node.tagName.toLowerCase() === "iframe" || zIndex > 10000;
54            if (isTawkLikeNode && rect.width <= 140 && rect.height <= 140) node.style.visibility = visible ? "" : "hidden";
55        });
56    }
57
58    function watchTcgTawkLauncherHidden() {
59        if (TcgTawkLauncherObserver || !window.MutationObserver) return;
60        TcgTawkLauncherObserver = new MutationObserver(function () {
61            if (TcgTawkLauncherKeepHidden) setTcgTawkLauncherVisible(false);
62        });
63        TcgTawkLauncherObserver.observe(document.body, {
64            childList: true,
65            subtree: true,
66            attributes: true,
67            attributeFilter: ["class", "style"]
68        });
69    }
70
71    function suppressTcgTawkLauncher() {
72        TcgTawkLauncherKeepHidden = true;
73        setTcgTawkLauncherVisible(false);
74        watchTcgTawkLauncherHidden();
75    }
76
77    function hideTcgTawkLauncher() {
78        suppressTcgTawkLauncher();
79        if (window.Tawk_API.hideWidget) window.Tawk_API.hideWidget();
80    }
81
82    function showTcgTawkLauncher() {
83        TcgTawkLauncherKeepHidden = false;
84        setTcgTawkLauncherVisible(true);
85    }
86
87    function isTcgTawkWindowVisible() {
88        var points = [
89            [window.innerWidth - 80, window.innerHeight - 170],
90            [window.innerWidth - 160, window.innerHeight - 120],
91            [window.innerWidth - 80, window.innerHeight - 260]
92        ];
93        for (var i = 0; i < points.length; i++) {
94            var x = points[i][0];
95            var y = points[i][1];
96            if (x < 0 || y < 0) continue;
97            var el = document.elementFromPoint(x, y);
98            while (el) {
99                if (el.classList && el.classList.contains("tcg-chat-now-btn")) break;
100                if (el.classList && el.classList.contains("whatsapp-float-btn")) break;
101                if (el.classList && el.classList.contains("gotop")) break;
102
103		    var tagName = el.tagName && el.tagName.toLowerCase();
104		    var mark = [
105		        el.id || "",
106		        typeof el.className === "string" ? el.className : "",
107		        el.getAttribute && (el.getAttribute("src") || ""),
108		        el.getAttribute && (el.getAttribute("title") || ""),
109		        el.getAttribute && (el.getAttribute("name") || "")
110		    ].join(" ").toLowerCase();
111
112    			if (tagName === "iframe" && mark.indexOf("tawk") !== -1) return true;
113                el = el.parentElement;
114            }
115        }
116        return false;
117    }
118
119    function finishTcgTawkOpening() {
120        TcgTawkPendingOpen = false;
121        clearTcgTawkPendingTimer();
122        clearTcgTawkFinishTimer();
123        clearTcgTawkOpenTimeout();
124        TcgTawkLauncherKeepHidden = false;
125        setTcgTawkLauncherVisible(true);
126        setTcgChatButtonLoading(false);
127        setTcgChatButtonVisible(false);
128    }
129
130    function watchTcgTawkOpening() {
131        TcgTawkPendingOpen = false;
132        clearTcgTawkPendingTimer();
133        clearTcgTawkFinishTimer();
134        if (isTcgTawkWindowVisible()) {
135            finishTcgTawkOpening();
136            return;
137        }
138        TcgTawkFinishTimer = setTimeout(watchTcgTawkOpening, 50);
139    }
140
141    function syncTcgTawkState() {
142        if ((window.Tawk_API.isChatMaximized && window.Tawk_API.isChatMaximized()) || isTcgTawkWindowVisible()) {
143            finishTcgTawkOpening();
144            return;
145        }
146        suppressTcgTawkLauncher();
147        setTcgChatButtonVisible(true);
148    }
149
150    function watchTcgTawkState(times) {
151        if (TcgTawkStateTimer) clearTimeout(TcgTawkStateTimer);
152        syncTcgTawkState();
153        if (times <= 0 || !TcgTawkLauncherKeepHidden) return;
154        TcgTawkStateTimer = setTimeout(function () {
155            watchTcgTawkState(times - 1);
156        }, 100);
157    }
158
159    function openLoadedTcgTawkChat() {
160        if (!window.Tawk_API || !window.Tawk_API.showWidget || !window.Tawk_API.maximize) return false;
161        setTcgChatButtonLoading(true);
162        showTcgTawkLauncher();
163        clearTcgTawkFinishTimer();
164        clearTcgTawkOpenTimeout();
165        window.Tawk_API.showWidget();
166        window.Tawk_API.maximize();
167        TcgTawkOpenTimeout = setTimeout(finishTcgTawkOpening, 4000);
168        watchTcgTawkOpening();
169        return true;
170    }
171
172    function tryOpenPendingTcgTawkChat() {
173        if (!TcgTawkPendingOpen || openLoadedTcgTawkChat()) return;
174        clearTcgTawkPendingTimer();
175        TcgTawkPendingTimer = setTimeout(tryOpenPendingTcgTawkChat, 200);
176    }
177
178    window.openTcgTawkChat = function () {
179        if (openLoadedTcgTawkChat()) return;
180        TcgTawkPendingOpen = true;
181        setTcgChatButtonLoading(true);
182        tryOpenPendingTcgTawkChat();
183    };
184
185    window.Tawk_API.onLoad = function () {
186        if (!TcgTawkPendingOpen) watchTcgTawkState(15);
187        tryOpenPendingTcgTawkChat();
188    };
189
190    window.Tawk_API.onChatMaximized = function () {
191        finishTcgTawkOpening();
192    };
193
194    window.Tawk_API.onChatMinimized = function () {
195        TcgTawkPendingOpen = false;
196        clearTcgTawkPendingTimer();
197        clearTcgTawkFinishTimer();
198        setTcgChatButtonLoading(false);
199        suppressTcgTawkLauncher();
200        setTcgChatButtonVisible(true);
201    };
202
203    window.Tawk_API.onChatHidden = function () {
204        TcgTawkPendingOpen = false;
205        clearTcgTawkPendingTimer();
206        clearTcgTawkFinishTimer();
207        setTcgChatButtonLoading(false);
208        hideTcgTawkLauncher();
209        setTcgChatButtonVisible(true);
210    };
211})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.