diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-03-16 17:13:47 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2016-08-15 19:46:45 +0200 |
| commit | 29703fb35afaf888afc8afd0864d9bebf663e59c (patch) | |
| tree | 64e3da9f38d594496fe70c50ed254c1157fb3db6 /js | |
| parent | e589d91be7746b2dbe0fec4fd71ba7857567c6e4 (diff) | |
| download | wvs-vplan-29703fb35afaf888afc8afd0864d9bebf663e59c.tar.gz wvs-vplan-29703fb35afaf888afc8afd0864d9bebf663e59c.zip | |
erster Versuch, ein PDF zu extrahieren [funktioniert nicht]
Diffstat (limited to 'js')
| -rw-r--r-- | js/index.js | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/js/index.js b/js/index.js index 837d5eb..162a810 100644 --- a/js/index.js +++ b/js/index.js @@ -15,21 +15,52 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +function fail(text){ + alert("Etwas ist schiefgelaufen: " + text); +} function download_pdf(link){ - var request = $.ajax({ - type: "GET", - url: link - }); + var filename = link.substring(link.lastIndexOf('/') + 1); - request.done(function(result){ - // TODO - console.log('Plan heruntergeladen'); - }); + window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){ + fileSystem.root.getFile(filename, {create: true, exclusive: false}, function(fileEntry){ + var localPath = fileEntry.fullPath; + if(device.platform == "Android" && localPath.indexOf("file://") == 0){ + localPath = localPath.substring(7); + } + var ft = new FileTransfer(); + ft.download(link, + localPath, function(entry){ + $('#input').attr('src', entry.fullPath); - request.fail(function(jqXHR, textStatus){ - alert("Etwas ist schiefgelaufen: " + textStatus); - }); + var input = document.getElementById("input"); + var processor = document.getElementById("processor"); + var output = document.getElementById("output"); + + window.addEventListener("message", function(event){ + if(event.source != processor.contentWindow) return; + + switch(event.data){ + case "ready": + var xhr = new XMLHttpRequest; + xhr.open("GET", input.getAttribute("src"), true); + xhr.responseType = "arraybuffer"; + + xhr.onload = function(event){ + processor.contentWindow.postMessage(this.response, "*"); + }; + + xhr.send(); + break; + + default: + output.textContent = event.data.replace(/\s+/g, " "); + break; + } + }, true); + }, fail); + }, fail); + }, fail); } function get_plan(link){ @@ -39,7 +70,7 @@ function get_plan(link){ }); request.done(function(result){ - var pdf_re = new RegExp("http://***REMOVED***\\.de/moodle/pluginfile\\.php/\\d+/mod_resource/content/\\d+.*?\\.pdf"); + 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); @@ -63,6 +94,7 @@ function get_overview(link){ var links = plans_re.exec(result); for(var i = 1; i < links.length; i += 2){ + console.log('suche Plan ' + links[i]); get_plan(links[i]); } |
