diff options
Diffstat (limited to 'js/index.js')
| -rw-r--r-- | js/index.js | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/js/index.js b/js/index.js index 5ef44b7..d78c6ea 100644 --- a/js/index.js +++ b/js/index.js @@ -16,14 +16,55 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +function download_pdf(link){ + var request = $.fileDownload(link); + + request.done(function(result){ + // TODO + console.log('Plan heruntergeladen'); + }); + + request.fail(function(jqXHR, textStatus){ + alert("Etwas ist schiefgelaufen: " + textStatus); + }); +} + +function get_plan(link){ + var request = $.ajax({ + type: "GET", + url: link + }); + + request.done(function(result){ + var pdf_re = new RegExp("http://***REMOVED***\\.de/moodle/pluginfile\\.php/\\d+/mod_resource/content/\\d+.*?\\.pdf"); + var pdflink = pdf_re.exec(result)[1]; + + console.log('Plan gefunden: ' + pdflink); + + download_pdf(pdflink); + }); + + request.fail(function(jqXHR, textStatus){ + alert("Etwas ist schiefgelaufen: " + textStatus); + }); +} + function get_overview(link){ var request = $.ajax({ type: "GET", url: link }); - request.done(function(msg){ + request.done(function(result){ + var plans_re = new RegExp("window\\.open\\'(http://***REMOVED***\\.de/moodle/mod/resource/view\\.php\\?id=\\d+)&redirect=1'\\)"); + var links = plans_re.exec(result); + + for(var i = 1; i < links.length; i += 2){ + get_plan(links[i]); + } + console.log('Übersichts-Request erfolgreich'); + location.href = '#overview'; }); |
