From: Antonio Ospite <ospite@studenti.unina.it>
Date: Fri, 9 Dec 2011 15:15:05 +0000 (+0100)
Subject: Split out _get_URL() and _add_link() functions
X-Git-Tag: 0.3~12
X-Git-Url: https://git.ao2.it/GM_direct_download_links.git/commitdiff_plain/c0b18e9381e770e8e1d9a87dd1faada30e176214?ds=sidebyside

Split out _get_URL() and _add_link() functions

This is in preparation for the introduction of async behaviors.

Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
---

diff --git a/direct_download_links.user.js b/direct_download_links.user.js
index a29f81c..8e06997 100644
--- a/direct_download_links.user.js
+++ b/direct_download_links.user.js
@@ -105,6 +105,16 @@ function direct_download_link_add(pageURL, site) {
     return null;
   }
 
+  var URL = _get_URL(site, element);
+  if (!URL) {
+    DDL_log('DirectDL (' + site.pageURL + '): cannot get the URL.');
+    return null;
+  }
+
+  return _add_link(site, URL);
+}
+
+function _get_URL(site, element) {
   var content = element.innerHTML;
   if (!content) {
     DDL_log('DirectDL (' + site.pageURL + '): content is null, cannot find URL.');
@@ -118,6 +128,11 @@ function direct_download_link_add(pageURL, site) {
   }
   var URL = matches[1];
 
+  return URL;
+}
+
+function _add_link(site, URL) {
+
   var links = document.getElementById(site.linkDest);
   if (!links) {
     DDL_log('DirectDl (' + site.pageURL + '): Cannot add the direct download link.');