-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupportxmrenhancement.user.js
141 lines (112 loc) · 3.49 KB
/
supportxmrenhancement.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
// ==UserScript==
// @run-at document-idle
// @name SupportXMR.com enhancement
// @namespace supportxmrenhancement
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_log
// @grant GM_getResourceURL
// @description Private functions.
// @version 1.0.0
// @author kai-grassnick.de
// @include http://*.supportxmr.*
// @include http://supportxmr.*
// @include https://*.supportxmr.*
// @include https://supportxmr.*
// ==/UserScript==
(function () {
"use strict";
// #####################
// #### definitions ####
// #####################
var version = GM_info.script.version;
// ---- exchange calculator ----
// Api which returns a JSON String including the latest XMR to USD price
var exchangeUrl = "https://poloniex.com/public?command=returnTicker";
// Set exchange value update interval in seconds
var exchangeUpdateInterval = 10;
// ##############################
// #### Actual functionality ####
// ##############################
var exchangeWrapperExists = function()
{
return $("#exchange_value").length;
};
var appendExchangeValue = function(element)
{
element.append(
$("<span/>")
.attr("id", "exchange_value")
.css({"padding-left":"5px", "color": "#777", "font-size": "14px"})
.text("(0.000 USD)")
);
};
var addExchangeWrapper = function()
{
var headlines = $("#content").find("h4");
headlines.each(function() {
if($(this).text() === " Total Due"){
var path = $(this).parent().find("h2").attr("id", "saving_value");
appendExchangeValue(path);
}
});
};
var getSavings = function()
{
var value = $("#saving_value").text().slice(0,4);
return parseFloat(value);
};
var setExchangeValue = function(value)
{
$("#exchange_value").text("(" + value.toFixed(4) + " USD)");
};
var updateExchangeValue = function()
{
if(!exchangeWrapperExists()){
addExchangeWrapper();
}
// if we can't find it, we're probably not on the dashboard...
if(exchangeWrapperExists()) {
$.getJSON(exchangeUrl, function (data) {
var savings = getSavings();
var value = data.USDT_XMR.last * savings;
setExchangeValue(value);
});
}
};
var autoUpdateValue = function()
{
updateExchangeValue();
setInterval(function() {
updateExchangeValue();
}, exchangeUpdateInterval * 1000);
};
// ####################
// #### Bootloader ####
// ####################
var startLog = function()
{
console.log("supportXMR enhancement - " + version);
console.log("by kai-grassnick.de");
};
var init = function()
{
addExchangeWrapper();
autoUpdateValue();
};
var bootWrapper = function()
{
// Show credits
startLog();
// Angular is a slow child, wait for him to be ready and do the magic afterwards
var initWatcher = setInterval(function() {
if (unsafeWindow.angular) {
clearInterval(initWatcher);
init();
}
}, 100);
};
// Trigger the start button
bootWrapper();
}());