Correct formatting
This commit is contained in:
parent
c676af242a
commit
633fa729df
|
@ -27,8 +27,8 @@ import { getPeertubeVideoURL } from './util';
|
||||||
* Retrieve the title of the video using Invidious API.
|
* Retrieve the title of the video using Invidious API.
|
||||||
*/
|
*/
|
||||||
const getTitle = async (id: string) => {
|
const getTitle = async (id: string) => {
|
||||||
let data = await InvidiousAPI.getVideo(id);
|
let data = await InvidiousAPI.getVideo(id);
|
||||||
return data.title;
|
return data.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,21 +36,21 @@ const getTitle = async (id: string) => {
|
||||||
* automatic redirection.
|
* automatic redirection.
|
||||||
*/
|
*/
|
||||||
const preventYoutube = async (r) => {
|
const preventYoutube = async (r) => {
|
||||||
const prefs = await Preferences.getPreferences();
|
const prefs = await Preferences.getPreferences();
|
||||||
|
|
||||||
if (prefs.redirectYoutube === 'Auto') {
|
if (prefs.redirectYoutube === 'Auto') {
|
||||||
const query = new URLSearchParams(r.url.substring(r.url.indexOf('?') + 1));
|
const query = new URLSearchParams(r.url.substring(r.url.indexOf('?') + 1));
|
||||||
|
|
||||||
let title = await getTitle(query.get('v'));
|
let title = await getTitle(query.get('v'));
|
||||||
let video = await searchByName(title);
|
let video = await searchByName(title);
|
||||||
let url = getPeertubeVideoURL(video, prefs);
|
let url = getPeertubeVideoURL(video, prefs);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
redirectUrl: url
|
redirectUrl: url
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildSearchByNameURL = (instance: string, query: string): string => `https://${instance}/api/v1/search/videos?search=${encodeURIComponent(query)}`;
|
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(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
preventYoutube,
|
preventYoutube,
|
||||||
{urls: ['*://*.youtube.com/watch?v=*']},
|
{ urls: ['*://*.youtube.com/watch?v=*'] },
|
||||||
['blocking']
|
['blocking']
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
export default {
|
export default {
|
||||||
defaultInstance: 'peertube.social',
|
defaultInstance: 'peertube.social',
|
||||||
invidiousAPI: {
|
invidiousAPI: {
|
||||||
url: 'https://invidio.us/api/v1',
|
url: 'https://invidio.us/api/v1',
|
||||||
videos: 'videos',
|
videos: 'videos',
|
||||||
channels: 'channels'
|
channels: 'channels'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,25 +2,25 @@ import * as _ from 'lodash/fp';
|
||||||
import constants from './constants';
|
import constants from './constants';
|
||||||
|
|
||||||
export default class InvidiousAPI {
|
export default class InvidiousAPI {
|
||||||
static async _fetchAPI(action: string, params: any) {
|
static async _fetchAPI(action: string, params: any) {
|
||||||
let paramString = typeof params == 'string'
|
let paramString = typeof params == 'string'
|
||||||
? params
|
? params
|
||||||
: Object.keys(params).map(function(key){
|
: Object.keys(params).map(function(key) {
|
||||||
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
|
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
|
||||||
}).join('&');
|
}).join('&');
|
||||||
|
|
||||||
return fetch(`${constants.invidiousAPI.url}/${action}/${paramString}`)
|
return fetch(`${constants.invidiousAPI.url}/${action}/${paramString}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.catch(e => console.error(
|
.catch(e => console.error(
|
||||||
'An error occured while trying to fetch API used by PeerTubeify: '
|
'An error occured while trying to fetch API used by PeerTubeify: '
|
||||||
+ e.message
|
+ e.message
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
static async getVideo(id: string) {
|
static async getVideo(id: string) {
|
||||||
return this._fetchAPI(constants.invidiousAPI.videos, id);
|
return this._fetchAPI(constants.invidiousAPI.videos, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getChannel(ucid: string) {
|
static async getChannel(ucid: string) {
|
||||||
return this._fetchAPI(constants.invidiousAPI.channels, ucid);
|
return this._fetchAPI(constants.invidiousAPI.channels, ucid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
export function htmlToElement(html: string): Element {
|
export function htmlToElement(html: string): Element {
|
||||||
const template = document.createElement('template');
|
const template = document.createElement('template');
|
||||||
template.innerHTML = html.trim();
|
template.innerHTML = html.trim();
|
||||||
return template.content.firstElementChild;
|
return template.content.firstElementChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPeertubeVideoURL(video, prefs) {
|
export function getPeertubeVideoURL(video, prefs) {
|
||||||
return `https://${getPeertubeHost(video.account.host, prefs)}/videos/watch/${video.uuid}`
|
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;
|
return prefs.openInOriginalInstance ? host : prefs.searchInstance;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue