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