-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstats-detail.user.js
152 lines (142 loc) · 5.59 KB
/
stats-detail.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// ==UserScript==
// @name Cryptohopper Stats Detail
// @namespace https://github.com/markrickert/cryptohopper-dashboard-watchlist
// @version 0.1
// @description Adds additional profit detail and base currency balance to the stats box
// @author @falcontx
// @match https://www.cryptohopper.com/dashboard
// @icon https://www.google.com/s2/favicons?domain=cryptohopper.com
// @grant none
// ==/UserScript==
try {
// Only run this code on the intended page(s) (useful when @required in a parent script)
if (["/dashboard"].includes(window.location.pathname))
(function () {
"use strict";
var base = collect_currency;
function statsDetail() {
jQuery(
"#statsinfo > div > div:nth-child(1) > div.col-xs-10 > p.text-muted.m-b-5.font-13.text-uppercase.pull-left"
).contents()[0].nodeValue = "Profit (gross + positions = current): ";
jQuery("#statsinfo > div > div:nth-child(1) > div.col-xs-10 > h4").prop(
"id",
"original"
);
jQuery("#original")
.clone()
.insertAfter("#original")
.prop("id", "gross");
jQuery("#original").hide();
jQuery("#gross").clone().insertAfter("#gross").prop("id", "positions");
jQuery("#positions")
.clone()
.insertAfter("#positions")
.prop("id", "net");
jQuery("#positions")
.addClass("text-inverse")
.css("border-bottom", "1px solid #555")
.css("display", "inline-block");
jQuery("#gross > strong > #stats_total_returns").prop(
"id",
"detail_total_gross"
);
jQuery("#positions > strong > #stats_total_returns").prop(
"id",
"detail_total_positions"
);
jQuery("#net > strong > #stats_total_returns").prop(
"id",
"detail_total_net"
);
jQuery("#gross > #stats_percent_change").prop(
"id",
"detail_percent_gross"
);
jQuery("#positions > #stats_percent_change").prop(
"id",
"detail_percent_positions"
);
jQuery("#net > #stats_percent_change").prop("id", "detail_percent_net");
jQuery("#statsinfo > div > div:nth-child(3) > div.col-xs-10").prop(
"id",
"basetotal"
);
jQuery("#basetotal").append('<hr class="m-b-15">');
jQuery("#basetotal").append(
`<p class="text-muted m-b-5 font-13 text-uppercase">${base} available on exchange:</p><h4 class="m-t-0 m-b-5 counter text-inverse"><strong><span id="val_baseavail"></span></strong> <span id="val_baseavail_percent_change_wrapper" style="display: inline;">(<span id="val_baseavail_percent_change"></span>%)</span></h4>`
);
updateValues();
}
function updateValues() {
//var netProfit = parseFloat(jQuery("#original > strong > #stats_total_returns").text());
var positions = parseFloat(jQuery("#stats_total_positions").text());
var startBalance = String(hopper_start_balance).replace(",", "");
var totalBalance = String(current_hopper_balance).replace(",", "");
var netProfit = totalBalance - startBalance;
var grossProfit = netProfit - positions;
var netProfitPct = (netProfit / startBalance) * 100;
var positionsPct = (positions / startBalance) * 100;
var grossProfitPct = (grossProfit / startBalance) * 100;
var baseAvail = $(
`#current_assets_table > tbody > tr > td:nth-child(1) > b`
)
.filter(function () {
return $(this).text() == base;
})
.closest("tr")
.children()
.eq(1)
.text();
var baseAvailPct = (baseAvail / totalBalance) * 100;
jQuery("#detail_total_gross").text(grossProfit.toFixed(2));
jQuery("#detail_percent_gross").text(grossProfitPct.toFixed(2));
jQuery("#detail_total_positions").text(positions.toFixed(2));
jQuery("#detail_percent_positions").text(positionsPct.toFixed(2));
jQuery("#detail_total_net").text(netProfit.toFixed(2));
jQuery("#detail_percent_net").text(netProfitPct.toFixed(2));
if (typeof jQuery("#val_totalbalance").attr("class") != "undefined") {
jQuery("#net").attr(
"class",
"m-t-0 m-b-5 " + jQuery("#val_totalbalance").attr("class")
);
} else {
jQuery("#net").attr(
"class",
jQuery("#val_totalbalance").parent().parent().attr("class")
);
}
if (grossProfit >= 0) {
jQuery("#gross").attr("class", "m-t-0 m-b-5 text-success");
} else {
jQuery("#gross").attr("class", "m-t-0 m-b-5 text-danger");
}
jQuery("#val_baseavail").text(baseAvail);
jQuery("#val_baseavail_percent_change").text(baseAvailPct.toFixed(2));
}
function watchStatsData() {
statsDetail();
jQuery(document).ajaxComplete(updateValues);
//$('body').on('DOMSubtreeModified', '#original', function() {
// $('body').on('DOMSubtreeModified', '#val_totalbalance', function() {
// updateValues();
// });
// $('body').on('DOMSubtreeModified', '#stats_total_positions', function() {
// updateValues();
// });
}
jQuery(() => {
watchStatsData();
});
})();
} catch (err) {
console.log(
`Error in script target-restore.user.js: ${err.name}: ${err.message}`
);
}
(function () {
"use strict";
function watchUpdates() {
jQuery(document).ajaxComplete(updateValues);
}
jQuery(() => {});
})();