Update transcript-tracer.js
Browse files- transcript-tracer.js +7 -91
transcript-tracer.js
CHANGED
@@ -466,8 +466,11 @@ function clearHighlightedWords(transcript) {
|
|
466 |
function handleWordClick(e) {
|
467 |
var wordElement = e.currentTarget;
|
468 |
var wordIndex = wordElement.dataset.ttWord;
|
|
|
|
|
|
|
469 |
var transcript = wordElement.closest('.tt-transcript');
|
470 |
-
var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
|
471 |
var startSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[wordIndex].startSeconds
|
472 |
|
473 |
ttLinkedDataByMediaUrl[mediaUrl].mediaElement.currentTime = startSeconds;
|
@@ -496,6 +499,9 @@ function handleWordClick(e) {
|
|
496 |
function handleWordDBClick(e) {
|
497 |
var wordElement = e.currentTarget;
|
498 |
var wordIndex = wordElement.dataset.ttWord;
|
|
|
|
|
|
|
499 |
var transcript = wordElement.closest('.tt-transcript');
|
500 |
var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
|
501 |
var startSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[wordIndex].startSeconds
|
@@ -609,8 +615,6 @@ function handleSelection() {
|
|
609 |
console.log(startWordListIndexForTime);
|
610 |
console.log(startSeconds);
|
611 |
|
612 |
-
// return
|
613 |
-
|
614 |
// ====================================================================================================
|
615 |
|
616 |
var endNode = selection.extentNode;
|
@@ -669,102 +673,14 @@ function handleSelection() {
|
|
669 |
return
|
670 |
|
671 |
// ====================================================================================================
|
672 |
-
|
673 |
-
// Used for computing the start seconds
|
674 |
-
|
675 |
-
|
676 |
-
// ====================================================================================================
|
677 |
-
|
678 |
-
var endNode = temp.extentNode;
|
679 |
-
|
680 |
-
var wordElement = endNode.parentNode;
|
681 |
-
var need_adjustment = true;
|
682 |
-
while (wordElement.className == "tt-whitespace") {
|
683 |
-
wordElement = wordElement.nextElementSibling;
|
684 |
-
need_adjustment = false;
|
685 |
-
}
|
686 |
-
|
687 |
-
var wordIndex = wordElement.dataset.ttWord;
|
688 |
-
var transcript = wordElement.closest('.tt-transcript');
|
689 |
-
var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
|
690 |
-
|
691 |
-
var endSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[wordIndex].endSeconds;
|
692 |
-
// adjustment
|
693 |
-
var targetEndIndex = parseInt(wordIndex)+1;
|
694 |
-
if (!need_adjustment) targetEndIndex = wordIndex;
|
695 |
-
targetEndIndex = targetEndIndex.toString();
|
696 |
-
|
697 |
-
if (targetEndIndex < ttLinkedDataByMediaUrl[mediaUrl].wordTimings.length) {
|
698 |
-
endSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[targetEndIndex].startSeconds;
|
699 |
-
}
|
700 |
-
|
701 |
-
var endWordIndex = parseInt(wordIndex);
|
702 |
-
if (!need_adjustment) endWordIndex = endWordIndex - 1;
|
703 |
-
endWordIndex = endWordIndex.toString();
|
704 |
-
// ? How to get this
|
705 |
-
// var endWordElement = startWordElement;
|
706 |
-
|
707 |
-
console.log(endSeconds);
|
708 |
-
|
709 |
-
console.log(startWordElement);
|
710 |
-
console.log(startWordIndex);
|
711 |
-
console.log(endWordIndex);
|
712 |
-
console.log(temp);
|
713 |
-
|
714 |
// Mark selection
|
715 |
|
716 |
-
var currentWordElement = startWordElement;
|
717 |
-
while (true) {
|
718 |
-
if (currentWordElement == null) break;
|
719 |
-
var isWhite = currentWordElement.className == "tt-whitespace";
|
720 |
-
var index = -1;
|
721 |
-
if (!isWhite) {
|
722 |
-
var index = currentWordElement.dataset.ttWord;
|
723 |
-
}
|
724 |
-
if (parseInt(index) > parseInt(endWordIndex)) {
|
725 |
-
break;
|
726 |
-
}
|
727 |
-
if (isWhite) {
|
728 |
-
var nextIndex = currentWordElement.nextElementSibling.dataset.ttWord;
|
729 |
-
if (parseInt(nextIndex) > parseInt(endWordIndex)) {
|
730 |
-
break;
|
731 |
-
}
|
732 |
-
}
|
733 |
-
console.log(currentWordElement);
|
734 |
-
currentWordElement = currentWordElement.nextElementSibling;
|
735 |
-
|
736 |
-
// var wordElements = ttCurrentTranscript.querySelectorAll(`[data-tt-word="${wordIndex}"]`);
|
737 |
-
// for (const wordElement of wordElements) wordElement.classList.add('tt-current-word');
|
738 |
-
}
|
739 |
-
|
740 |
-
console.log(transcript);
|
741 |
-
console.log(transcript.children);
|
742 |
-
console.log(transcript.children[0]);
|
743 |
-
console.log(transcript.children[0].children);
|
744 |
|
745 |
-
var dict = {};
|
746 |
-
var nodes = [];
|
747 |
-
var listIndex = -1;
|
748 |
-
for (const x of transcript.children) {
|
749 |
-
for (const y of x.children) {
|
750 |
-
nodes.push(y);
|
751 |
-
listIndex = listIndex + 1;
|
752 |
-
if (y.className != "tt-whitespace") {
|
753 |
-
wordElement = y;
|
754 |
-
wordIndex = wordElement.dataset.ttWord;
|
755 |
-
dict[wordIndex] = listIndex;
|
756 |
-
}
|
757 |
-
}
|
758 |
-
}
|
759 |
-
console.log(nodes);
|
760 |
-
console.log(dict);
|
761 |
-
|
762 |
// for (const wordElement of ttCurrentTranscript.getElementsByClassName('tt-word')) {
|
763 |
// if (wordElement.classList.contains('tt-current-word')) break;
|
764 |
// wordElement.classList.add('tt-previous-word');
|
765 |
// }
|
766 |
|
767 |
-
|
768 |
}
|
769 |
|
770 |
loadTranscriptTracer({ blockSelector: null, phraseSelector: null, alignmentFuzziness: 0, timeOffset: 0, autoScroll: "word", clickable: true})
|
|
|
466 |
function handleWordClick(e) {
|
467 |
var wordElement = e.currentTarget;
|
468 |
var wordIndex = wordElement.dataset.ttWord;
|
469 |
+
|
470 |
+
if (wordElement.className == "tt-whitespace" || wordIndex === undefined) return;
|
471 |
+
|
472 |
var transcript = wordElement.closest('.tt-transcript');
|
473 |
+
var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
|
474 |
var startSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[wordIndex].startSeconds
|
475 |
|
476 |
ttLinkedDataByMediaUrl[mediaUrl].mediaElement.currentTime = startSeconds;
|
|
|
499 |
function handleWordDBClick(e) {
|
500 |
var wordElement = e.currentTarget;
|
501 |
var wordIndex = wordElement.dataset.ttWord;
|
502 |
+
|
503 |
+
if (wordElement.className == "tt-whitespace" || wordIndex === undefined) return;
|
504 |
+
|
505 |
var transcript = wordElement.closest('.tt-transcript');
|
506 |
var mediaUrl = transcript.dataset.ttCurrentMediaUrl;
|
507 |
var startSeconds = ttLinkedDataByMediaUrl[mediaUrl].wordTimings[wordIndex].startSeconds
|
|
|
615 |
console.log(startWordListIndexForTime);
|
616 |
console.log(startSeconds);
|
617 |
|
|
|
|
|
618 |
// ====================================================================================================
|
619 |
|
620 |
var endNode = selection.extentNode;
|
|
|
673 |
return
|
674 |
|
675 |
// ====================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
676 |
// Mark selection
|
677 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
678 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
679 |
// for (const wordElement of ttCurrentTranscript.getElementsByClassName('tt-word')) {
|
680 |
// if (wordElement.classList.contains('tt-current-word')) break;
|
681 |
// wordElement.classList.add('tt-previous-word');
|
682 |
// }
|
683 |
|
|
|
684 |
}
|
685 |
|
686 |
loadTranscriptTracer({ blockSelector: null, phraseSelector: null, alignmentFuzziness: 0, timeOffset: 0, autoScroll: "word", clickable: true})
|