PageSourceSearch

https://www.lojaintt.com.br/common/js/whatsappFloatButton.js?v=X1

js lojaintt.com.br collected 2026-09-26 10:09:50 UTC 4,509 bytes, 151 lines download raw bytes

1if (typeof whatsappButtonService === "undefined") {
2    whatsappButtonService = [];
3    whatsappButtonService.useDefaultButton = true;
4}
5
6whatsappButtonService.getWhatsappButton = () => {
7    if (typeof WhWidgetSendButton !== "undefined") {
8        whatsappButtonService.useDefaultButton = true;
9        return;
10    }
11
12    whatsappButtonService.useDefaultButton = false;
13
14    const numberEl = document.querySelector(".whatsappbuttonnumber");
15    const positionEl = document.querySelector(".whatsappbuttonposition");
16
17    if (!numberEl || !positionEl) return;
18
19    const rawInput = (numberEl.value || "").trim();
20    const rawPosition = (positionEl.value || "").trim();
21
22    if (!rawInput) return;
23
24    const position = rawPosition === "s" ? "left" : "right";
25
26    const allowedHosts = new Set([
27        "chat.whatsapp.com",
28        "wa.me",
29        "api.whatsapp.com",
30        "web.whatsapp.com",
31        "www.whatsapp.com",
32        "whatsapp.com"
33    ]);
34
35    const allowedPathPrefixes = [
36        "/send",
37        "/channel/"
38    ];
39
40    const isDeepLink = (value) => value.toLowerCase().startsWith("whatsapp://");
41
42    const normalizeHttpLink = (value) => {
43        const v = value.trim();
44        if (isDeepLink(v)) return v;
45        if (v.startsWith("https://")) return v;
46        if (v.startsWith("http://")) return `https://${v.slice("http://".length)}`;
47        return `https://${v}`;
48    };
49
50    const isWhatsappLink = (value) => {
51        if (!value) return false;
52
53        const v = value.trim();
54        if (isDeepLink(v)) return true;
55
56        const normalized = normalizeHttpLink(v);
57
58        try {
59            const url = new URL(normalized);
60
61            if (!allowedHosts.has(url.hostname)) return false;
62
63            if (url.hostname === "chat.whatsapp.com" || url.hostname === "wa.me") {
64                return true;
65            }
66
67            return allowedPathPrefixes.some(prefix => url.pathname.startsWith(prefix));
68        } catch {
69            return false;
70        }
71    };
72
73    const parseInput = (value) => {
74        const parts = value.split(";").map(p => (p || "").trim());
75        return {
76            target: parts[0] || "",
77            message: parts[1] || ""
78        };
79    };
80
81    const extractDeepLinkFallback = (deepLinkValue) => {
82        const result = { phone: "", text: "" };
83
84        try {
85            const query = deepLinkValue.split("?")[1] || "";
86            const params = new URLSearchParams(query);
87            result.phone = (params.get("phone") || "").replace(/[^0-9]/g, "");
88            result.text = params.get("text") || "";
89        } catch {}
90
91        return result;
92    };
93
94    const existingButton = document.getElementById("whatsappBtnFloating");
95    if (existingButton) {
96        existingButton.style[position] = "22px";
97        return;
98    }
99
100    const { target, message } = parseInput(rawInput);
101
102    const link = document.createElement("a");
103    link.target = "_blank";
104    link.id = "whatsappBtnFloating";
105    link.className = "whatsapp-btn-floating";
106    link.ariaLabel = "Ir para o Whatsapp";
107
108    if (isWhatsappLink(target)) {
109        if (isDeepLink(target)) {
110            const { phone, text } = extractDeepLinkFallback(target);
111
112            if (phone) {
113                const encoded = text ? encodeURIComponent(text) : "";
114                link.href = `https://wa.me/${phone}${encoded ? `?text=${encoded}` : ""}`;
115            } else {
116                link.href = normalizeHttpLink(target);
117            }
118        } else {
119            link.href = normalizeHttpLink(target);
120        }
121    } else {
122        const digits = target.replace(/[^0-9]/g, "");
123        if (digits.length < 10) return;
124
125        const encodedMessage = message ? encodeURIComponent(message) : "";
126        const withCountry = digits.startsWith("55") ? digits : `55${digits}`;
127
128        link.href = `https://wa.me/${withCountry}${encodedMessage ? `?text=${encodedMessage}` : ""}`;
129    }
130
131    const icon = document.createElement("i");
132    icon.id = "whatsappBtnIcon";
133    icon.className = "fa fa-whatsapp whatsapp-icon";
134    icon.ariaHidden = "true";
135
136    link.appendChild(icon);
137    document.body.appendChild(link);
138
139    link.style[position] = "22px";
140};
141
142document.addEventListener("DOMContentLoaded", () => {
143    if (!whatsappButtonService.useDefaultButton) return;
144
145    if (typeof lazyLoadService === "undefined") {
146        whatsappButtonService.getWhatsappButton();
147        return;
148    }
149
150    lazyLoadService.addFunctionToQueue(whatsappButtonService.getWhatsappButton);
151});

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.