From: Antonio Ospite Date: Thu, 8 Dec 2011 18:26:17 +0000 (+0100) Subject: Misc fixes X-Git-Tag: 0.3~16 X-Git-Url: https://git.ao2.it/GM_direct_download_links.git/commitdiff_plain/d0aadfa63348eab5239adb51f6db2c988980363a?ds=sidebyside Misc fixes - use innerHTML instead of textContent, this is how it should have been from the start, textContent just worked for Repubblica, as the URL was in a script, but what if it is in some html code (, )? - check the regexp actually matches something Signed-off-by: Antonio Ospite --- diff --git a/direct_download_links.user.js b/direct_download_links.user.js index 9b98b37..452e2a4 100644 --- a/direct_download_links.user.js +++ b/direct_download_links.user.js @@ -95,16 +95,18 @@ function direct_download_link_add(pageURL, fileElem, fileRegexp, linkDest) { return null; } - var content = element.textContent; + var content = element.innerHTML; if (!content) { - alert('DirectDL (' + pageURL + '): textContent is null, cannot find 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) {