Created
October 13, 2022 21:16
-
-
Save pavi2410/353ed1509a4050be865ea608c414fdf7 to your computer and use it in GitHub Desktop.
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
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
const MAPPINGS = { | |
title: [1, 2, 0, 0], | |
// description: [1, 2, 72, 0, 1], | |
// descriptionHTML: [1, 2, 72, 0, 1], | |
summary: [1, 2, 73, 0, 1], | |
installs: [1, 2, 13, 0], | |
minInstalls: [1, 2, 13, 1], | |
maxInstalls: [1, 2, 13, 2], | |
score: [1, 2, 51, 0, 1], | |
scoreText: [1, 2, 51, 0, 0], | |
ratings: [1, 2, 51, 2, 1], | |
} | |
function traverse(ko, ka) { | |
console.log("____") | |
let o = Object.assign({}, ko) | |
let a = Object.assign({}, ka) | |
while(a.length) { | |
console.log(o, a) | |
o = o[a.shift()] | |
} | |
return o | |
} | |
async function handleRequest(request) { | |
let q = new URL(request.url).searchParams | |
let id = q.get('id') | |
const response = await fetch(`https://play.google.com/store/apps/details?id=${id}&gl=US`) | |
let html = await response.text() | |
let appName = html.match(/<meta property="og:title" content="(.*?) - Apps on Google Play">/)[1] | |
let json = html.match(/AF_initDataCallback\(({key: 'ds:5', .*?})\);<\/script>/)[1] | |
json = json.replace(/({|, )([a-z0-9A-Z_]+?):/g, '$1"$2":').replaceAll("'", '"'); | |
json = JSON.parse(json) | |
json = json.data | |
console.log(json) | |
return Response.json({ | |
appName, | |
data: Object.fromEntries(Object.entries(MAPPINGS).map(([k, v]) => [k, traverse(json, v)])) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment