- var download_link = document.createElement('a');
- download_link.textContent = 'Direct Link';
- download_link.setAttribute('href', fileURL);
- 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);
+ // 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) {
+ var debug = false;
+ if (debug) {
+ alert(message)
+ } else {
+ GM_log(message);
+ }
+}
+
+function _rai_get_actual_url(site, URL) {
+ // http://www.neaveru.com/wordpress/index.php/2008/05/09/greasemonkey-bug-domnodeinserted-event-doesnt-allow-gm_xmlhttprequest/
+ setTimeout( function() {
+ GM_xmlhttpRequest({
+ method: "GET",
+ // XXX A custom header. This is the "clever" trick Rai uses to ensure
+ // the content is accessed by www.rai.tv only...
+ headers: {'viaurl': 'www.rai.tv'},
+ url: URL,
+ onload: function(response) {
+ text = response.responseText;
+ text = text.replace(/&/g, '&')
+ parser = new DOMParser();
+ xmlDoc = parser.parseFromString(text, "text/xml");