Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
hcr5 authored Feb 18, 2024
1 parent 2ac0591 commit 14c6810
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<input type="text" id="username" placeholder="Enter Username">
<button onclick="loadFollowers()">Load Followers</button>
<button onclick="loadFollowing()">Load Following</button>
<button onclick="stopLoading()">Stop</button>
<div id="result"></div>

Expand Down Expand Up @@ -49,6 +50,40 @@
load();
}

function loadFollowing() {
var username = $('#username').val(); // Utilize jQuery to get the input value
var page = 1;
loading = true; // Set loading flag to true

// Clear old followers before loading new ones
$('#result').empty();

function load() {
if (!stopLoadingFlag) { // Check if loading process should continue
$.get("https://scratch.mit.edu/users/" + username + "/following/?page=" + page, loaded);
}
}

function loaded(data) {
var users = $(data).find('span.title > a'); // Use jQuery to find users directly
var $out = $('#result');

users.each(function() {
var user = $(this).text().trim(); // Use $(this) to reference the current user
$out.append(user + '<br>');
});

page++;
if (!stopLoadingFlag) { // Check if loading process should continue
load(); // Call load function recursively
} else {
loading = false; // Set loading flag to false when loading stops
}
}

load();
}

function stopLoading() {
stopLoadingFlag = true; // Set the flag to stop loading
}
Expand Down

0 comments on commit 14c6810

Please sign in to comment.