-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaverage.js
More file actions
38 lines (33 loc) · 1.22 KB
/
average.js
File metadata and controls
38 lines (33 loc) · 1.22 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
import eventManager from 'src/utils/eventManager.js';
import * as settings from 'src/utils/settings/index.js';
import { global } from 'src/utils/global.js';
import onPage from 'src/utils/onPage.js';
import * as hover from 'src/utils/hover.js';
import Translation from 'src/structures/constants/translation';
const setting = settings.register({
name: Translation.Setting('deck.average'),
key: 'underscript.disable.deck.average',
refresh: onPage('Decks'),
page: 'Library',
});
// Calculate average
eventManager.on(':preload:Decks', () => {
if (setting.value()) return;
const label = $('<span>');
const avg = $('<span>');
$('#soulInfo span').after(label, ' ', avg).remove();
function round(amt, dec = 2) {
return Number.parseFloat(amt).toFixed(dec);
}
function count() {
let val = 0;
const list = global('decks')[global('soul')];
list.forEach(({ cost }) => val += cost); // eslint-disable-line no-return-assign
avg.text(`(${round(list.length ? val / list.length : val)})`);
}
eventManager.on('Deck:Soul Deck:Change Deck:Loaded', count);
eventManager.on('underscript:ready', () => {
label.text(Translation.General('passive'));
avg.hover(hover.show(Translation.General('deck.average')));
});
});