diff --git a/src/background.ts b/src/background.ts index 1530514..d939e4a 100644 --- a/src/background.ts +++ b/src/background.ts @@ -27,8 +27,8 @@ import { getPeertubeVideoURL } from './util'; * Retrieve the title of the video using Invidious API. */ const getTitle = async (id: string) => { - let data = await InvidiousAPI.getVideo(id); - return data.title; + let data = await InvidiousAPI.getVideo(id); + return data.title; } /** @@ -36,21 +36,21 @@ const getTitle = async (id: string) => { * automatic redirection. */ const preventYoutube = async (r) => { - const prefs = await Preferences.getPreferences(); + const prefs = await Preferences.getPreferences(); - if (prefs.redirectYoutube === 'Auto') { - const query = new URLSearchParams(r.url.substring(r.url.indexOf('?') + 1)); + if (prefs.redirectYoutube === 'Auto') { + const query = new URLSearchParams(r.url.substring(r.url.indexOf('?') + 1)); - let title = await getTitle(query.get('v')); - let video = await searchByName(title); - let url = getPeertubeVideoURL(video, prefs); + let title = await getTitle(query.get('v')); + let video = await searchByName(title); + let url = getPeertubeVideoURL(video, prefs); - return { - redirectUrl: url - }; - } + return { + redirectUrl: url + }; + } - return {}; + return {}; }; const buildSearchByNameURL = (instance: string, query: string): string => `https://${instance}/api/v1/search/videos?search=${encodeURIComponent(query)}`; @@ -93,7 +93,7 @@ browser.runtime.onMessage.addListener(function(message, sender) { }); browser.webRequest.onBeforeRequest.addListener( - preventYoutube, - {urls: ['*://*.youtube.com/watch?v=*']}, - ['blocking'] + preventYoutube, + { urls: ['*://*.youtube.com/watch?v=*'] }, + ['blocking'] ); diff --git a/src/constants.ts b/src/constants.ts index 15be776..7614a01 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,8 +1,8 @@ export default { - defaultInstance: 'peertube.social', - invidiousAPI: { - url: 'https://invidio.us/api/v1', - videos: 'videos', - channels: 'channels' - } + defaultInstance: 'peertube.social', + invidiousAPI: { + url: 'https://invidio.us/api/v1', + videos: 'videos', + channels: 'channels' + } }; diff --git a/src/invidious-api.ts b/src/invidious-api.ts index 767796f..9049d07 100644 --- a/src/invidious-api.ts +++ b/src/invidious-api.ts @@ -2,25 +2,25 @@ import * as _ from 'lodash/fp'; import constants from './constants'; export default class InvidiousAPI { - static async _fetchAPI(action: string, params: any) { - let paramString = typeof params == 'string' - ? params - : Object.keys(params).map(function(key){ - return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); - }).join('&'); + static async _fetchAPI(action: string, params: any) { + let paramString = typeof params == 'string' + ? params + : Object.keys(params).map(function(key) { + return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); + }).join('&'); - return fetch(`${constants.invidiousAPI.url}/${action}/${paramString}`) - .then(res => res.json()) - .catch(e => console.error( - 'An error occured while trying to fetch API used by PeerTubeify: ' - + e.message - )); - } - static async getVideo(id: string) { - return this._fetchAPI(constants.invidiousAPI.videos, id); - } + return fetch(`${constants.invidiousAPI.url}/${action}/${paramString}`) + .then(res => res.json()) + .catch(e => console.error( + 'An error occured while trying to fetch API used by PeerTubeify: ' + + e.message + )); + } + static async getVideo(id: string) { + return this._fetchAPI(constants.invidiousAPI.videos, id); + } - static async getChannel(ucid: string) { - return this._fetchAPI(constants.invidiousAPI.channels, ucid); - } + static async getChannel(ucid: string) { + return this._fetchAPI(constants.invidiousAPI.channels, ucid); + } } diff --git a/src/util.ts b/src/util.ts index 956b162..502d097 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,14 +1,13 @@ export function htmlToElement(html: string): Element { - const template = document.createElement('template'); - template.innerHTML = html.trim(); - return template.content.firstElementChild; + const template = document.createElement('template'); + template.innerHTML = html.trim(); + return template.content.firstElementChild; } export function getPeertubeVideoURL(video, prefs) { return `https://${getPeertubeHost(video.account.host, prefs)}/videos/watch/${video.uuid}` } -export function getPeertubeHost(host, prefs) -{ +export function getPeertubeHost(host, prefs) { return prefs.openInOriginalInstance ? host : prefs.searchInstance; }