+ if (site.processURL) {
+ site.processURL(site, URL);
+ return;
+ }
+
+ var evt = document.createEvent('Event');
+ evt.initEvent('UrlFetched', true, true);
+ evt.site = site;
+ evt.URL = URL;
+ document.dispatchEvent(evt);
+}
+
+function _add_link(e) {
+ var site = e.site;
+ var URL = e.URL;;
+
+ var destination = getElementByXPath(site.linkDestXPath);
+ if (!destination) {
+ DDL_log('DirectDl (' + site.pageURL + '): Cannot add the direct download link.');
+ return;
+ }
+
+ // 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;'
+ style += ' position: relative; z-index: 1000;'
+ download_link.setAttribute('style', style);
+
+ destination.insertBefore(download_link, destination.firstChild);
+ }
+}
+
+function DDL_log(message) {
+ var debug = false;
+ if (debug) {
+ alert(message)
+ } else {
+ GM_log(message);