diff --git a/src/background.ts b/src/background.ts index e28b782..41f2511 100644 --- a/src/background.ts +++ b/src/background.ts @@ -39,13 +39,15 @@ const redirectYoutube = async (r) => { const prefs = await Preferences.getPreferences(); if (prefs.redirectYoutube == RedirectType.Auto) { - const isEmbed = r.url.indexOf('embed') >= 0; + const isEmbed = _.contains('embed', r.url); - const query = isEmbed ? r.url.substr(r.url.lastIndexOf('/') + 1, 11) : r.url.substr(r.url.indexOf('?v=') + 3, 11); + const query = isEmbed + ? r.url.substr(r.url.lastIndexOf('/') + 1, 11) + : r.url.substr(r.url.indexOf('?v=') + 3, 11); const title = await getTitle(query); const video = await searchByName(title); - const url = await getPeertubeVideoURL(video, prefs, isEmbed); + const url = getPeertubeVideoURL(video, prefs, isEmbed); return { redirectUrl: url @@ -68,7 +70,8 @@ const redirectPeertube = async (r) => { if (prefs.redirectPeertube == RedirectType.Auto) { const id = _.last(_.split('/', r.url)); const video: any = await PeertubeAPI.getVideo(id); - const isEmbed = r.url.indexOf('embed') >= 0; + + const isEmbed = _.contains('embed', r.url); if (prefs.openInOriginalInstance && video.account.host === hostname) { return {}; // Don't redirect if original instance diff --git a/src/youtube.ts b/src/youtube.ts index 759dc1d..5267af3 100644 --- a/src/youtube.ts +++ b/src/youtube.ts @@ -22,7 +22,7 @@ import { MessageKind, RedirectType } from './types'; import Preferences from './preferences' const thumbnailURL = (host, path) => `https://${host}${path}`; -const isYouTube = document.location.hostname.indexOf('youtube.com') >= 0; +const isYouTube = _.contains('youtube.com', document.location.hostname); const LINK_ID = 'peertube-link'; function searchVideo(query) {