From ad2bcfd5510f036a8906bc78089462b910c9b065 Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Fri, 20 Nov 2020 15:20:52 +0100 Subject: [PATCH] Add drag-and-drop support for files --- OOMAnalyser.html | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/OOMAnalyser.html b/OOMAnalyser.html index 2d8cedb..3875668 100644 --- a/OOMAnalyser.html +++ b/OOMAnalyser.html @@ -180,6 +180,31 @@ function goBack() { window.history.back(); } + +// Add listener after the document has been loaded completely +window.addEventListener('DOMContentLoaded', function() { + let dropArea = document.getElementById('input'); + dropArea.addEventListener('drop', file_dragged, false); +}); + +// Event handler triggered if a file has been dragged +function file_dragged(event) { + let file = event.dataTransfer.files[0] + event.preventDefault() + read_and_display_file(file) + return true; +}; + +// Read and display local file +function read_and_display_file(file) { + let reader = new FileReader(); + reader.onload = function(e) { + let textarea_oom = document.getElementById('textarea_oom') + textarea_oom.value = reader.result; + } + reader.readAsText(file); +} + @@ -210,7 +235,13 @@ function goBack() {

Step 1 - Enter your OOM message

- + +
+
+ +

@@ -792,6 +823,7 @@ function goBack() {
  • Fix: Trigger process isn't part of process table
  • Update to Transcrypt 3.7
  • Line "Killed process" can contain the process UID
  • +
  • Add drag-and-drop support for files
  • ...