Use lodash's `contains` function instead of checking indexOf

Because I love not having to think what code does. Functions rule.
This commit is contained in:
Ealhad 2019-02-18 15:38:58 +01:00
parent a465394457
commit 104598477e
2 changed files with 8 additions and 5 deletions

View File

@ -39,13 +39,15 @@ const redirectYoutube = async (r) => {
const prefs = await Preferences.getPreferences(); const prefs = await Preferences.getPreferences();
if (prefs.redirectYoutube == RedirectType.Auto) { 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 title = await getTitle(query);
const video = await searchByName(title); const video = await searchByName(title);
const url = await getPeertubeVideoURL(video, prefs, isEmbed); const url = getPeertubeVideoURL(video, prefs, isEmbed);
return { return {
redirectUrl: url redirectUrl: url
@ -68,7 +70,8 @@ const redirectPeertube = async (r) => {
if (prefs.redirectPeertube == RedirectType.Auto) { if (prefs.redirectPeertube == RedirectType.Auto) {
const id = _.last(_.split('/', r.url)); const id = _.last(_.split('/', r.url));
const video: any = await PeertubeAPI.getVideo(id); 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) { if (prefs.openInOriginalInstance && video.account.host === hostname) {
return {}; // Don't redirect if original instance return {}; // Don't redirect if original instance

View File

@ -22,7 +22,7 @@ import { MessageKind, RedirectType } from './types';
import Preferences from './preferences' import Preferences from './preferences'
const thumbnailURL = (host, path) => `https://${host}${path}`; 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'; const LINK_ID = 'peertube-link';
function searchVideo(query) { function searchVideo(query) {