async function searchResults(keyword) { try { const encodedKeyword = encodeURIComponent(keyword); const response = await soraFetch(`https://www.novelcool.com/search/?name=${encodedKeyword}`); const data = await response.text(); const results = []; const regex = /
]*itemtype\s*=\s*["'][^"']*Book[^"']*["'][^>]*>([\s\S]*?)<\/div>\s*<\/div>/g; let match; while ((match = regex.exec(data)) !== null) { const bookItemHTML = match[1]; if (bookItemHTML.includes('book-type-manga')) { continue; } let titleMatch = bookItemHTML.match(/
]*title="([^"]*)"/); let title = ""; if (titleMatch && titleMatch[1]) { title = titleMatch[1].trim(); } else { titleMatch = bookItemHTML.match(/]*\bclass\s*=\s*["'][^"']*book-name[^"']*["'][^>]*itemprop\s*=\s*["']name["'][^>]*>(.*?)<\/div>/); if (titleMatch && titleMatch[1]) { title = titleMatch[1].trim(); } } const hrefMatch = bookItemHTML.match(/]*href\s*=\s*["'](https:\/\/www\.novelcool\.com\/novel\/[^"']*)["'][^>]*itemprop\s*=\s*["']url["']|]*href\s*=\s*["'](https:\/\/www\.novelcool\.com\/novel\/[^"']*)["']/); const href = (hrefMatch && (hrefMatch[1] || hrefMatch[2])) ? (hrefMatch[1] || hrefMatch[2]).trim() : ''; const imgTagMatch = bookItemHTML.match(/]*itemprop\s*=\s*["']image["'][^>]*>/i); let image = ''; if (imgTagMatch) { const imgTag = imgTagMatch[0]; const srcMatch = imgTag.match(/\bsrc\s*=\s*["']([^"']*)["']/i); if (srcMatch && srcMatch[1]) { image = srcMatch[1].trim(); } } if (title && href) { results.push({ title: title, href: href, image: image }); } } console.log("Search Results:", results); return JSON.stringify(results); } catch (error) { console.error('Fetch error in searchResults:', error); return JSON.stringify([{ title: 'Error', href: '', image: '' }]); } } async function extractDetails(url) { try { const response = await soraFetch(url); const htmlText = await response.text(); const descriptionMatch = htmlText.match(/
]*>([\s\S]*?)<\/div>/); const description = descriptionMatch ? descriptionMatch[1].trim() : 'No description available'; const transformedResults = [{ description, aliases: 'N/A', airdate: 'N/A' }]; console.log(JSON.stringify(transformedResults)); return JSON.stringify(transformedResults); } catch (error) { console.log('Details error:', error); return JSON.stringify([{ description: 'Error loading description', aliases: 'N/A', airdate: 'N/A' }]); } } async function extractChapters(url) { try { const response = await soraFetch(url); const htmlText = await response.text(); const rawChapters = []; const regex = /