Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * google image search 21 agustus 2026
- * skrep mungkin gk akan hidup selamanya
- * karena perlu kuki NID yang valid
- * kalian bisa generate sendiri kalau semisal kukinya dead ya
- * tapi untuk saat ini mungkin masih bisa digunakan, cb aja
- * btw bs aja valuenya detail isi beberapa info kaya w x h, about url, source url dll
- * tapi aku kasih url image aja biar simple haha
- *
- * @param {string} query
- * @returns {string[]} array of string
- * @throws {Error} kalau error :v
- */
- const googleImageSearch = async (query) => {
- const queryType = typeof query
- if (queryType !== "string" || !query) throw Error(`param query harus string dan gak boleh kosong. ${queryType} diterima`)
- const url = new URL("https://www.google.com")
- url.pathname = "/search"
- url.search = new URLSearchParams({
- "as_st": "y",
- "as_q": query,
- "as_epq": "",
- "as_eq": "",
- "as_sitesearch": "",
- "imgar": "",
- "cr": "",
- "as_filetype": "",
- "tbs": "",
- "authuser": "0",
- "udm": "2",
- "safe": "off", // disable SafeSearch
- "gl": "us", // serve US results - bypasses region-locked SafeSearch
- "hl": "en"
- })
- const r = await fetch(url, {
- "headers": {
- "accept-encoding": "gzip, deflate, br, zstd",
- "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
- "cookie": "NID=534=FRsb06yREkoXVEB8CKNITU5K8HTcx3y741Eg_QDN4MjKxBiuMCD8lcSuZi36lxvEoiUstRhL1COb2LMQZqhfhrHS4OvJIfBK6TZhKzeFNQt6NrgYZDm9LKN0z5fAXb1B02ZMMwImXAHQLO9ogy70znVfQJm6sRtmSFvp20ScBXmUjwx9xE6RX_EdtNBSvB4PGvB-4Tx_eacO31t6eISnAsId8kypbh6oXytpKWK7GBNbdylXU2fSBQTG8xUagI_Q-cwH8Mxt24JPbjiTi1p2FbPXIw",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36"
- },
- });
- const html = await r.text()
- const match = html.match(/var m=(\{.+?\});var a=m/s)
- if (!match) throw Error(`data block gak ketemu, NID kemungkinan udah mati/diflag (status ${r.status}, page ${html.length} bytes)`)
- const res = eval(`(${match[1]})`)
- const imageUrls = Object.keys(res)
- .map(k => res[k]?.[3]?.[0])
- .filter(url => url?.startsWith('http'))
- return imageUrls
- }
- // cara pakai
- try {
- const result = await googleImageSearch("isabelle animal crossing cute fanart") // O.o
- console.log(result)
- } catch (e) {
- console.log(`waduh error\n${e.message}`)
- }
- /* result
- [
- 'https://...60d20d2.png',
- 'https://i....d98.jpg',
- 'https:...45975952',
- 'https://look...',
- ....
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment