Check if the Direct Download Link has been added already
authorAntonio Ospite <ospite@studenti.unina.it>
Sat, 10 Dec 2011 00:50:27 +0000 (01:50 +0100)
committerAntonio Ospite <ospite@studenti.unina.it>
Sat, 10 Dec 2011 01:19:29 +0000 (02:19 +0100)
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
direct_download_links.user.js

index d430887..9f42a3f 100644 (file)
@@ -185,16 +185,24 @@ function _add_link(e) {
     return;
   }
 
     return;
   }
 
-  var download_link = document.createElement('a');
-  download_link.textContent = 'Direct Link';
-  download_link.setAttribute('href', URL);
-  var style = 'background-color: white; color: blue;';
-  style += ' border: 2px solid red;'
-  style += ' float: right; font-size: large;';
-  style += ' padding: .5em; margin: 1em;'
-  download_link.setAttribute('style', style);
-
-  destination.insertBefore(download_link, destination.firstChild);
+  // Check if we added the link already, if so just update the href attribute.
+  // This is useful when _get_URL() is called on async events.
+  var download_link = document.getElementById('GM_direct_downaload_link');
+  if (download_link) {
+    download_link.setAttribute('href', URL);
+  } else {
+    download_link = document.createElement('a');
+    download_link.textContent = 'Direct Link';
+    download_link.setAttribute('id', 'GM_direct_downaload_link');
+    download_link.setAttribute('href', URL);
+    var style = 'background-color: white; color: blue;';
+    style += ' border: 2px solid red;'
+    style += ' float: right; font-size: large;';
+    style += ' padding: .5em; margin: 1em;'
+    download_link.setAttribute('style', style);
+
+    destination.insertBefore(download_link, destination.firstChild);
+  }
 }
 
 function DDL_log(message) {
 }
 
 function DDL_log(message) {