2022-03-28 02:07:03 +00:00
|
|
|
// General utility functions for the renderers
|
|
|
|
class rendererUtils {
|
|
|
|
static getNavigationEndpoints(base) {
|
2022-05-02 04:42:56 +00:00
|
|
|
if (!base) return;
|
|
|
|
if (base.urlEndpoint) {
|
|
|
|
const params = new Proxy(new URLSearchParams(base.urlEndpoint.url), {
|
|
|
|
get: (searchParams, prop) => searchParams.get(prop),
|
|
|
|
});
|
2022-04-04 11:33:16 +00:00
|
|
|
if (params.q) return decodeURI(params.q);
|
2022-05-02 04:42:56 +00:00
|
|
|
else return new URL(base.urlEndpoint.url).pathname;
|
|
|
|
} else if (base.browseEndpoint) {
|
|
|
|
return base.browseEndpoint.canonicalBaseUrl;
|
|
|
|
} else if (base.watchEndpoint) {
|
|
|
|
return `/watch?v=${base.watchEndpoint.videoId}`;
|
|
|
|
} else if (base.navigationEndpoint) {
|
2022-03-28 02:07:03 +00:00
|
|
|
return; //for now
|
2022-05-02 04:42:56 +00:00
|
|
|
} else if (base.searchEndpoint) {
|
|
|
|
return `/search?q=${encodeURI(base.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;
|