addEventListener('fetch', event => { let response = handleRequest(event.request); const origin = event.request.headers.get('Origin'); if ([ 'http://localhost', 'https://akarin.dev', 'https://transparentlc.github.io', // Add other mirrors ].includes(origin)) { response = response.then(e => { e.headers.set('Access-Control-Allow-Origin', origin); return e; }); } event.respondWith(response); }); /** * Respond to the request * @param {Request} request */ async function handleRequest(request) { const result = { success: false, title: '', cover: '', }; const responseConfig = { status: 200, headers: { 'Content-Type': 'application/json', }, } const articleURL = new URL(request.url).searchParams.get('url'); try { if (!articleURL || !articleURL.startsWith('https://mp.weixin.qq.com')) throw new Error('Invalid URL'); const articleContent = await fetch(articleURL).then(res => res.text()); const match = articleContent.match( /var msg_title = \'(?