2022-03-28 02:07:03 +00:00
|
|
|
// General utility functions for the renderers
|
|
|
|
class rendererUtils {
|
|
|
|
static getNavigationEndpoints(base) {
|
|
|
|
const navEndpoint = base.navigationEndpoint;
|
|
|
|
if (!navEndpoint) return;
|
2022-04-04 11:33:16 +00:00
|
|
|
if (navEndpoint.urlEndpoint) {
|
|
|
|
const params = new Proxy(
|
|
|
|
new URLSearchParams(navEndpoint.urlEndpoint.url),
|
|
|
|
{
|
|
|
|
get: (searchParams, prop) => searchParams.get(prop),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (params.q) return decodeURI(params.q);
|
|
|
|
else return new URL(navEndpoint.urlEndpoint.url).pathname;
|
2022-03-28 02:07:03 +00:00
|
|
|
} else if (navEndpoint.browseEndpoint) {
|
|
|
|
return navEndpoint.browseEndpoint.canonicalBaseUrl;
|
|
|
|
} else if (navEndpoint.watchEndpoint) {
|
|
|
|
return `/watch?v=${navEndpoint.watchEndpoint.videoId}`;
|
|
|
|
} else if (navEndpoint.navigationEndpoint) {
|
|
|
|
return; //for now
|
2022-04-04 11:33:16 +00:00
|
|
|
} else if (navEndpoint.searchEndpoint) {
|
|
|
|
return `/search?q=${encodeURI(navEndpoint.searchEndpoint.query)}`;
|
2022-03-28 02:07:03 +00:00
|
|
|
}
|
2022-03-21 23:47:11 +00:00
|
|
|
}
|
2022-03-20 12:20:13 +00:00
|
|
|
|
2022-03-28 02:07:03 +00:00
|
|
|
static checkInternal(base) {
|
2022-04-04 11:33:16 +00:00
|
|
|
const tmp = document.createElement("a");
|
|
|
|
tmp.href = this.getNavigationEndpoints(base);
|
|
|
|
if (tmp.host !== window.location.host || !base.navigationEndpoint) {
|
2022-03-28 02:07:03 +00:00
|
|
|
return false;
|
2022-04-04 11:33:16 +00:00
|
|
|
} else {
|
|
|
|
return true;
|
2022-03-28 02:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-20 12:20:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 02:07:03 +00:00
|
|
|
export default rendererUtils;
|