fetch-supported-languages.js
1 import fs from 'fs'; 2 3 const url = 'https://mastodon.social/'; 4 5 const html = await fetch(url).then((res) => res.text()); 6 7 // Extract the JSON between <script id="initial-state" type="application/json"></script> 8 const json = html.match( 9 /<script id="initial-state" type="application\/json">(.*)<\/script>/, 10 )[1]; 11 12 const initialState = JSON.parse(json); 13 const { languages } = initialState; 14 15 console.log(`Found ${languages.length} languages`); 16 17 // Write to file 18 const path = './src/data/status-supported-languages.json'; 19 fs.writeFileSync(path, JSON.stringify(languages, null, '\t'), 'utf8'); 20 console.log(`Wrote ${path}`);