From 2be2301d92e37d13a4839ded1fc436836292b7d4 Mon Sep 17 00:00:00 2001 From: PrestonN Date: Mon, 10 Jan 2022 21:16:50 -0500 Subject: [PATCH] Prevent middle click from opening URLs within the app --- src/renderer/App.js | 68 +++++++++++-------- .../ft-video-player/ft-video-player.js | 15 ++-- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/renderer/App.js b/src/renderer/App.js index ec2ebd13..f3eaecd6 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -41,7 +41,6 @@ export default Vue.extend({ latestBlogUrl: '', updateChangelog: '', changeLogTitle: '', - lastExternalLinkToBeOpened: '', showExternalLinkOpeningPrompt: false, externalLinkOpeningPromptValues: [ @@ -313,32 +312,40 @@ export default Vue.extend({ openAllLinksExternally: function () { $(document).on('click', 'a[href^="http"]', (event) => { - const el = event.currentTarget - console.log(this.usingElectron) - console.log(el) - event.preventDefault() - - // Check if it's a YouTube link - const youtubeUrlPattern = /^https?:\/\/((www\.)?youtube\.com(\/embed)?|youtu\.be)\/.*$/ - const isYoutubeLink = youtubeUrlPattern.test(el.href) - - if (isYoutubeLink) { - this.handleYoutubeLink(el.href) - } else if (this.externalLinkHandling === 'doNothing') { - // Let user know opening external link is disabled via setting - this.showToast({ - message: this.$t('External link opening has been disabled in the general settings') - }) - } else if (this.externalLinkHandling === 'openLinkAfterPrompt') { - // Storing the URL is necessary as - // there is no other way to pass the URL to click callback - this.lastExternalLinkToBeOpened = el.href - this.showExternalLinkOpeningPrompt = true - } else { - // Open links externally - this.openExternalLink(el.href) - } + this.handleLinkClick(event) }) + + $(document).on('auxclick', 'a[href^="http"]', (event) => { + this.handleLinkClick(event) + }) + }, + + handleLinkClick: function (event) { + const el = event.currentTarget + console.log(this.usingElectron) + console.log(el) + event.preventDefault() + + // Check if it's a YouTube link + const youtubeUrlPattern = /^https?:\/\/((www\.)?youtube\.com(\/embed)?|youtu\.be)\/.*$/ + const isYoutubeLink = youtubeUrlPattern.test(el.href) + + if (isYoutubeLink) { + this.handleYoutubeLink(el.href) + } else if (this.externalLinkHandling === 'doNothing') { + // Let user know opening external link is disabled via setting + this.showToast({ + message: this.$t('External link opening has been disabled in the general settings') + }) + } else if (this.externalLinkHandling === 'openLinkAfterPrompt') { + // Storing the URL is necessary as + // there is no other way to pass the URL to click callback + this.lastExternalLinkToBeOpened = el.href + this.showExternalLinkOpeningPrompt = true + } else { + // Open links externally + this.openExternalLink(el.href) + } }, handleYoutubeLink: function (href) { @@ -445,15 +452,16 @@ export default Vue.extend({ } }, - ...mapMutations([ - 'setInvidiousInstancesList' - ]), - setWindowTitle: function() { if (this.windowTitle !== null) { document.title = this.windowTitle } }, + + ...mapMutations([ + 'setInvidiousInstancesList' + ]), + ...mapActions([ 'showToast', 'openExternalLink', diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index 2c69c3f1..f7414408 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -1620,12 +1620,6 @@ export default Vue.extend({ } }, - ...mapActions([ - 'calculateColorLuminance', - 'updateDefaultCaptionSettings', - 'showToast', - 'sponsorBlockSkipSegments' - ]), addPlayerStatsEvent: function() { this.stats.videoId = this.videoId this.player.on('volumechange', () => { @@ -1704,6 +1698,13 @@ export default Vue.extend({ break } } - } + }, + + ...mapActions([ + 'calculateColorLuminance', + 'updateDefaultCaptionSettings', + 'showToast', + 'sponsorBlockSkipSegments' + ]) } })