minor updates
[urlittler] / src / template / root-html.js
index 65e34c73017c7500764d8339250c59823ef2966f..c7550c5e37251cdcc072acd5680c95da6d104946 100644 (file)
@@ -1,6 +1,7 @@
 'use strict';
 
-module.exports = (ctx, pageTitle) => {
+module.exports = (ctx, pageTitle, logoUrl) => {
+  const logoImg = logoUrl ? `<img src="${logoUrl}" class="logo">` : '';
   return `<!DOCTYPE html>
 <html lang="en">
   <head>
@@ -10,21 +11,26 @@ module.exports = (ctx, pageTitle) => {
     <link rel="stylesheet" href="static/theme.css">
   </head>
   <body>
-  <script type="text/javascript">
+  <script type="text/javascript">` + (!ctx.createdLink ? '0;' : `
     document.addEventListener('DOMContentLoaded', function () {
-      document.querySelector('.copy-button').addEventListener('click', function(event) {
+      let timeout;
+      document.querySelector('.copy-button').addEventListener('click', function (event) {
         const linkHref = document.querySelector('.link').href;
         navigator.clipboard.writeText(linkHref);
         const copyButton = this;
         copyButton.style.backgroundColor = 'lightgreen';
-        setTimeout(function () {
+        if (timeout) {
+          clearTimeout(timeout);
+        }
+        timeout = setTimeout(function () {
           copyButton.style.backgroundColor = 'initial';
+          timeout = undefined;
         }, 3000);
       });
-    });
-  </script>
+    });`) + `
+    </script>
     <header>
-      <h1>${pageTitle}</h1>
+      <h1>${logoImg}${pageTitle}</h1>
     </header>` +
     (!ctx.createdLink ? '' : `
     <section class="created-link">