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://tv.repubblica.it/*
27 // @include http://trovacinema.repubblica.it/*
28 // @include http://www.kataweb.it/tvzap/*
33 * - find a way to use the same string as in the @include lines to match the
34 * current window.location
37 var supported_sites = [
39 locationRegexp: /^http:\/\/tv\.repubblica\.it\/.*$/,
40 fileElem: 'boxPlayer',
41 fileRegexp: /'pcUrl', '(http:\/\/[^']*)'/,
42 linkDest: 'box_embed',
45 locationRegexp: /^http:\/\/trovacinema\.repubblica\.it\/.*$/,
46 fileElem: 'col-center',
47 fileRegexp: /'flvUrl', '(http:\/\/[^']*)'/,
48 linkDest: 'col-center',
51 locationRegexp: /^http:\/\/www\.kataweb\.it\/tvzap\/.*$/,
52 fileElem: 'tvzap_video',
53 fileRegexp: /'pcUrl', '(http:\/\/[^']*)'/,
54 linkDest: 'playerCont',
58 /* Apply different rules to different sites */
59 for (i = 0; i < supported_sites.length; i++) {
60 var site = supported_sites[i];
62 var result = window.location.href.match(site.locationRegexp);
64 var ret = direct_download_link_add(window.location.href, site.fileElem, site.fileRegexp, site.linkDest);
66 alert('Cannot add the link');
72 * Add a Direct Download link on the page for the specified file
74 * @param pageURL: the URL of the page we are modifying
75 * @param fileElem: the element containing the file URL
76 * @param fileRegexp: the regular expression for finding the file, the first
77 * sub-pattern is taken as the file URL
78 * @param linkDest: the element where to place the Direct Download link
80 * @return: null on error, true on success
82 function direct_download_link_add(pageURL, fileElem, fileRegexp, linkDest) {
83 var element = document.getElementById(fileElem);
85 alert('DirectDL (' + pageURL + '): Cannot find the element containing the file URL.');
89 var content = element.textContent;
91 alert('DirectDL (' + pageURL + '): textContent is null, cannot fild file URL.');
94 var fileURL = content.match(fileRegexp)[1];
96 alert('DirectDL (' + pageURL + '): file URL not found, check the fileRegexp');
100 var links = document.getElementById(linkDest);
102 alert('DirectDl (' + pageURL + '): Cannot add the direct download link.');
106 var download_link = document.createElement('a');
107 download_link.textContent = 'Direct Download';
108 download_link.setAttribute('href', fileURL);
109 var style = 'background-color: white; color: blue;';
110 style += ' border: 2px solid red;'
111 style += ' float: left; font-size: large;';
112 style += ' padding: .5em; margin-left: 30px; margin-bottom: 1em;'
113 download_link.setAttribute('style', style);
115 links.insertBefore(download_link, links.firstChild);