From: Antonio Ospite Date: Mon, 14 Nov 2011 10:22:04 +0000 (+0100) Subject: Rename to direct_download_links.user.js X-Git-Tag: 0.2~1 X-Git-Url: https://git.ao2.it/GM_direct_download_links.git/commitdiff_plain/9b78a08b8941d4f5ded69bdd5bbbf8d4804dea37 Rename to direct_download_links.user.js The '.user.js' suffix allows to update the script directly from the git repository. Signed-off-by: Antonio Ospite --- diff --git a/direct_download_links.js b/direct_download_links.js deleted file mode 100644 index 6d0f401..0000000 --- a/direct_download_links.js +++ /dev/null @@ -1,125 +0,0 @@ -// direct_download_links - Add direct download links for (video) files -// version 0.1 -// 2011-08-02 -// Copyright (C) 2011 Antonio Ospite -// Released under the GPL license -// http://www.gnu.org/copyleft/gpl.html -// -// -------------------------------------------------------------------- -// -// This is a Greasemonkey user script. -// -// To install, you need Greasemonkey: https://addons.mozilla.org/en-US/firefox/addon/748 -// Then restart Firefox and revisit this script. -// Under Tools, there will be a new menu item to "Install User Script". -// Accept the default configuration and install. -// -// To uninstall, go to Tools/Manage User Scripts, -// select "Direct Download Links", and click Uninstall. -// -// -------------------------------------------------------------------- -// -// ==UserScript== -// @name Direct Download Links -// @namespace http://git.ao2.it/GM_direct_download_links.git -// @description Add direct download links for (video) files -// @include http://video.repubblica.it/* -// @include http://tv.repubblica.it/* -// @include http://trovacinema.repubblica.it/* -// @include http://www.kataweb.it/tvzap/* -// ==/UserScript== - -/* - * TODO: - * - find a way to use the same string as in the @include lines to match the - * current window.location - */ - -var supported_sites = [ - { - locationRegexp: /^http:\/\/video\.repubblica\.it\/.*$/, - fileElem: 'contA', - fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, - linkDest: 'contA', - }, - { - locationRegexp: /^http:\/\/tv\.repubblica\.it\/.*$/, - fileElem: 'boxPlayer', - fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, - linkDest: 'box_embed', - }, - { - locationRegexp: /^http:\/\/trovacinema\.repubblica\.it\/.*$/, - fileElem: 'col-center', - fileRegexp: /'flvUrl', '((http|mms):\/\/[^']*)'/, - linkDest: 'col-center', - }, - { - locationRegexp: /^http:\/\/www\.kataweb\.it\/tvzap\/.*$/, - fileElem: 'tvzap_video', - fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, - linkDest: 'playerCont', - }, -]; - -/* Apply different rules to different sites */ -for (i = 0; i < supported_sites.length; i++) { - var site = supported_sites[i]; - - var result = window.location.href.match(site.locationRegexp); - if (result) { - var ret = direct_download_link_add(window.location.href, site.fileElem, site.fileRegexp, site.linkDest); - if (!ret) { - alert('Cannot add the link'); - } - } -} - -/** - * Add a Direct Download link on the page for the specified file - * - * @param pageURL: the URL of the page we are modifying - * @param fileElem: the element containing the file URL - * @param fileRegexp: the regular expression for finding the file, the first - * sub-pattern is taken as the file URL - * @param linkDest: the element where to place the Direct Download link - * - * @return: null on error, true on success - */ -function direct_download_link_add(pageURL, fileElem, fileRegexp, linkDest) { - var element = document.getElementById(fileElem); - if (!element) { - alert('DirectDL (' + pageURL + '): Cannot find the element containing the file URL.'); - return null; - } - - var content = element.textContent; - if (!content) { - alert('DirectDL (' + pageURL + '): textContent is null, cannot fild file URL.'); - } - - var fileURL = content.match(fileRegexp)[1]; - if (!fileURL) { - alert('DirectDL (' + pageURL + '): file URL not found, check the fileRegexp'); - return null; - } - - var links = document.getElementById(linkDest); - if (!links) { - alert('DirectDl (' + pageURL + '): Cannot add the direct download link.'); - return null; - } - - 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); - - links.insertBefore(download_link, links.firstChild); - - return true; -} diff --git a/direct_download_links.user.js b/direct_download_links.user.js new file mode 100644 index 0000000..6d0f401 --- /dev/null +++ b/direct_download_links.user.js @@ -0,0 +1,125 @@ +// direct_download_links - Add direct download links for (video) files +// version 0.1 +// 2011-08-02 +// Copyright (C) 2011 Antonio Ospite +// Released under the GPL license +// http://www.gnu.org/copyleft/gpl.html +// +// -------------------------------------------------------------------- +// +// This is a Greasemonkey user script. +// +// To install, you need Greasemonkey: https://addons.mozilla.org/en-US/firefox/addon/748 +// Then restart Firefox and revisit this script. +// Under Tools, there will be a new menu item to "Install User Script". +// Accept the default configuration and install. +// +// To uninstall, go to Tools/Manage User Scripts, +// select "Direct Download Links", and click Uninstall. +// +// -------------------------------------------------------------------- +// +// ==UserScript== +// @name Direct Download Links +// @namespace http://git.ao2.it/GM_direct_download_links.git +// @description Add direct download links for (video) files +// @include http://video.repubblica.it/* +// @include http://tv.repubblica.it/* +// @include http://trovacinema.repubblica.it/* +// @include http://www.kataweb.it/tvzap/* +// ==/UserScript== + +/* + * TODO: + * - find a way to use the same string as in the @include lines to match the + * current window.location + */ + +var supported_sites = [ + { + locationRegexp: /^http:\/\/video\.repubblica\.it\/.*$/, + fileElem: 'contA', + fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, + linkDest: 'contA', + }, + { + locationRegexp: /^http:\/\/tv\.repubblica\.it\/.*$/, + fileElem: 'boxPlayer', + fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, + linkDest: 'box_embed', + }, + { + locationRegexp: /^http:\/\/trovacinema\.repubblica\.it\/.*$/, + fileElem: 'col-center', + fileRegexp: /'flvUrl', '((http|mms):\/\/[^']*)'/, + linkDest: 'col-center', + }, + { + locationRegexp: /^http:\/\/www\.kataweb\.it\/tvzap\/.*$/, + fileElem: 'tvzap_video', + fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, + linkDest: 'playerCont', + }, +]; + +/* Apply different rules to different sites */ +for (i = 0; i < supported_sites.length; i++) { + var site = supported_sites[i]; + + var result = window.location.href.match(site.locationRegexp); + if (result) { + var ret = direct_download_link_add(window.location.href, site.fileElem, site.fileRegexp, site.linkDest); + if (!ret) { + alert('Cannot add the link'); + } + } +} + +/** + * Add a Direct Download link on the page for the specified file + * + * @param pageURL: the URL of the page we are modifying + * @param fileElem: the element containing the file URL + * @param fileRegexp: the regular expression for finding the file, the first + * sub-pattern is taken as the file URL + * @param linkDest: the element where to place the Direct Download link + * + * @return: null on error, true on success + */ +function direct_download_link_add(pageURL, fileElem, fileRegexp, linkDest) { + var element = document.getElementById(fileElem); + if (!element) { + alert('DirectDL (' + pageURL + '): Cannot find the element containing the file URL.'); + return null; + } + + var content = element.textContent; + if (!content) { + alert('DirectDL (' + pageURL + '): textContent is null, cannot fild file URL.'); + } + + var fileURL = content.match(fileRegexp)[1]; + if (!fileURL) { + alert('DirectDL (' + pageURL + '): file URL not found, check the fileRegexp'); + return null; + } + + var links = document.getElementById(linkDest); + if (!links) { + alert('DirectDl (' + pageURL + '): Cannot add the direct download link.'); + return null; + } + + 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); + + links.insertBefore(download_link, links.firstChild); + + return true; +}