Misc fixes
[GM_direct_download_links.git] / direct_download_links.user.js
index 0a9aac5..452e2a4 100644 (file)
@@ -91,20 +91,22 @@ for (i = 0; i < supported_sites.length; i++) {
 function direct_download_link_add(pageURL, fileElem, fileRegexp, linkDest) {
   var element = document.getElementById(fileElem);
   if (!element) {
-    alert('DirectDL (' + pageURL  + '): Cannot find the element containing the file URL.');
+    alert('DirectDL (' + pageURL  + '): Cannot find the element ' + fileElem + ' containing the file URL.');
     return null;
   }
 
-  var content = element.textContent;
+  var content = element.innerHTML;
   if (!content) {
-    alert('DirectDL (' + pageURL + '): textContent is null, cannot fild file URL.');
+    alert('DirectDL (' + pageURL + '): content is null, cannot find file URL.');
+    return null;
   }
 
-  var fileURL = content.match(fileRegexp)[1];
-  if (!fileURL) {
+  var matches = content.match(fileRegexp);
+  if (!matches || matches.length < 2 || !matches[1]) {
       alert('DirectDL (' + pageURL + '): file URL not found, check the fileRegexp');
       return null;
   }
+  var fileURL = matches[1];
 
   var links = document.getElementById(linkDest);
   if (!links) {