-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
127 lines (108 loc) · 4.87 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* (GNU GENERAL PUBLIC LICENSE)
developed by dm-development.de 2014 - published 2017 - updated 2024
* LICENSE: https://github.com/He3556/Mixcloud-Unfollowers/blob/master/LICENSE
* SOURCE: https://github.com/He3556
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
*/
/*
follers = new Array(); // Array of followers
ing = 0; // Array pointer - username to check
j; // counter of follower (Frontend: Data Calculated)
w; // counter of following (Frontend: Data Calculated)
followercnt; // Counter of (your) followers
followingcnt; // Counter (DJs you are) following
cnt; //counter
offst = 0; // for paging of content
lmt = 100; // limit 100 for 1 page
var follok = 0; //number of followers that are following back (green)
var follnot = 0; //number of followers that are NOT following back (green)
*/
$(document).ready(function () {
$("#searchtext").focus(); // Focus on the text input
// Reset function
$('#goback').click(function () {
$("#searchtext").val("");
$("#error").empty();
$("#info").empty();
$("#cntfollowers").text('Followers: 0');
$("#cntfollowing").text('Following: 0');
$("#fok").html('<div>0</div>');
$("#fnot").html('<div>0</div>');
$("#followingok").empty();
$("#followingmiss").empty();
});
// Search function
$('#input').click(async function () {
const uname = $("#searchtext").val();
if (uname === "") {
$("#error").append('There was nothing to search for!<br />');
return;
}
let followercnt = 0;
let followingcnt = 0;
try {
const result = await $.getJSON(`https://api.mixcloud.com/${uname}/?metadata=1`);
followercnt = parseInt(result.follower_count);
followingcnt = parseInt(result.following_count);
$("#info").append(`Followers: ${followercnt} <br />Following: ${followingcnt}`);
if (followercnt === 0 || followingcnt === 0) {
$("#error").append('User was not found on Mixcloud<br /><br /><br /><br />');
return;
}
const cnt = Math.ceil(followercnt / 100);
const cntb = Math.ceil(followingcnt / 100);
const followers = await getFollowers(cnt, uname);
await getFollowing(cntb, uname, followers);
// Kontrolle, ob alle Entitäten verarbeitet wurden
if (followers.length === followercnt) {
console.log('All followers were processed successfully.');
} else {
console.log(`${followercnt}, : ${followers.length}`);
}
const totalFollowingProcessed = follok + follnot;
if (totalFollowingProcessed === followingcnt) {
console.log('All followed users were processed successfully.');
} else {
console.log(`${followingcnt}, : ${totalFollowingProcessed}`);
}
} catch (error) {
$("#error").append(`An error occurred while fetching data: ${error.message}<br />`);
console.error('Error fetching data:', error);
}
});
async function getFollowers(cnt, uname) {
const followers = [];
for (let i = 0; i < cnt; i++) {
const result = await $.getJSON(`https://api.mixcloud.com/${uname}/followers/?limit=100&offset=${i * 100}`);
result.data.forEach(follower => {
followers.push(follower.username);
});
$("#cntfollowers").text(`Followers: ${followers.length}`);
}
return followers;
}
async function getFollowing(cntb, uname, followers) {
follok = 0;
follnot = 0;
$("#followingok").empty();
$("#followingmiss").empty();
for (let i = 0; i < cntb; i++) {
const result = await $.getJSON(`https://api.mixcloud.com/${uname}/following/?limit=100&offset=${i * 100}`);
result.data.forEach(following => {
const ing = following.username;
const isFollowingBack = followers.includes(ing);
if (isFollowingBack) {
follok++;
$("#fok").html(`<div>${follok}</div>`);
$("#followingok").append(`<div><img src="./pictures/ok.png" height="12" width="12"> ${ing} <a target='_blank' href='https://mixcloud.com/${ing}'>open profile</a></div>`);
} else {
follnot++;
$("#fnot").html(`<div>${follnot}</div>`);
$("#followingmiss").append(`<div><img src="./pictures/missing.png" height="12" width="12"> ${ing} <a target='_blank' href='https://mixcloud.com/${ing}'>open profile</a></div>`);
}
$("#cntfollowing").text(`Following: ${follok + follnot}`);
});
}
}
});