From 633fa729df2072faf1ed8fd1ca57137785f8638c Mon Sep 17 00:00:00 2001 From: Ealhad Date: Mon, 12 Nov 2018 15:24:12 +0100 Subject: [PATCH] Correct formatting --- src/background.ts | 32 ++++++++++++++++---------------- src/constants.ts | 12 ++++++------ src/invidious-api.ts | 38 +++++++++++++++++++------------------- src/util.ts | 9 ++++----- 4 files changed, 45 insertions(+), 46 deletions(-) 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; }