-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathquestProgress.js
More file actions
66 lines (56 loc) · 1.9 KB
/
questProgress.js
File metadata and controls
66 lines (56 loc) · 1.9 KB
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
import Quest from 'src/structures/quests/Quest.js'; // eslint-disable-line no-unused-vars
import { toast } from 'src/utils/2.toasts.js';
import * as settings from 'src/utils/settings/index.js';
import onPage from 'src/utils/onPage.js';
import eventManager from 'src/utils/eventManager.js';
import { fetch } from 'src/utils/quests.js';
const setting = settings.register({
name: 'Disable Quest Toast',
key: 'underscript.disable.questNotifications',
page: 'Game',
category: 'Notifications',
});
onPage('Game', () => {
if (setting.value()) return;
/**
* @param {Quest[]} results
*/
function setup(results) {
const cache = new Map(results.map((q) => [q.id, q.clone()]));
eventManager.once('questProgress', updateQuests);
/**
* @param {Quest[]} quests
*/
function updateQuests(quests) {
const changes = quests.filter((quest) => {
if (quest.claimed) return false;
const previous = cache.get(quest.id);
return previous && quest.progress.compare(previous.progress);
}).sort((a, b) => b.claimable - a.claimable);
if (!changes.length) return;
const message = (() => {
const lines = [];
let completed = true;
changes.forEach((e, i) => {
if (!i && e.claimable) {
lines.push('### Completed');
} else if (completed && !e.claimable) {
completed = false;
if (i) lines.push('\n'); // Separate completed from progress
lines.push('### Progression');
}
lines.push(`- ${e.name} (+${e.progress.compare(cache.get(e.id).progress)})`);
});
return lines.join('\n');
})();
toast({
title: 'Quest Progress!',
text: `${message}\nClick to go to Quests page`,
onClose: () => {
location.href = '/Quests';
},
});
}
}
fetch(({ quests }) => quests && setup(quests), false);
});