add channelurlfixer

This commit is contained in:
Ashley 2023-09-13 19:06:20 +00:00
parent ad4924afab
commit 5b90c0d5a4

View file

@ -26,8 +26,7 @@ function linkify(text) {
return text.replace(urlRegex, (url) => { return text.replace(urlRegex, (url) => {
// wrap the URL in an <a> tag with the URL as the href attribute // wrap the URL in an <a> tag with the URL as the href attribute
return `<a href="/api/redirect?u=${btoa( return `<a href="/api/redirect?u=${btoa(url
url
.replace(/twitter\.com/g, "nitter.net") .replace(/twitter\.com/g, "nitter.net")
.replace(/reddit\.com/g, "teddit.net") .replace(/reddit\.com/g, "teddit.net")
.replace("https://youtube.com", "") .replace("https://youtube.com", "")
@ -36,6 +35,15 @@ function linkify(text) {
}); });
} }
function channelurlfixer(text) {
// Create a regular expression to match <a> tags with href containing "/channel/"
const regex = /<a\s+href="\/channel\/([^"]+)"/g;
// Replace matching <a> tags with the modified href attribute
const updatedDescription = text.replace(regex, '<a href="/channel?id=$1"');
return updatedDescription;
}
function endsWithYouTubeAutoGenerated(text) { function endsWithYouTubeAutoGenerated(text) {
const target = " Auto-generated by YouTube. "; const target = " Auto-generated by YouTube. ";
return text.endsWith(target); return text.endsWith(target);
@ -237,6 +245,7 @@ module.exports = function (app, config, renderTemplate) {
if (uaos === "Windows XP" || uaos === "Windows Vista") if (uaos === "Windows XP" || uaos === "Windows Vista")
res.redirect("/lite?v=" + req.query.v); res.redirect("/lite?v=" + req.query.v);
try { try {
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
color: data.color, color: data.color,
@ -244,6 +253,7 @@ module.exports = function (app, config, renderTemplate) {
linkify, linkify,
engagement, engagement,
IsOldWindows, IsOldWindows,
channelurlfixer,
support, support,
u: u.url, u: u.url,
isvidious: u.isInvidiousURL, isvidious: u.isInvidiousURL,