PageSourceSearch

https://www.smart-union.org/wp-content/plugins/text-to-speech-plugin//button-toggle.js?ver=1790271025

js smart-union.org collected 2026-09-24 17:34:03 UTC 1,903 bytes, 65 lines download raw bytes

1// Create a MutationObserver to watch for added elements
2const observer = new MutationObserver((mutations) => {
3  mutations.forEach((mutation) => {
4    if (mutation.addedNodes.length) {
5      initializeTTSButtons();
6    }
7  });
8});
9
10// Function to initialize the TTS buttons
11function initializeTTSButtons() {
12  const ttsContainers = document.querySelectorAll(".mg-text-to-speech");
13  console.log("Number of containers found:", ttsContainers.length);
14
15  ttsContainers.forEach((container, index) => {
16    // Skip if already initialized
17    if (container.dataset.initialized) return;
18    
19    const button = container.querySelector(".mg-tts-button");
20    const audio = container.querySelector("audio");
21    console.log(`Button ${index}:`, button);
22
23    if (button) {
24      button.addEventListener("click", function (e) {
25        console.log("click event triggered", e);
26        container.classList.toggle("active");
27
28        if (container.classList.contains("active")) {
29          audio.style.display = "block";
30          audio.play();
31        } else {
32          audio.pause();
33          audio.style.display = "none";
34        }
35      });
36
37      // Mark as initialized to prevent duplicate listeners
38      container.dataset.initialized = 'true';
39    }
40  });
41}
42
43// Function to start observing
44function startObserving() {
45  if (document.body) {
46    observer.observe(document.body, {
47      childList: true,
48      subtree: true
49    });
50  } else {
51    // If body isn't ready, wait for it
52    document.addEventListener('DOMContentLoaded', () => {
53      observer.observe(document.body, {
54        childList: true,
55        subtree: true
56      });
57    });
58  }
59}
60
61// Start observing
62startObserving();
63
64// Also run once on DOMContentLoaded for any elements that might be there initially
65document.addEventListener("DOMContentLoaded", initializeTTSButtons);

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.