summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--static/hide.js17
-rw-r--r--static/misc.js41
-rw-r--r--templates/lobby_html.jinja6
3 files changed, 44 insertions, 20 deletions
diff --git a/static/hide.js b/static/hide.js
deleted file mode 100644
index 67cb5c9..0000000
--- a/static/hide.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var hidden = false;
-
-function hideOffline() {
- hidden = !hidden;
- var 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);
-
-// vim: commentstring=/*\ %s\ */
diff --git a/static/misc.js b/static/misc.js
new file mode 100644
index 0000000..074e2f9
--- /dev/null
+++ b/static/misc.js
@@ -0,0 +1,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\ */
diff --git a/templates/lobby_html.jinja b/templates/lobby_html.jinja
index fcf440b..c1d7fac 100644
--- a/templates/lobby_html.jinja
+++ b/templates/lobby_html.jinja
@@ -2,7 +2,7 @@
<title>CS:GO Lobbylinkfinder</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="static/style.css" />
- <script src="static/hide.js"></script>
+ <script src="static/misc.js"></script>
</head>
<body>
@@ -47,7 +47,7 @@
{% if profile['lobbysteamid'] %}
<div class="buttons">
<a href="steam://joinlobby/{{ profile['gameid'] }}/{{ profile['lobbysteamid'] }}/{{ profile['steamid'] }}" class="joinbutton">Join lobby</a>
- <a href="#" onclick="javascript:window.prompt('Lobbylink', '[url]steam://joinlobby/{{ profile['gameid'] }}/{{ profile['lobbysteamid'] }}/{{ profile['steamid'] }}[/url]'); return false;" class="joinbutton">Copy link</a>
+ <a href="#" onclick="javascript:copyToClipboard('[url]steam://joinlobby/{{ profile['gameid'] }}/{{ profile['lobbysteamid'] }}/{{ profile['steamid'] }}[/url]'); return false;" class="joinbutton">Copy link</a>
</div>
{% elif profile['gameserverip'] %}
{# playing on a server, got info? #}
@@ -67,7 +67,7 @@
{% endif %}
<div class="buttons">
<a href="steam://connect/{{ profile['gameserverip'] }}" class="joinbutton">Connect</a>
- <a href="#" onclick="javascript:window.prompt('Lobbylink', '[url]steam://connect/{{ profile['gameserverip'] }}[/url]'); return false;" class="joinbutton">Copy link</a>
+ <a href="#" onclick="javascript:copyToClipboard('[url]steam://connect/{{ profile['gameserverip'] }}[/url]'); return false;" class="joinbutton">Copy link</a>
</div>
{% endif %}
{% elif profile['gameextrainfo'] %}