-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtownstar_production_rate_monitor.js
72 lines (66 loc) · 3.32 KB
/
townstar_production_rate_monitor.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
// ==UserScript==
// @name Production Rate Monitor
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Monitor production rate of specified craft items.
// @author Groove
// @match *://*.sandbox-games.com/launch*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const trackedItems = [
{item: 'Wheat', count: 0, first: 0, oneMin: 0, oneHour: 0},
{item: 'Wood', count: 0, first: 0, oneMin: 0, oneHour: 0},
];
let loaded = 0;
new MutationObserver(function(mutations) {
if (document.querySelector('.hud .right .hud-right') && loaded == 0) {
loaded = 1;
LoadProductionMonitor();
}
}).observe(document, {childList: true, subtree: true});
function LoadProductionMonitor() {
let trackedHud = document.createElement('div');
trackedHud.id = 'tracked-items';
let trackedItemHeader = document.createElement('div');
trackedItemHeader.id = 'tracked-item-header';
trackedItemHeader.classList.add('bank');
trackedItemHeader.style = 'width: 75%;';
trackedItemHeader.innerHTML = 'Craft: Count | /1Min | /1Hour';
trackedHud.appendChild(trackedItemHeader);
let hudRight = document.querySelector('.hud .right .hud-right');
hudRight.insertBefore(trackedHud, hudRight.querySelector('.right-hud').nextSibling);
for (let item of trackedItems) {
let trackedItemElem = document.createElement('div');
trackedItemElem.id = 'tracked-item-' + item.item;
trackedItemElem.classList.add('bank', 'contextual');
trackedItemElem.style = 'width: 75%;';
trackedItemElem.innerHTML = item.item + ': Count | /1Min | /1Hour';
trackedHud.appendChild(trackedItemElem);
}
class TrackUnitDeliverOutputTask extends UnitDeliverOutputTask {
onArrive() {
super.onArrive();
let trackedItem = trackedItems.find(item => item.item.toUpperCase() == this.craft.toUpperCase())
if (trackedItem) {
trackedItem.count++;
if (trackedItem.count == 1) {
trackedItem.first = Date.now();
} else {
let timeDiff = Date.now() - trackedItem.first;
trackedItem.oneMin = trackedItem.count / (timeDiff / 60000)
trackedItem.oneHour = trackedItem.count / (timeDiff / 3600000)
}
document.getElementById('tracked-item-' + trackedItem.item).innerHTML = trackedItem.item + ': <b>' + trackedItem.count + '</b> | <b>' + trackedItem.oneMin.toFixed(2) + '</b> | <b>' + trackedItem.oneHour.toFixed(2) + '</b>';
}
}
}
let origfindDeliverOutputTask = TS_UnitLogic.prototype.findDeliverOutputTask;
TS_UnitLogic.prototype.findDeliverOutputTask = function(t) {
let origReturn = origfindDeliverOutputTask.call(this, t);
return origReturn ? new TrackUnitDeliverOutputTask(origReturn.unit,origReturn.targetObject,t) : null
}
}
})();