1
0
mirror of https://gitlab.com/Cha_deL/peertubeify synced 2024-12-21 20:34:23 +01:00

Correct formatting

This commit is contained in:
Ealhad 2018-11-12 15:24:12 +01:00
parent c676af242a
commit 633fa729df
4 changed files with 45 additions and 46 deletions

View File

@ -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']
);

View File

@ -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'
}
};

View File

@ -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);
}
}

View File

@ -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;
}