Skip to content

Instantly share code, notes, and snippets.

@Piterden
Last active January 27, 2018 18:20
Show Gist options
  • Save Piterden/9520388a5de85e371a3912415db37033 to your computer and use it in GitHub Desktop.
Save Piterden/9520388a5de85e371a3912415db37033 to your computer and use it in GitHub Desktop.
Telegram API page parser. Run this in the console on tg API page
Array.from(document.querySelectorAll('h4')).map((el) => {
const nextEl = el.nextElementSibling
const tableEl = nextEl.nextElementSibling
return `
/**${nextEl.innerText.replace(/(.{1,72}\s)\s*?/g, '\n * $1')}
*/
export type ${el.innerText} = {
` + Array.from(tableEl.children[0].children).slice(1).map((tr) => {
const arr = Array.from(tr.children)
return arr.length
? arr[2].innerText.length > 72
? `
/**${arr[2].innerText.replace(/(.{1,72}\s)\s*?/g, '\n * $1')}
*/
${arr[0].innerText}: ${arr[1].innerText.toLowerCase()},
`
: ` /** ${arr[2].innerText} */\n ${arr[0].innerText}: ${arr[1].innerText.toLowerCase()},\n\n`
: ''
}).join('') + `}
`}).join('')
@Piterden
Copy link
Author

https://github.com/sergeysova/telegram-typings
Thanx, Sova, you are da shit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment