1 // direct_download_links - Add direct download links
4 // Copyright (C) 2011 Antonio Ospite <ospite@studenti.unina.it>
5 // Released under the GPL license
6 // http://www.gnu.org/copyleft/gpl.html
8 // --------------------------------------------------------------------
10 // This is a Greasemonkey user script.
12 // To install, you need Greasemonkey: https://addons.mozilla.org/en-US/firefox/addon/748
13 // Then restart Firefox and revisit this script.
14 // Under Tools, there will be a new menu item to "Install User Script".
15 // Accept the default configuration and install.
17 // To uninstall, go to Tools/Manage User Scripts,
18 // select "Direct Download Links", and click Uninstall.
20 // --------------------------------------------------------------------
23 // @name Direct Download Links
24 // @namespace http://git.ao2.it/GM_direct_download_links.git
25 // @description Add direct download links
26 // @include http://video.repubblica.it/*
27 // @include http://tv.repubblica.it/*
28 // @include http://trovacinema.repubblica.it/*
29 // @include http://www.kataweb.it/tvzap/*
34 * - find a way to use the same string as in the @include lines to match the
35 * current window.location
36 * - use xpath instead of regexp like in http://a32.me/2009/11/greasemonkey/
37 * - use jquery, like shown in http://a32.me/2009/11/greasemonkey/
40 /* Fields supported by the "site" object.
43 * pageURL: the URL of the page we are modifying
44 * urlContainer: the element containing the URL to link
45 * urlRegexp: the regular expression for finding the URL, the first
46 * sub-pattern is taken as the URL
47 * linkDest: the element where to place the Direct Download link
54 var supported_sites = [
56 locationRegexp: /^http:\/\/video\.repubblica\.it\/.*$/,
57 urlContainer: 'contA',
58 urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/,
62 locationRegexp: /^http:\/\/tv\.repubblica\.it\/.*$/,
63 urlContainer: 'boxPlayer',
64 urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/,
65 linkDest: 'box_embed',
68 locationRegexp: /^http:\/\/trovacinema\.repubblica\.it\/.*$/,
69 urlContainer: 'col-center',
70 urlRegexp: /'flvUrl', '((http|mms):\/\/[^']*)'/,
71 linkDest: 'col-center',
74 locationRegexp: /^http:\/\/www\.kataweb\.it\/tvzap\/.*$/,
75 urlContainer: 'tvzap_video',
76 urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/,
77 linkDest: 'playerCont',
81 /* Apply different rules to different sites */
82 for (i = 0; i < supported_sites.length; i++) {
83 var site = supported_sites[i];
85 var result = window.location.href.match(site.locationRegexp);
87 var ret = direct_download_link_add(window.location.href, site);
89 alert('Cannot add the link');
95 * Add a Direct Download link on the page for the specified URL
97 * @param: a 'site' object described above.
99 * @return: null on error, true on success
101 function direct_download_link_add(pageURL, site) {
102 var element = document.getElementById(site.urlContainer);
104 alert('DirectDL (' + site.pageURL + '): Cannot find the element ' + site.urlContainer + ' containing the URL.');
108 var content = element.innerHTML;
110 alert('DirectDL (' + site.pageURL + '): content is null, cannot find URL.');
114 var matches = content.match(site.urlRegexp);
115 if (!matches || matches.length < 2 || !matches[1]) {
116 alert('DirectDL (' + site.pageURL + '): URL not found, check the urlRegexp');
119 var URL = matches[1];
121 var links = document.getElementById(site.linkDest);
123 alert('DirectDl (' + site.pageURL + '): Cannot add the direct download link.');
127 var download_link = document.createElement('a');
128 download_link.textContent = 'Direct Link';
129 download_link.setAttribute('href', URL);
130 var style = 'background-color: white; color: blue;';
131 style += ' border: 2px solid red;'
132 style += ' float: right; font-size: large;';
133 style += ' padding: .5em; margin: 1em;'
134 download_link.setAttribute('style', style);
136 links.insertBefore(download_link, links.firstChild);