Skip to content

Instantly share code, notes, and snippets.

@betillogalvanfbc
Created January 30, 2025 00:45
Show Gist options
  • Save betillogalvanfbc/dd67107a342f5d8bcac4d283b7d2bc73 to your computer and use it in GitHub Desktop.
Save betillogalvanfbc/dd67107a342f5d8bcac4d283b7d2bc73 to your computer and use it in GitHub Desktop.
onelefmin.js
javascript:(async%20function()%7Bconst%20scanningDiv%3Ddocument.createElement(%22div%22)%3BscanningDiv.style.position%3D%22fixed%22%2CscanningDiv.style.bottom%3D%220%22%2CscanningDiv.style.left%3D%220%22%2CscanningDiv.style.width%3D%22100%25%22%2CscanningDiv.style.maxHeight%3D%2250%25%22%2CscanningDiv.style.overflowY%3D%22scroll%22%2CscanningDiv.style.backgroundColor%3D%22white%22%2CscanningDiv.style.color%3D%22black%22%2CscanningDiv.style.padding%3D%2210px%22%2CscanningDiv.style.zIndex%3D%229999%22%2CscanningDiv.style.borderTop%3D%222px%20solid%20black%22%2CscanningDiv.innerHTML%3D%22%3Ch4%3EScanning%20resources...%3C%2Fh4%3E%22%2Cdocument.body.appendChild(scanningDiv)%3Blet%20paths%3D%5B%5D%2CprocessedUrls%3Dnew%20Set%3Basync%20function%20fetchContent(url)%7Btry%7Bconst%20response%3Dawait%20fetch(url)%3Breturn%20response.ok%3Fawait%20response.text()%3Anull%7Dcatch(error)%7Breturn%20console.error(%60Error%20fetching%20%24%7Burl%7D%3A%60%2Cerror)%2Cnull%7D%7Dfunction%20extractPaths(text)%7Breturn%5B...text.matchAll(%2F%5B'%22%60%5D((%3F%3A%5C%2F%7C%5C.%5C.%5C%2F%7C%5C.%5C%2F)%5B%5E'%22%60%5D%2B)%5B'%22%60%5D%2Fg)%5D.map(match%3D%3Ematch%5B1%5D).filter(isValidPath)%7Dfunction%20isValidPath(path)%7Bconst%20ignoredExtensions%3D%5B%22.png%22%2C%22.jpg%22%2C%22.jpeg%22%2C%22.gif%22%2C%22.css%22%2C%22.woff%22%2C%22.woff2%22%5D%3Breturn(path.startsWith(%22%2F%22)%7C%7Cpath.startsWith(%22.%2F%22)%7C%7Cpath.startsWith(%22..%2F%22))%26%26!path.includes(%22%20%22)%26%26!%2F%5B%5E%5Cx20-%5Cx7E%5D%2F.test(path)%26%26path.length%3E1%26%26path.length%3C200%26%26!ignoredExtensions.some(ext%3D%3Epath.endsWith(ext))%7Dasync%20function%20processUrl(url)%7Bif(processedUrls.has(url))return%3BprocessedUrls.add(url)%2Cconsole.log(%60Fetching%20and%20processing%3A%20%24%7Burl%7D%60)%3Bconst%20content%3Dawait%20fetchContent(url)%3Bif(content)%7Bconst%20foundPaths%3DextractPaths(content)%3Bpaths.push(...foundPaths)%3Bif(url.endsWith(%22.js%22))%7Bconst%20endpoints%3DextractEndpoints(content)%3Bfor(const%20endpoint%20of%20endpoints)%7Bconst%20fullUrl%3Dnew%20URL(endpoint.url%2Curl).href%3Bawait%20processUrl(fullUrl)%7D%7D%7D%7Dfunction%20extractEndpoints(content)%7Bconst%20regex%3D%2F(?:fetch%7Caxios%5C.(?:get%7Cpost%7Cput%7Cdelete)%7CXMLHttpRequest%5C.open)%5Cs*%5C(%5Cs*%5B'%22%60%5D(%5B%5E'%22%60%5D%2B)%5B'%22%60%5D%5Cs*(?:%2C%5Cs*%7B.*%3Fmethod%5Cs*%3A%5Cs*%5B'%22%60%5D(%5B%5E'%22%60%5D%2B)%5B'%22%60%5D%7C%2C%5Cs*%5B'%22%60%5D(%5B%5E'%22%60%5D%2B)%5B'%22%60%5D)%3F%2Fg%3Bconst%20endpoints%3D%5B%5D%3Blet%20match%3Bwhile((match%3Dregex.exec(content))!%3D%3Dnull)%7Bconst%20url%3Dmatch%5B1%5D%2Cmethod%3Dmatch%5B2%5D%7C%7Cmatch%5B3%5D%7C%7C%22GET%22%3Bendpoints.push(%7Burl%2Cmethod%7D)%7Dreturn%5B...new%20Set(endpoints.map(e%3D%3EJSON.stringify(e)))%5D.map(e%3D%3EJSON.parse(e))%7Dconst%20resources%3Dperformance.getEntriesByType(%22resource%22).map(res%3D%3Eres.name)%3Bconsole.log(%22Resources%20found%3A%22%2Cresources)%3Bawait%20Promise.all(resources.map(processUrl))%3Bconst%20uniquePaths%3D%5B...new%20Set(paths)%5D%3Bconsole.log(%22Final%20list%20of%20unique%20paths%3A%22%2CuniquePaths)%3Bconsole.log(%22All%20scanned%20resources%3A%22%2CArray.from(processedUrls))%3BscanningDiv.innerHTML%3D%60%3Ch4%3EUnique%20Paths%20Found%3A%3C%2Fh4%3E%3Cul%3E%24%7BuniquePaths.map(path%3D%3E%60%3Cli%3E%24%7Bpath%7D%3C%2Fli%3E%60).join(%22%22)%7D%3C%2Ful%3E%3Ch4%3EAll%20Scanned%20Resources%3A%3C%2Fh4%3E%3Cul%3E%24%7BArray.from(processedUrls).map(resource%3D%3E%60%3Cli%3E%24%7Bresource%7D%3C%2Fli%3E%60).join(%22%22)%7D%3C%2Ful%3E%3Cbutton%20id%3D%22downloadButton%22%3EDownload%20as%20TXT%3C%2Fbutton%3E%60%3Bdocument.getElementById(%22downloadButton%22).addEventListener(%22click%22%2C()%3D%3E%7Bconst%20content%3D%60%3D%3D%3D%20Unique%20Paths%20Found%20%3D%3D%3D%5Cn%24%7BuniquePaths.join(%22%5Cn%22)%7D%5Cn%5Cn%3D%3D%3D%20All%20Scanned%20Resources%20%3D%3D%3D%5Cn%24%7BArray.from(processedUrls).join(%22%5Cn%22)%7D%5Cn%5Cn%3D%3D%3D%20Endpoints%20with%20HTTP%20Methods%20%3D%3D%3D%5Cn%24%7BextractEndpointsFromProcessedUrls().join(%22%5Cn%22)%7D%60%3Bconst%20blob%3Dnew%20Blob(%5Bcontent%5D%2C%7Btype%3A%22text%2Fplain%22%7D)%3Bconst%20url%3DURL.createObjectURL(blob)%3Bconst%20a%3Ddocument.createElement(%22a%22)%3Ba.href%3Durl%3Ba.download%3D%22scan_results.txt%22%3Ba.click()%3BURL.revokeObjectURL(url)%3Balert(%22File%20downloaded%20successfully!%22)%7D)%3Bfunction%20extractEndpointsFromProcessedUrls()%7Bconst%20endpoints%3D%5B%5D%3Bfor(const%20url%20of%20processedUrls)%7Bif(url.endsWith(%22.js%22))%7Bconst%20content%3DfetchContentSync(url)%3Bif(content)%7Bconst%20foundEndpoints%3DextractEndpoints(content)%3Bendpoints.push(...foundEndpoints.map(e%3D%3E%60%24%7Be.method%7D%20%24%7Be.url%7D%60))%7D%7D%7Dreturn%5B...new%20Set(endpoints)%5D%7Dfunction%20fetchContentSync(url)%7Bconst%20xhr%3Dnew%20XMLHttpRequest()%3Bxhr.open(%22GET%22%2Curl%2Cfalse)%3Bxhr.send()%3Breturn%20xhr.status%3D%3D%3D200%3Fxhr.responseText%3Anull%7D%7D)()%3B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment