Created
May 1, 2026 11:39
-
-
Save ItsFelix5/5889641d6c450d72c925a538f6aa1565 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { launch } from "puppeteer"; | |
| import { format } from "prettier"; | |
| // Go to slack | |
| const browser = await launch(); | |
| browser.setCookie({ | |
| name: "d", | |
| value: process.env.SLACK_COOKIE!, | |
| domain: ".slack.com", | |
| }); | |
| const page = await browser.newPage(); | |
| await page.goto("https://app.slack.com/client", { waitUntil: "load" }); | |
| // Extract all webpack chunks | |
| const result = (await page.evaluate( | |
| () => | |
| new Promise((r) => | |
| webpackChunkwebapp.push([ | |
| [Symbol()], | |
| {}, | |
| (wpRequire) => { | |
| let chunks: Record<string, string> = {}; | |
| const fn = wpRequire.u.toString(); | |
| const regex = /if\s*\(\s*["']([^"']+)["']\s*===\s*e\s*\)/g; | |
| let match; | |
| while ((match = regex.exec(fn)) !== null) { | |
| if (match[1]) | |
| chunks[match[1]] = wpRequire.u(match[1])?.split("?")[0]!; | |
| } | |
| r(chunks); | |
| }, | |
| ]), | |
| ), | |
| )) as Record<string, string>; | |
| await page.close(); | |
| await browser.close(); | |
| // Save updated chunks | |
| const file = Bun.file("chunks.json"); | |
| const last: Record<string, string> = await file.json(); | |
| file.write(JSON.stringify(result)); | |
| console.log("Added: " + Object.keys(result).filter((k) => !last[k])); | |
| console.log("Removed: " + Object.keys(last).filter((k) => !result[k])); | |
| console.log( | |
| "Modified: " + | |
| Object.keys(result).filter((k) => last[k] && last[k] !== result[k]), | |
| ); | |
| for (let k of Object.keys(last).filter((k) => !result[k])) | |
| Bun.file("./chunks/" + k + ".js") | |
| .delete() | |
| .catch(() => {}); | |
| for (let k of Object.keys(result).filter((k) => last[k] !== result[k])) | |
| await fetch("https://a.slack-edge.com/bv1-13-br/" + result[k]) | |
| .then((r) => r.text()) | |
| .then((r) => format(r, { parser: "babel" })) | |
| .then((r) => Bun.file("./chunks/" + k + ".js").write(r)) | |
| .catch((e) => console.error("Failed to fetch " + k, e)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment