From 7cb396fcce18ecdce3dff9e745ab11e9dcc67749 Mon Sep 17 00:00:00 2001 From: Mykyta Poturai Date: Sat, 19 Sep 2020 19:19:58 +0300 Subject: [PATCH] Make timestamps clickable Replaces timestamps in comments and description with links that set current video timestamp when clicked. --- .../ft-timestamp-catcher.css | 0 .../ft-timestamp-catcher.js | 26 +++++++++++++++++++ .../ft-timestamp-catcher.vue | 9 +++++++ .../watch-video-comments.js | 8 +++++- .../watch-video-comments.vue | 8 +++--- .../watch-video-description.js | 7 ++++- .../watch-video-description.vue | 5 ++-- src/renderer/views/Watch/Watch.js | 3 +++ src/renderer/views/Watch/Watch.vue | 2 ++ 9 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.css create mode 100644 src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.js create mode 100644 src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.vue diff --git a/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.css b/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.css new file mode 100644 index 00000000..e69de29b diff --git a/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.js b/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.js new file mode 100644 index 00000000..b66b234e --- /dev/null +++ b/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.js @@ -0,0 +1,26 @@ +import Vue from 'vue' + +export default Vue.extend({ + name: 'FtTimestampCatcher', + props: { + inputHTML: { + type: String, + default: '' + } + }, + methods: { + catchTimestampClick: function(event) { + const match = event.detail.match(/(\d+):(\d+):?(\d+)?/) + if (match[3] !== undefined) { // HH:MM:SS + const seconds = 3600 * Number(match[1]) + 60 * Number(match[2]) + Number(match[3]) + this.$emit('timestampEvent', seconds) + } else { // MM:SS + const seconds = 60 * Number(match[1]) + Number(match[2]) + this.$emit('timestampEvent', seconds) + } + }, + detectTimestamps: function (input) { + return input.replaceAll(/(\d+(:\d+)+)/g, '$1') + } + } +}) diff --git a/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.vue b/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.vue new file mode 100644 index 00000000..034da7c8 --- /dev/null +++ b/src/renderer/components/ft-timestamp-catcher/ft-timestamp-catcher.vue @@ -0,0 +1,9 @@ + + +