mirror of
https://github.com/demostf/cutter.git
synced 2026-06-03 11:54:08 +02:00
auto ticks and naming
This commit is contained in:
parent
e08617bcf0
commit
d151938cc8
5 changed files with 43 additions and 18 deletions
23
www/index.js
23
www/index.js
|
|
@ -4,7 +4,11 @@ import {cut} from "democutter";
|
|||
let fileSelect = document.getElementById('file');
|
||||
let startInput = document.getElementById('start');
|
||||
let endInput = document.getElementById('end');
|
||||
fileSelect.addEventListener('change', (event) => {
|
||||
let cutButton = document.getElementById('cut');
|
||||
|
||||
let outputName = "cut.dem";
|
||||
|
||||
cutButton.addEventListener('click', (event) => {
|
||||
let start = parseInt(startInput.value);
|
||||
let end = parseInt(endInput.value);
|
||||
console.log(start, end);
|
||||
|
|
@ -15,10 +19,25 @@ fileSelect.addEventListener('change', (event) => {
|
|||
console.log(reader.result);
|
||||
let result = cut(new Uint8Array(reader.result), start, end);
|
||||
fileSelect.disabled = false;
|
||||
save(result, "cut.dem");
|
||||
save(result, outputName);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
fileSelect.addEventListener('change', (event) => {
|
||||
const tickRate = 66;
|
||||
let name = fileSelect.files[0].name;
|
||||
let match = name.match(/^([^_]+)_(\d+)\.dem$/);
|
||||
if (match) {
|
||||
let highlightTick = parseInt(match[2]);
|
||||
startInput.value = highlightTick - tickRate * 10;
|
||||
endInput.value = highlightTick + tickRate * 5 * 60;
|
||||
outputName = `${match[1]}_${tickRate * 10}.dem`;
|
||||
} else {
|
||||
outputName = name.replace(/\.dem/, "_cut.dem");
|
||||
}
|
||||
});
|
||||
|
||||
function save(data, fileName) {
|
||||
let a = document.createElement("a");
|
||||
document.body.appendChild(a);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue