PageSourceSearch

https://www.hasselt.be/modules/custom/hasselt_chat/js/hasselt_chat.online-chat.js?tlptj7

js hasselt.be collected 2026-09-24 17:52:52 UTC 3,510 bytes, 103 lines download raw bytes

1(() => {
2  const observeDOM = (() => {
3    const MutationObserver =
4      window.MutationObserver || window.WebKitMutationObserver;
5
6    return (obj, callback) => {
7      if (!obj || !obj.nodeType === 1) {
8        return; // validation
9      }
10
11      if (MutationObserver) {
12        // define a new observer
13        const obs = new MutationObserver((mutations, observer) => {
14          callback(mutations, observer);
15        });
16        // have the observer observe foo for changes in children
17        obs.observe(obj, {
18          childList: true,
19          attributes: false,
20          characterData: false,
21          subtree: false,
22          attributeOldValue: false,
23          characterDataOldValue: false
24        });
25      } else if (window.addEventListener) {
26        obj.addEventListener("DOMNodeInserted", callback, false);
27        obj.addEventListener("DOMNodeRemoved", callback, false);
28      }
29    };
30  })();
31
32  // Append script.
33  const jsScript = document.createElement("script");
34  jsScript.src = window.drupalSettings.hasseltChat.externalScriptUri;
35  document.body.appendChild(jsScript);
36
37  // Observe the document element.
38  observeDOM(document.body, (mutations, observer) => {
39    let chatButton = document.getElementById(
40      "cloudlink-chat-overlay-contact-us-button"
41    );
42    const chatOverlayWrapper = document.getElementById(
43      "cloudlink-chat-overlay-buttons"
44    );
45
46    if (chatButton) {
47      // Stop observing.
48      observer.disconnect();
49
50      let newLabel;
51
52      // Replace the current button with an exact copy
53      // or replace the SVG text in the original button.
54      if (!window.drupalSettings.hasseltChat.isAvailable) {
55        const newLink = window.drupalSettings.hasseltChat.linkUnavailable;
56        const newLinkTarget =
57          window.drupalSettings.hasseltChat.targetLinkUnavailable;
58
59        // Remove original button from parent.
60        chatButton.parentNode.removeChild(chatButton);
61
62        // Create a new button.
63        if (typeof newLink !== "undefined" && newLink !== "") {
64          chatButton = document.createElement("a");
65          chatButton.setAttribute("href", newLink);
66          chatButton.setAttribute("target", newLinkTarget);
67        } else {
68          chatButton = document.createElement("div");
69        }
70
71        chatButton.id = "cloudlink-chat-overlay-contact-us-button";
72        chatButton.className = "not-available";
73
74        newLabel = window.drupalSettings.hasseltChat.labelUnavailable;
75
76        // Prepend new button to parent.
77        chatOverlayWrapper.insertBefore(
78          chatButton,
79          chatOverlayWrapper.firstChild
80        );
81      } else {
82        newLabel = window.drupalSettings.hasseltChat.labelAvailable;
83
84        // Replace the label in the SVG.
85        if (chatButton.getElementsByTagName("text").length > 0) {
86          chatButton.getElementsByTagName("text")[0].innerHTML = newLabel;
87          // Hide the SVG.
88          chatButton.getElementsByTagName("text")[0].style.display = "none";
89        } else if (chatButton.getElementsByTagName("span").length > 0) {
90          chatButton.getElementsByTagName("span")[0].innerHTML = newLabel;
91          // Hide the SVG.
92          chatButton.getElementsByTagName("span")[0].style.display = "none";
93        }
94      }
95
96      // Add a span with the same text.
97      const span = document.createElement("span");
98      const textnode = document.createTextNode(newLabel);
99      span.appendChild(textnode);
100      chatButton.appendChild(span);
101    }
102  });
103})();

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.