Skip to content

Commit d345696

Browse files
committed
fix: friendship ranking
1 parent 06a2267 commit d345696

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# UnderScript Changelog
22

3+
## Version 0.53.1 (2023-07-02)
4+
1. Fixed changelog
5+
1. Fixed friendship ranking not loading sometimes
6+
37
## Version 0.53.0 (2023-05-23)
48
### New Features
59
1. Added craft/disenchant protection to prevent double clicking

src/base/friendship/collect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function getLabel(type = '') {
5353
}
5454
}
5555

56-
eventManager.on('Friendship:loaded', () => {
56+
eventManager.on(':loaded:Friendship', () => {
5757
button.prop('disabled', setting.value() || !canCollect());
5858
});
5959

src/base/friendship/ranking.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function displayRank(card, rank) {
132132
// TODO: This needs to be hooked into leaderboard
133133
// eventManager.on('updateFriendship', (data) => updateCache({ ...data, save: true }));
134134

135-
eventManager.on('Friendship:load', () => {
135+
eventManager.on(':loaded:Friendship', () => {
136136
style.add(
137137
`.rank {
138138
position: relative;
@@ -188,30 +188,27 @@ eventManager.on('Friendship:load', () => {
188188
loaded = true;
189189
});
190190

191-
eventManager.on(':loaded', () => {
192-
globalSet('appendCardFriendship', function func(card, ...args) {
193-
const ret = this.super(card, ...args);
194-
if (setting.value() !== disabled) {
195-
const id = card.idCard || card.fixedId || card.id;
196-
pending.push(pendingUpdate(id, card.xp)
197-
.then(({ rank, cached }) => {
198-
displayRank(id, rank);
199-
return cached;
200-
}));
201-
}
202-
return ret;
203-
});
191+
eventManager.on('Friendship:page', () => {
192+
if (!pending.length) return;
193+
Promise.all(pending.splice(0))
194+
.then((vals = []) => {
195+
const notAllCached = vals.some((val) => !val);
196+
if (notAllCached) {
197+
saveCache();
198+
}
199+
});
204200
});
205201

206-
eventManager.on('Friendship:page', () => {
207-
if (pending.length) {
208-
Promise.all(pending.splice(0))
209-
.then((vals = []) => {
210-
const notAllCached = vals.some((val) => !val);
211-
if (notAllCached) {
212-
saveCache();
213-
}
214-
});
202+
globalSet('appendCardFriendship', function func(card, ...args) {
203+
const ret = this.super(card, ...args);
204+
if (setting.value() !== disabled) {
205+
const id = card.idCard || card.fixedId || card.id;
206+
pending.push(pendingUpdate(id, card.xp)
207+
.then(({ rank, cached }) => {
208+
displayRank(id, rank);
209+
return cached;
210+
}));
215211
}
212+
return ret;
216213
});
217214
});

src/hooks/friendship.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import eventManager from '../utils/eventManager.js';
22
import { global } from '../utils/global.js';
33

44
eventManager.on(':loaded:Friendship', () => {
5-
eventManager.emit('Friendship:load');
5+
eventManager.singleton.emit('Friendship:load');
66
$(document).ajaxComplete((event, xhr, settings) => {
77
if (settings.url !== 'FriendshipConfig') return;
88
if (settings.type === 'GET') {

0 commit comments

Comments
 (0)