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:
parent
a465394457
commit
104598477e
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue