angular.module('utils.linkGeneration', [])

.factory('linkGeneration', [function() {
  var linkGeneration = {};

  var s4 = function() {
    //this is a random 4-charactder hash generator
    return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
  };

  linkGeneration.adjAdjAnimal = function() {
    return adjAdjAnimal(); // global function from adjective-adjective-animal bower package, returns promise
  };

  linkGeneration.generateHash = function() {
    return s4() + s4() + s4() + s4();
  };

  linkGeneration.copyToClipboard = function(elem) {
      // create hidden text element, if it doesn't already exist
      var targetId = "_hiddenCopyText_";
      var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
      var origSelectionStart, origSelectionEnd;
      if (isInput) {
        // can just use the original source element for the selection and copy
        target = elem;
        origSelectionStart = elem.selectionStart;
        origSelectionEnd = elem.selectionEnd;
      } else {
        // must use a temporary form element for the selection and copy
        target = document.getElementById(targetId);
        if (!target) {
          var target = document.createElement("textarea");
          target.style.position = "absolute";
          target.style.left = "-9999px";
          target.style.top = "0";
          target.id = targetId;
          document.body.appendChild(target);
        }
        target.textContent = elem.textContent;
      }
      // select the content
      var currentFocus = document.activeElement;
      target.focus();
      target.setSelectionRange(0, target.value.length);

      // copy the selection
      return document.execCommand("copy");
    }

  return linkGeneration;

}]);
@@ -319,31 +319,8 @@
 %0A   
- return adjAdjAnimal();
  // 
@@ -398,16 +398,43 @@
 promise%0A
+    return adjAdjAnimal();%0A
   %7D;%0A%0A  
@@ -472,24 +472,49 @@
 unction() %7B%0A
+    // 16 character hash%0A
     return s
@@ -597,26 +597,24 @@
 elem) %7B%0A    
-  
 // create hi
@@ -660,26 +660,24 @@
 y exist%0A    
-  
 var targetId
@@ -699,26 +699,24 @@
 Text_%22;%0A    
- 
- 
 var isInput 
@@ -774,26 +774,24 @@
 TAREA%22;%0A    
-  
 var origSele
@@ -814,28 +814,34 @@
 SelectionEnd
+, target
 ;%0A
-  
     if (isIn
@@ -849,26 +849,24 @@
 ut) %7B%0A      
-  
 // can just 
@@ -922,34 +922,32 @@
  and copy%0A      
-  
 target = elem;%0A 
@@ -943,34 +943,32 @@
 t = elem;%0A      
- 
- 
 origSelectionSta
@@ -995,26 +995,24 @@
 tart;%0A      
-  
 origSelectio
@@ -1041,18 +1041,16 @@
 nd;%0A    
- 
- 
 %7D else %7B
@@ -1050,18 +1050,16 @@
  else %7B%0A
-  
       //
@@ -1122,26 +1122,24 @@
  copy%0A      
- 
- 
 target = doc
@@ -1176,18 +1176,16 @@
 ;%0A      
-  
 if (!tar
@@ -1199,22 +1199,16 @@
         
- 
- var 
 target =
@@ -1244,34 +1244,32 @@
 area%22);%0A        
-  
 target.style.pos
@@ -1288,18 +1288,16 @@
 olute%22;%0A
-  
         
@@ -1331,26 +1331,24 @@
 x%22;%0A        
-  
 target.style
@@ -1363,26 +1363,24 @@
 0%22;%0A        
-  
 target.id = 
@@ -1397,18 +1397,16 @@
         
- 
- 
 document
@@ -1438,26 +1438,24 @@
 ;%0A      
-  
 %7D%0A      
   target
@@ -1442,26 +1442,24 @@
     %7D%0A      
- 
- 
 target.textC
@@ -1485,30 +1485,26 @@
 ontent;%0A    
-  %7D%0A  
+%7D%0A
     // selec
@@ -1521,18 +1521,16 @@
 ent%0A    
-  
 var curr
@@ -1564,18 +1564,16 @@
 lement;%0A
-  
     targ
@@ -1584,26 +1584,24 @@
 ocus();%0A    
-  
 target.setSe
@@ -1639,18 +1639,16 @@
 ngth);%0A%0A
-  
     // c
@@ -1669,18 +1669,16 @@
 ion%0A    
-  
 return d
@@ -1706,18 +1706,16 @@
 copy%22);%0A
-  
   %7D%0A%0A  r
@@ -1741,8 +1741,9 @@
 n;%0A%0A%7D%5D);
+%0A

Add comments and fix syntax lint in linkGenerationFactory.js