summaryrefslogtreecommitdiff
path: root/static/misc.js
blob: 074e2f90fd5269b44a437b2797bb1de586ae0d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
let hidden = false;

function hideOffline() {
  hidden = !hidden;
  const playerboxes = document.querySelectorAll('div.Offline');
  for(index in playerboxes) /* Show/Hide player row */
  {
    if(typeof playerboxes[index] != 'object') continue;
    playerboxes[index].style.display = (hidden) ? 'none' : 'inline-block';
  }
  /* And update the text on our button. */
  document.querySelector('#offlinetoggle').innerHTML = (hidden) ? 'Show Offline' : 'Hide Offline';
}
/* Execute function on page load. */
setTimeout(hideOffline, 1);

function copyToClipboard(text) {
  let copiedData = false
  if (window.clipboardData && window.clipboardData.setData) {
    // IE specific code path to prevent textarea being shown while dialog is visible.
    copiedData = clipboardData.setData("Text", text); 
  } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
    const textarea = document.createElement("textarea");
    textarea.textContent = text;
    textarea.style.position = "fixed";  // Prevent scrolling to bottom of page in MS Edge.
    document.body.appendChild(textarea);
    textarea.select();
    try {
      copiedData = document.execCommand("copy");  // Security exception may be thrown by some browsers.
    } catch (ex) {
      console.warn("Copy to clipboard failed.", ex);
    } finally {
      document.body.removeChild(textarea);
    }
  }
  if (!copiedData) {
    window.prompt('Lobbylink', text);
  }
}

// vim: commentstring=/*\ %s\ */