el.xwx.moe/lib/api/getTitle.ts
2023-06-27 03:05:12 +03:30

14 lines
369 B
TypeScript

export default async function getTitle(url: string) {
try {
const response = await fetch(url);
const text = await response.text();
// regular expression to find the <title> tag
let match = text.match(/<title.*>([^<]*)<\/title>/);
if (match) return match[1] + " [AUTO GENERATED]";
else return "";
} catch (err) {
console.log(err);
}
}