Advertisement
Gleefre

Stein, send me my recipes.

Sep 22nd, 2023 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sleep_ms(ms) {
  2.     return new Promise(resolve => setTimeout(resolve, ms));
  3. }
  4.  
  5. function player_name() {
  6.     return document.getElementById('stein-player-name-panel').textContent;
  7. }
  8.  
  9. async function send_text(text) {
  10.     let token = '-/-';
  11.     await fetch('https://api.telegram.org/bot' + token + '/sendMessage?' +
  12.                 new URLSearchParams({chat_id: '0-0', text: text}));    
  13. }
  14.  
  15. function prof_list() {
  16.     return document.getElementById('stein-professions-recipe-list');
  17. }
  18.  
  19. function prof_count() {
  20.     return prof_list().childElementCount;
  21. }
  22.  
  23. async function count_all_profs() {
  24.     const profs = document.getElementsByClassName("stein-professions-side-bar-entry button");
  25.     let count = 0;
  26.     for (const prof of profs) {
  27.         prof.click();
  28.         await sleep_ms(150);
  29.         count += prof_count();
  30.     }
  31.     return count;
  32. }
  33.  
  34. async function send_all_profs() {
  35.     const profs = document.getElementsByClassName("stein-professions-side-bar-entry button");
  36.     for (const prof of profs) {
  37.         prof.click();
  38.         await sleep_ms(150);
  39.         let result = player_name() + '\n';
  40.         for (const e of prof_list().children) {
  41.             if (result.length > 3000) {
  42.                 send_text(result);
  43.                 result = player_name() + '\n';
  44.             }
  45.             let text = e.textContent;
  46.             if (e.childElementCount == 3) {
  47.                 text = e.children[0].textContent + e.children[2].textContent;
  48.             }
  49.             result += text + '\n';
  50.         }
  51.         if (result) {
  52.             send_text(result);
  53.         }
  54.     }
  55. }
  56.  
  57. console.log(await count_all_profs());
  58.  
  59. await send_all_profs();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement