console.log("Parsing result...");
// Use regex to search for src=""
const regex = /src="([^"]*)"/g;
const matches = [...result.matchAll(regex)].map((match) => match[1]);
// Remove Bad Images(https://r.bing.com/rp/xxx)
const safe_image_links = matches.filter(link => !/r.bing.com\/rp/i.test(link))
// Remove size limit
const normal_image_links = safe_image_links.map(link => (link.split("?w=")[0]));
// Remove duplicates
const unique_image_links = [...new Set(normal_image_links)];
// No images
if (unique_image_links.length === 0) {
throw new Error("error_no_images");
}
return unique_image_links;