PageSourceSearch

https://wroclawiski.eu/wp-content/plugins/mo-copy-text/copy-greetings.js?ver=1.0

js wroclawiski.eu collected 2026-09-26 04:44:35 UTC 2,704 bytes, 79 lines download raw bytes

1document.addEventListener('DOMContentLoaded', function() {
2  const buttons = document.querySelectorAll('.copy-btn');
3
4  buttons.forEach(button => {
5    button.addEventListener('click', function() {
6      const targetId = button.getAttribute('data-target');
7      const msgId    = button.getAttribute('data-msg');
8
9      const textEl = document.getElementById(targetId);
10      const msgEl  = document.getElementById(msgId);
11
12      if (!textEl) return;
13
14      // Отримуємо текст (разом з емоджі) з <p> (чи іншого тегу).
15      const textToCopy = textEl.innerText || textEl.textContent;
16
17      // Спробуємо API navigator.clipboard
18      if (navigator.clipboard && navigator.clipboard.writeText) {
19        navigator.clipboard.writeText(textToCopy)
20          .then(() => {
21            showCopiedMessage(button, msgEl);
22          })
23          .catch(err => {
24            console.warn('navigator.clipboard.writeText не спрацював, спробуємо fallback', err);
25            fallbackCopyText(textToCopy);
26            showCopiedMessage(button, msgEl);
27          });
28      } else {
29        // Якщо браузер старий або заборонено, робимо fallback
30        fallbackCopyText(textToCopy);
31        showCopiedMessage(button, msgEl);
32      }
33    });
34  });
35
36  /**
37   * Показуємо повідомлення «Copied!» і вмикаємо анімацію кнопки.
38   */
39  function showCopiedMessage(button, msgEl) {
40    // Анімація кнопки
41    button.classList.add('clicked');
42    setTimeout(() => {
43      button.classList.remove('clicked');
44    }, 400);
45
46    // Показуємо «Copied!» на 2с
47    if (msgEl) {
48      msgEl.style.display = 'inline';
49      setTimeout(() => {
50        msgEl.style.display = 'none';
51      }, 2000);
52    }
53  }
54
55  /**
56   * Fallback-метод через прихований textarea + document.execCommand('copy').
57   * Підтримка старих iOS та деяких Android-браузерів.
58   */
59  function fallbackCopyText(text) {
60    const textArea = document.createElement('textarea');
61    textArea.value = text;
62
63    // Щоб textarea не "стрибав" по сторінці, заховаємо його поза вікном
64    textArea.style.position = 'fixed';
65    textArea.style.left = '-999999px';
66
67    document.body.appendChild(textArea);
68    textArea.focus();
69    textArea.select();
70
71    try {
72      document.execCommand('copy');
73    } catch (err) {
74      console.error('Fallback copy error:', err);
75    }
76    document.body.removeChild(textArea);
77  }
78
79});

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.