el.xwx.moe/lib/api/getTitle.ts

10 lines
305 B
TypeScript
Raw Normal View History

export default async function getTitle(url: string) {
const response = await fetch(url);
const text = await response.text();
// regular expression to find the <title> tag
let match = text.match(/<title.*>([^<]*)<\/title>/);
2023-06-20 10:04:38 -05:00
if (match) return match[1] + " [AUTO GENERATED]";
else return "";
}