Created
March 14, 2023 17:05
-
-
Save hashtafak/f94ed822932a82c0165f9dd5fac1ab21 to your computer and use it in GitHub Desktop.
Cloudflare Worker ICQ UIN Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
async fetch(request, env) { | |
/** | |
* gatherResponse awaits and returns a response body as a string. | |
* Use await gatherResponse(..) in an async function to get the response body | |
* @param {Response} response | |
*/ | |
async function gatherResponse(response) { | |
const { | |
headers | |
} = response; | |
const contentType = headers.get('content-type') || ''; | |
if (contentType.includes('application/json')) { | |
return JSON.stringify(await response.json()); | |
} else if (contentType.includes('application/text')) { | |
return response.text(); | |
} else if (contentType.includes('text/html')) { | |
return response.text(); | |
} else { | |
return response.text(); | |
} | |
} | |
try { | |
const { | |
pathname | |
} = new URL(request.url); | |
if (pathname.startsWith("/uin")) { | |
const username = (pathname.split("/")[2]); | |
console.log(username); | |
const response = await fetch("https://icq.im/" + username); | |
const results = await gatherResponse(response); | |
const uinREG = /href="\/\/web\.icq\.com\/chat\/(.*?)"/ | |
const nameREG = /<h2 class="icq-profile__name">(.*?)<\/h2>/; | |
const profileName = nameREG.exec(results); | |
if (profileName !== null && profileName.length > 1) console.log(profileName[1]) | |
const uin = uinREG.exec(results); | |
if (uin !== null && uin.length > 1) console.log(uin[1]) | |
return new Response(`<!DOCTYPE html><html><head><title>${username}|${profileName[1]}|${uin[1]}</title><meta name="description" content="${username}|${profileName[1]}|${uin[1]}"></head><body>${username}|${profileName[1]}|${uin[1]}</body></html>`, { | |
headers: { | |
'content-type': 'text/html', | |
}, | |
}); | |
} | |
return new Response('usage: https://---.---.workers.dev/uin/ICQ_username', { | |
headers: { | |
'content-type': 'text/html', | |
}, | |
}); | |
} catch (e) { | |
return new Response(err.stack, { | |
status: 500 | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment