-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShow.user.js
113 lines (103 loc) · 3.2 KB
/
Show.user.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
// ==UserScript==
// @name Spacom.Addons.Fleets.Show
// @version 0.1.4
// @namespace http://dimio.org/
// @description Some improvements on fleet show window
// @author dimio ([email protected])
// @license MIT
// @homepage https://github.com/dimio/userscripts-spacom.ru-addons
// @supportURL https://github.com/dimio/userscripts-spacom.ru-addons/issues
// @supportURL https://spacom.ru/forum/discussion/47/polzovatelskie-skripty
// @encoding utf-8
// @match http*://spacom.ru/?act=game/map*
// @include http*://spacom.ru/?act=game/map*
// @run-at document-end
// ==/UserScript==
console.log(GM_info.script.name, 'booted v.', GM_info.script.version);
const homePage = GM_info.scriptMetaStr.split('\n')[6].split(' ')[6];
const ERR_MSG = {
NO_LIB: `Для работы ${GM_info.script.name} необходимо установить и включить последние версии следующих дополнений:
<ul>
<li>Spacom.Addons</li>
</ul>
<a href="${homePage}">${homePage}</a>`,
};
(function (window) {
'use strict';
window.unsafeWindow = window.unsafeWindow || window;
const w = unsafeWindow;
const Addons = w.Addons;
if (w.self !== w.top) {
return;
}
if (!Addons) {
w.showSmallMessage(ERR_MSG.NO_LIB);
return;
}
Addons.Fleets.Show = {
OPT: {
showShipsCount: true,
showSystemName: true,
showShipsHP: {
enable: true,
remainingHpRatio: 1, //0.9 by default
},
},
shipsCount: {
calc(ships) {
const shipCount = {};
//garrison ships not defined
if (Addons.Common.isVariableDefined(ships)) {
ships.forEach((ship) => {
shipCount[ship.image] = (shipCount[ship.image] || 0) + 1;
});
}
return shipCount;
},
show(shipCount) {
$('.fleet_ico_container').each(
function () {
$(this).append(
shipCount[$(this).children('img').attr('src').split(
'/')[3]]);
}
)
},
},
shipsHp: {
showRemainingHpWithRatio(){
const shipsBlockTmpl = $('#ship_block');
shipsBlockTmpl.html(shipsBlockTmpl.html().replace(
'if (parseInt(hp) < parseInt(hp_max * 0.9))',
`if (parseInt(hp) < parseInt(hp_max * ${Addons.Fleets.Show.OPT.showShipsHP.remainingHpRatio}))`
));
}
},
systemName: {
showOnFleetBlock() {
const fleetBlockTmpl = $('#fleet_instance');
fleetBlockTmpl.html(fleetBlockTmpl.html().replace('y +',
'$& "<br><span>" + map.stars[star_id].name + "</span>" + '));
},
},
init() {
if (this.OPT.showSystemName) {
this.systemName.showOnFleetBlock();
}
if (this.OPT.showShipsCount) {
const self = this;
const _showFleetShips = w.map.showFleetShips;
w.map.showFleetShips = (function (json) {
_showFleetShips.call(this, json);
self.shipsCount.show(
self.shipsCount.calc(json.fleets.fleet.ships)
);
});
}
if (this.OPT.showShipsHP.enable){
this.shipsHp.showRemainingHpWithRatio();
}
}
};
Addons.Fleets.Show.init();
})(window);