]> git.cworth.org Git - lmno.games/blobdiff - scribe/scribe.jsx
Add a button to copy the game URL for sharing and tighten up text
[lmno.games] / scribe / scribe.jsx
index 06a8541297059bdc046f6f40ae3ac129d8ff2e74..be0de3799acf1f6bedaeb2171de86e9588832c38 100644 (file)
@@ -79,14 +79,31 @@ events.addEventListener("game-state", event => {
  * Game and supporting classes                           *
  *********************************************************/
 
+function copy_to_clipboard(id)
+{
+  const tmp = document.createElement("input");
+  tmp.setAttribute("value", document.getElementById(id).innerHTML);
+  document.body.appendChild(tmp);
+  tmp.select();
+  document.execCommand("copy");
+  document.body.removeChild(tmp);
+}
+
 function GameInfo(props) {
   if (! props.id)
     return null;
 
   return (
     <div className="game-info">
-      <h2>{props.id}</h2>
-      Invite a friend to play by sending this URL: {props.url}
+      <span className="game-id">{props.id}</span>
+      {" "}
+      Share this link to invite a friend:{" "}
+      <span id="game-share-url">{props.url}</span>
+      {" "}
+      <button
+        className="inline"
+        onClick={() => copy_to_clipboard('game-share-url')}
+      >Copy Link</button>
     </div>
   );
 }
@@ -132,7 +149,7 @@ function PlayerInfo(props) {
 
   return (
     <div className="player-info">
-      <h2>Players</h2>
+      <span className="players-header">Players: </span>
       {props.player.name}
       {props.player.team ? ` (${props.player.team})` : ""}
       {props.first_move ? "" : " "}