-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
192 lines (160 loc) · 6.45 KB
/
popup.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
document.getElementById('checkFollowers').addEventListener('click', function() {
checkFollowers();
});
document.getElementById('accountName').addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
checkFollowers();
}
});
function checkFollowers() {
const accountName = document.getElementById('accountName').value;
if (accountName) {
document.getElementById('progress').innerHTML = `<p><strong>Checking followers for account: ${accountName}</strong></p>`;
getAccountAgeInDays(accountName).then(ageInDays => {
getFollowers(accountName, ageInDays);
}).catch(error => {
console.error('Error fetching account age:', error);
alert('Error fetching account age. Please try again.');
});
} else {
alert('Please enter a Steemit account name.');
}
}
async function getAccountAgeInDays(accountName) {
const apiUrl = 'https://api.steemit.com';
const requestData = {
jsonrpc: "2.0",
method: "condenser_api.get_accounts",
params: [[accountName]],
id: 1
};
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
const data = await response.json();
const createdDate = new Date(data.result[0].created);
const currentDate = new Date();
const diffTime = Math.abs(currentDate - createdDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
return diffDays;
}
async function getFollowers(accountName, accountAgeInDays) {
document.getElementById('results').innerHTML = '';
document.getElementById('progress').innerHTML = '';
let followers = [];
let lastFollower = null;
let previousLastFollower = null;
let iterationCounter = 0;
const limit = 100;
while (true) {
const params = JSON.stringify({
jsonrpc: "2.0",
method: "condenser_api.get_followers",
params: [accountName, lastFollower, "blog", limit],
id: 1
});
const response = await fetch('https://api.steemit.com', {
method: 'POST',
body: params,
headers: { 'Content-Type': 'application/json' }
});
const data = await response.json();
const newFollowers = data.result;
if (!newFollowers || newFollowers.length === 0) {
break;
}
if (lastFollower && newFollowers[0].follower === lastFollower) {
newFollowers.shift();
}
if (newFollowers.length > 0) {
followers = followers.concat(newFollowers);
previousLastFollower = lastFollower;
lastFollower = newFollowers[newFollowers.length - 1].follower;
iterationCounter++;
if (iterationCounter === 5) {
document.getElementById('progress').innerHTML = `<p><strong>Fetched ${followers.length} followers so far...</strong></p>`;
iterationCounter = 0;
}
}
if (newFollowers.length < limit - 1) {
break;
}
if (lastFollower === previousLastFollower) {
break;
}
}
const totalFollowers = followers.length;
const weightedAccountAgeInDays = weightedAge(accountAgeInDays);
const newFollowersPerMonth = (365.25 * totalFollowers) / (12 * accountAgeInDays);
const adjustedFollowersPerMonth = (365.25 * totalFollowers) / (12 * weightedAccountAgeInDays);
const reputations = followers.map(f => f.reputation).sort((a, b) => a - b);
const medianReputation = calculateMedian(reputations);
const followerStrength = calculateFollowerStrength(adjustedFollowersPerMonth, medianReputation);
document.getElementById('progress').innerHTML = '';
document.getElementById('results').innerHTML = `
<p><strong>Account Name:</strong> ${accountName}</p>
<p><strong>Account Age in Days:</strong> ${accountAgeInDays}</p>
<p><strong>Adjusted Account Age in Days:</strong> ${weightedAccountAgeInDays}</p>
<p><strong>Total Followers:</strong> ${totalFollowers}</p>
<p><strong>New Followers per month:</strong> ${newFollowersPerMonth}</p>
<p><strong>Adjusted Followers per month:</strong> ${adjustedFollowersPerMonth}</p>
<p><strong>Median Follower Reputation:</strong> ${medianReputation.toFixed(2)}</p>
<p><strong>Follower Network Strength:</strong> ${Number(followerStrength).toFixed(2)}</p>
`;
console.log(`Account Age in Days: ${accountAgeInDays}`);
console.log(`Total Followers: ${totalFollowers}`);
console.log(`Median Follower Reputation: ${medianReputation}`);
console.log(`Follower Network Strength: ${followerStrength}`);
}
function calculateMedian(numbers) {
const mid = Math.floor(numbers.length / 2);
if (numbers.length % 2 === 0) {
return (numbers[mid - 1] + numbers[mid]) / 2;
} else {
return numbers[mid];
}
}
function calculateFollowerStrength(followerCount, medianReputation) {
const maxFollowerCount = 60;
const base = Math.max(1, 30 - Math.min ( 30, followerCount / 5 ));
const maxReputation = Math.min(50, base + (50 - base) * (Math.max(0, (maxFollowerCount - followerCount)) / maxFollowerCount));
const threshold = 26;
const minFollowers = 0.5;
let normMedianReputation = 0;
let normFollowerCount = 0;
if (medianReputation > threshold && followerCount >= minFollowers) {
// normMedianReputation = ((medianReputation - threshold) / (maxReputation - threshold));
normMedianReputation = ((medianReputation - threshold) / maxReputation);
normMedianReputation = Math.min(1, normMedianReputation);
normFollowerCount = (followerCount - minFollowers) / (maxFollowerCount - minFollowers);
normFollowerCount = Math.min(1, normFollowerCount);
const distance = Math.sqrt(Math.pow(normFollowerCount, 2) + Math.pow(normMedianReputation, 2));
console.log(`Normalized followers: ${normFollowerCount}, Normalized reputation: ${normMedianReputation}`);
const strength = Math.max(distance, 0.01);
return strength.toFixed(2);
} else {
return 0.01.toFixed(2);
}
}
function getVersionNumber() {
return chrome.runtime.getManifest().version;
}
function updatePopupVersion() {
var versionElement = document.getElementById('version');
if (versionElement) {
versionElement.textContent = getVersionNumber();
}
}
function weightedAge(days) {
let firstTerm = Math.pow(2, 1/(365.25 * 4)); // Daily adjustment for inactive accounts that accumulate over time.
let commonRatio = Math.pow(2, 1/(365.25 * 4)); // Every 4 years, the weight of a day doubles.
let adjustedAge = firstTerm * (Math.pow(commonRatio, days) - 1) / (commonRatio - 1);
return adjustedAge;
}
document.addEventListener('DOMContentLoaded', function() {
updatePopupVersion();
});