1 // direct_download_links - Add direct download links for (video) files
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 for (video) files
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
38 var supported_sites = [
40 locationRegexp: /^http:\/\/video\.repubblica\.it\/.*$/,
42 fileRegexp: /'pcUrl', '(http:\/\/[^']*)'/,
46 locationRegexp: /^http:\/\/tv\.repubblica\.it\/.*$/,
47 fileElem: 'boxPlayer',
48 fileRegexp: /'pcUrl', '(http:\/\/[^']*)'/,
49 linkDest: 'box_embed',
52 locationRegexp: /^http:\/\/trovacinema\.repubblica\.it\/.*$/,
53 fileElem: 'col-center',
54 fileRegexp: /'flvUrl', '(http:\/\/[^']*)'/,
55 linkDest: 'col-center',
58 locationRegexp: /^http:\/\/www\.kataweb\.it\/tvzap\/.*$/,
59 fileElem: 'tvzap_video',
60 fileRegexp: /'pcUrl', '(http:\/\/[^']*)'/,
61 linkDest: 'playerCont',
65 /* Apply different rules to different sites */
66 for (i = 0; i < supported_sites.length; i++) {
67 var site = supported_sites[i];
69 var result = window.location.href.match(site.locationRegexp);
71 var ret = direct_download_link_add(window.location.href, site.fileElem, site.fileRegexp, site.linkDest);
73 alert('Cannot add the link');
79 * Add a Direct Download link on the page for the specified file
81 * @param pageURL: the URL of the page we are modifying
82 * @param fileElem: the element containing the file URL
83 * @param fileRegexp: the regular expression for finding the file, the first
84 * sub-pattern is taken as the file URL
85 * @param linkDest: the element where to place the Direct Download link
87 * @return: null on error, true on success
89 function direct_download_link_add(pageURL, fileElem, fileRegexp, linkDest) {
90 var element = document.getElementById(fileElem);
92 alert('DirectDL (' + pageURL + '): Cannot find the element containing the file URL.');
96 var content = element.textContent;
98 alert('DirectDL (' + pageURL + '): textContent is null, cannot fild file URL.');
101 var fileURL = content.match(fileRegexp)[1];
103 alert('DirectDL (' + pageURL + '): file URL not found, check the fileRegexp');
107 var links = document.getElementById(linkDest);
109 alert('DirectDl (' + pageURL + '): Cannot add the direct download link.');
113 var download_link = document.createElement('a');
114 download_link.textContent = 'Direct Download';
115 download_link.setAttribute('href', fileURL);
116 var style = 'background-color: white; color: blue;';
117 style += ' border: 2px solid red;'
118 style += ' float: left; font-size: large;';
119 style += ' padding: .5em; margin-left: 30px; margin-bottom: 1em;'
120 download_link.setAttribute('style', style);
122 links.insertBefore(download_link, links.firstChild);