From ec7bc7941492fb3f84be2c67f068fc496eb51e5d Mon Sep 17 00:00:00 2001 From: Eli Carter Date: Mon, 6 Jun 2022 20:13:44 -0500 Subject: [PATCH 1/6] Find element by ID --- videoskip.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/videoskip.html b/videoskip.html index fd30f83..199611c 100644 --- a/videoskip.html +++ b/videoskip.html @@ -398,7 +398,7 @@

Instructions

makeTimeLabels() }) } - var inputNode = document.querySelector('input') + var inputNode = document.getElementById('videoFile') inputNode.addEventListener('change', playSelectedFile, false) })(); @@ -1510,4 +1510,4 @@

Instructions

blurBox.style.display = 'none' - \ No newline at end of file + From 76893288e1715c56712237d218df9e97bc313de7 Mon Sep 17 00:00:00 2001 From: Eli Carter Date: Sat, 18 Jun 2022 15:22:19 -0500 Subject: [PATCH 2/6] Refactor video loading logic --- videoskip.html | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/videoskip.html b/videoskip.html index 199611c..bdb9985 100644 --- a/videoskip.html +++ b/videoskip.html @@ -389,19 +389,20 @@

Instructions

if (isError) { return } - - var fileURL = URL.createObjectURL(file) - videoNode.src = fileURL; - ready(function(){ - cuts = PF_SRT.parse(skipBox.value); - setActions(); - makeTimeLabels() - }) + loadVideoURL(URL.createObjectURL(file)); } var inputNode = document.getElementById('videoFile') inputNode.addEventListener('change', playSelectedFile, false) })(); +function loadVideoURL(url){ + var videoNode = document.querySelector('video') + videoNode.src = url; + cuts = PF_SRT.parse(skipBox.value); + setActions(); + makeTimeLabels() +} + var displayMessage = function (message, isError) { var element = document.querySelector('#videoMsg') element.innerHTML = message From 252d6e3434183816009a165bd5e5ba98401af6a6 Mon Sep 17 00:00:00 2001 From: Eli Carter Date: Sat, 18 Jun 2022 15:24:02 -0500 Subject: [PATCH 3/6] Refactor skip loading logic --- videoskip.html | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/videoskip.html b/videoskip.html index bdb9985..1edd5b9 100644 --- a/videoskip.html +++ b/videoskip.html @@ -431,32 +431,38 @@

Instructions

} //loads the skip file -function loadFileAsURL(){ +function loadSkipsFromFile(){ var fileToLoad = skipFile.files[0], fileReader = new FileReader(); fileReader.onload = function(fileLoadedEvent){ - var URLFromFileLoaded = fileLoadedEvent.target.result; var extension = fileToLoad.name.slice(-4); if(extension == ".skp"){ - var data = URLFromFileLoaded.split('data:image/jpeg;base64,'); //separate skips and offsets from screenshot - var data1 = data[0].split('{'); //separate skips from offsets - name = fileToLoad.name.slice(0,-4).replace(/ \[[a-z0-9\-]*\]/,''); //remove extension and service list - skipBox.value = data1[0].trim(); - if(data1[1]) offsets = JSON.parse('{' + data1[1].trim()); //make offsets object - if(data[1]) screenShot.src = 'data:image/jpeg;base64,' + data[1] //extract screenshot + loadSkipsData(fileLoadedEvent.target.result); }else{ boxMsg.textContent = "wrong file type" } boxMsg.textContent = 'This is the content of file: ' + fileToLoad.name; - ready(function(){ - cuts = PF_SRT.parse(skipBox.value); - setSliders(); - applyOffset() //this includes setActions at the end - }) }; fileReader.readAsText(fileToLoad) } +function loadSkipsData(skips_data){ + var data, screenshot; + [data, screenshot] = skips_data.split('data:image/jpeg;base64,'); //separate skips and offsets from screenshot + var skips, offsets_json; + [skips, offsets_json] = data.split('{'); //separate skips from offsets + skipBox.value = skips.trim(); + if(offsets) offsets = JSON.parse('{' + offsets_json.trim()); //make offsets object + if(screenshot){ + screenShot.src = 'data:image/jpeg;base64,' + screenshot; //extract screenshot + } else { + screenShot.src = ''; //clear any previous screenshot + } + cuts = PF_SRT.parse(skipBox.value); + setSliders(); + applyOffset() //this includes setActions at the end +} + //similar, for loading subtitles; includes option to generate skips for profanity function loadSubs(){ var fileToLoad = subFile.files[0], @@ -1365,7 +1371,7 @@

Instructions

filters.addEventListener('change', setActions); -skipFile.addEventListener('change', loadFileAsURL); +skipFile.addEventListener('change', loadSkipsFromFile); /* //loads other websites from a select option list function loadPage(){ From e9f6845d37ec503fa58921e4a17c730e6d2d9e02 Mon Sep 17 00:00:00 2001 From: Eli Carter Date: Sat, 18 Jun 2022 15:25:06 -0500 Subject: [PATCH 4/6] Support loading skips from a URL --- videoskip.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/videoskip.html b/videoskip.html index 1edd5b9..6066f3c 100644 --- a/videoskip.html +++ b/videoskip.html @@ -446,6 +446,12 @@

Instructions

fileReader.readAsText(fileToLoad) } +function loadSkipsFromURL(url){ + fetch(url) + .then(response => response.text()) + .then(loadSkipsData); +} + function loadSkipsData(skips_data){ var data, screenshot; [data, screenshot] = skips_data.split('data:image/jpeg;base64,'); //separate skips and offsets from screenshot From 73b83fa71fc829bb18d44c361b930a427be757a0 Mon Sep 17 00:00:00 2001 From: Eli Carter Date: Sat, 18 Jun 2022 15:24:21 -0500 Subject: [PATCH 5/6] Handle URL parameters on page load --- videoskip.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/videoskip.html b/videoskip.html index 6066f3c..0672930 100644 --- a/videoskip.html +++ b/videoskip.html @@ -1521,6 +1521,20 @@

Instructions

dragElement(screenShot); blurBox.style.display = 'none' + +ready(function(){ + // Automatically load the video and skips files from the URL parameters if + // they were provided. + const params = new URLSearchParams(window.location.search); + const video = params.get("video"); + if (video !== null ) { + loadVideoURL(video); + } + const skips = params.get("skips"); + if (skips !== null ) { + loadSkipsFromURL(skips); + } +}); From 2ddcccbf4d599bf7c6be4fb7c837582d977e5eb9 Mon Sep 17 00:00:00 2001 From: Eli Carter Date: Sat, 2 Jul 2022 18:20:27 -0500 Subject: [PATCH 6/6] Improve error handling --- videoskip.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/videoskip.html b/videoskip.html index 0672930..3afdac5 100644 --- a/videoskip.html +++ b/videoskip.html @@ -449,7 +449,10 @@

Instructions

function loadSkipsFromURL(url){ fetch(url) .then(response => response.text()) - .then(loadSkipsData); + .then(loadSkipsData) + .catch(error => { + alert(`Failed to load skips from ${url}: "${error}"`); + }); } function loadSkipsData(skips_data){