From: Antonio Ospite Date: Thu, 8 Dec 2011 18:57:38 +0000 (+0100) Subject: Rename fileElem to urlContainer and fileRegexp to urlRegexp X-Git-Tag: 0.3~15 X-Git-Url: https://git.ao2.it/GM_direct_download_links.git/commitdiff_plain/2638b96a6a4a02f75f1569fd52e4a18465a82ebd?ds=sidebyside;hp=d0aadfa63348eab5239adb51f6db2c988980363a Rename fileElem to urlContainer and fileRegexp to urlRegexp We are dealing with URL in general, not necessarily with static files on the server. --- diff --git a/direct_download_links.user.js b/direct_download_links.user.js index 452e2a4..e3707a1 100644 --- a/direct_download_links.user.js +++ b/direct_download_links.user.js @@ -1,4 +1,4 @@ -// direct_download_links - Add direct download links for (video) files +// direct_download_links - Add direct download links // version 0.2 // 2011-11-14 // Copyright (C) 2011 Antonio Ospite @@ -22,7 +22,7 @@ // ==UserScript== // @name Direct Download Links // @namespace http://git.ao2.it/GM_direct_download_links.git -// @description Add direct download links for (video) files +// @description Add direct download links // @include http://video.repubblica.it/* // @include http://tv.repubblica.it/* // @include http://trovacinema.repubblica.it/* @@ -40,26 +40,26 @@ var supported_sites = [ { locationRegexp: /^http:\/\/video\.repubblica\.it\/.*$/, - fileElem: 'contA', - fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, + urlContainer: 'contA', + urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, linkDest: 'contA', }, { locationRegexp: /^http:\/\/tv\.repubblica\.it\/.*$/, - fileElem: 'boxPlayer', - fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, + urlContainer: 'boxPlayer', + urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, linkDest: 'box_embed', }, { locationRegexp: /^http:\/\/trovacinema\.repubblica\.it\/.*$/, - fileElem: 'col-center', - fileRegexp: /'flvUrl', '((http|mms):\/\/[^']*)'/, + urlContainer: 'col-center', + urlRegexp: /'flvUrl', '((http|mms):\/\/[^']*)'/, linkDest: 'col-center', }, { locationRegexp: /^http:\/\/www\.kataweb\.it\/tvzap\/.*$/, - fileElem: 'tvzap_video', - fileRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, + urlContainer: 'tvzap_video', + urlRegexp: /'pcUrl', '((http|mms):\/\/[^']*)'/, linkDest: 'playerCont', }, ]; @@ -70,7 +70,7 @@ for (i = 0; i < supported_sites.length; 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); + var ret = direct_download_link_add(window.location.href, site.urlContainer, site.urlRegexp, site.linkDest); if (!ret) { alert('Cannot add the link'); } @@ -78,35 +78,35 @@ for (i = 0; i < supported_sites.length; i++) { } /** - * Add a Direct Download link on the page for the specified file + * Add a Direct Download link on the page for the specified URL * * @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 urlContainer: the element containing the URL to link + * @param urlRegexp: the regular expression for finding the URL, the first + * sub-pattern is taken as the 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); +function direct_download_link_add(pageURL, urlContainer, urlRegexp, linkDest) { + var element = document.getElementById(urlContainer); if (!element) { - alert('DirectDL (' + pageURL + '): Cannot find the element ' + fileElem + ' containing the file URL.'); + alert('DirectDL (' + pageURL + '): Cannot find the element ' + urlContainer + ' containing the URL.'); return null; } var content = element.innerHTML; if (!content) { - alert('DirectDL (' + pageURL + '): content is null, cannot find file URL.'); + alert('DirectDL (' + pageURL + '): content is null, cannot find URL.'); return null; } - var matches = content.match(fileRegexp); + var matches = content.match(urlRegexp); if (!matches || matches.length < 2 || !matches[1]) { - alert('DirectDL (' + pageURL + '): file URL not found, check the fileRegexp'); + alert('DirectDL (' + pageURL + '): URL not found, check the urlRegexp'); return null; } - var fileURL = matches[1]; + var URL = matches[1]; var links = document.getElementById(linkDest); if (!links) { @@ -116,7 +116,7 @@ function direct_download_link_add(pageURL, fileElem, fileRegexp, linkDest) { var download_link = document.createElement('a'); download_link.textContent = 'Direct Link'; - download_link.setAttribute('href', fileURL); + download_link.setAttribute('href', URL); var style = 'background-color: white; color: blue;'; style += ' border: 2px solid red;' style += ' float: right; font-size: large;';