JSFiddle - React, Tailwind, and code Playground

by frogggeee McFrogggeee

JavaScript

let username = prompt("whos followers to invite?", "griffpatch");
let page = 0;
let usernames = [];
let completed = 0;
let totalPages = 10;
function extract(p) {
	fetch('https://cors-anywhere.herokuapp.com/https://api.scratch.mit.edu/users/' + username + '/followers?offset=' + p)
	.then(response => response.json())
	.then(data => {
	for (let i = 0; i < data.length; i++) {
  	usernames.push(data[i].username);
  }
  completed++;
  if (completed == totalPages) {
    console.log(usernames);
    alert("usernames extracted, please wait about 20 seconds to invite 150 scratchers.");
    startInv();
  }
});
}
for (let i = 0; i < totalPages; i++) {
	extract(page);
  page += 20;
}
function invite() {
 $.ajax({
      url: '/site-api/users/curators-in/' + Scratch.INIT_DATA.GALLERY.model.id + '/invite_' + "curator" + '/?usernames=' + usernames[invCount],
      type: 'PUT',
    });
    invCount++;
    if (invCount == usernames.length) {
    	alert("program successfully invited about 150 scratchers to the studio " + Scratch.INIT_DATA.GALLERY.model.title);
    }
}
let invCount = 0;
function startInv() {
	for (let i = 0; i < usernames.length; i++) {
  	setTimeout(invite, i*100);
  }
}