-
Notifications
You must be signed in to change notification settings - Fork 0
/
kite.js
225 lines (184 loc) · 8.59 KB
/
kite.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// ==UserScript==
// @name ChartIQ Candlestick Points Info
// @namespace Violentmonkey Scripts
// @match https://kite.zerodha.com/chart/*
// @grant none
// @version 1.0
// @author -
// @description 8/19/2023, 2:38:19 AM
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
// Disclaimer
/**
* DISCLAIMER:
* This script is provided "as is" without warranty of any kind, express or implied.
* While efforts have been made to ensure the script's compatibility,
* the author and contributors are not responsible for any potential
* issues, damages, or unintended consequences that may arise from its use.
* Users implement this script at their own risk and are advised to
* review and test it thoroughly before deployment in any production environment.
*/
(function () {
"use strict";
// Wait for the target element to be available
function checkForElement() {
var chartIframe = document.getElementById("chart-iframe");
if (chartIframe) {
var innerDoc = chartIframe.contentDocument || chartIframe.contentWindow.document;
var targetElement = $(innerDoc).find("cq-hu-static > div:nth-child(1)");
// Check if the target element and its structure are ready
if (targetElement.length > 0 && setTimeout(console.log("wait few secs"), 2000)) {
clearInterval(elementCheckInterval);
// Wait for the target structure to be ready if needed
// For example, you can use a specific class or attribute that indicates readiness
var isReady = $(innerDoc).find("cq-hu-open");
if (isReady) {
// Create a new div element
var newDiv = $(`<div id="candle-info" style="position: absolute; margin-left: 1.2rem;width: auto!important;left: 370px;">
Pts: <span id="value_span" style="font-size: 12px;"></span>
</div>`
);
// Append the new div element to the target element
targetElement.append(newDiv);
$(innerDoc).find("#candle-info::after").css("display", "none");
console.log("Element found and newDiv appended.");
// Bind the event after appending
bindEvent(innerDoc);
}
}
}
}
// Check for the element every 200ms
let elementCheckInterval = setInterval(checkForElement, 200);
// Bind the event
function bindEvent(innerDoc) {
// Ensure we bind the event within the iframe's context
$(innerDoc).find(".chartContainer").mousemove(function (event) {
const candlestick = $(event.target);
// console.log(event.target);
if (candlestick.find("cq-hu-open").text() == "N/A") {
const valueSpan = $("#value_span", innerDoc);
valueSpan.css("color", "black");
valueSpan.text("\u00A0N/A");
}
else if (candlestick.length > 0) {
const openPrice = parseFloat(candlestick.find("cq-hu-open").text());
const closePrice = parseFloat(candlestick.find("cq-hu-close").text());
const percentageChange = ((closePrice - openPrice) / openPrice) * 100;
const pointsMoved = Math.abs(closePrice - openPrice);
const valueSpan = $("#value_span", innerDoc);
if (openPrice === "N/A") console.log("LOL");
let sign = " ";
if (percentageChange > 0) sign = "+";
else if (percentageChange == 0) sign = "\u00A0";
else if (percentageChange < 0) sign = "-";
valueSpan.text(sign + pointsMoved.toFixed(2) + " (" + percentageChange.toFixed(2) + "%" + ")");
if (percentageChange > 0) {
valueSpan.css("color", "#4caf50");
} else if (percentageChange == 0) {
valueSpan.css("color", "black");
} else {
valueSpan.css("color", "#df514c");
}
// console.log(pointsMoved.toFixed(2) + '(' + percentageChange.toFixed(2) + '%' + ')');
}
});
}
function overrideAfterContent(innerDoc) {
var style = document.createElement("style");
style.innerHTML = `
cq-hu-static > div > div:after {
content: "";
}
`;
innerDoc.head.appendChild(style);
}
overrideAfterContent(innerDoc);
})();
// ==UserScript==
// @name ChartIQ Candlestick Points Info
// @namespace Violentmonkey Scripts
// @match https://kite.zerodha.com/chart/*
// @grant none
// @version 1.0
// @author -
// @description 8/19/2023, 2:38:19 AM
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
(function () {
"use strict";
// Wait for the target element to be available
function checkForElement() {
var chartIframe = document.getElementById("chart-iframe");
if (chartIframe) {
var innerDoc = chartIframe.contentDocument || chartIframe.contentWindow.document;
var targetElement = $(innerDoc).find("cq-hu-static > div:nth-child(1)");
// Check if the target element and its structure are ready
if (targetElement.length > 0 && setTimeout(console.log("wait few secs"), 2000)) {
clearInterval(elementCheckInterval);
// Wait for the target structure to be ready if needed
// For example, you can use a specific class or attribute that indicates readiness
var isReady = $(innerDoc).find("cq-hu-open");
if (isReady) {
// Create a new div element
var newDiv = $(`<div id="candle-info" style="position: absolute; margin-left: 1.2rem;width: auto!important;left: 370px;">
Pts: <span id="value_span" style="font-size: 12px;"></span>
</div>`
);
// Append the new div element to the target element
targetElement.append(newDiv);
$(innerDoc).find("#candle-info:after").css("display", "none");
console.log("Element found and newDiv appended.");
// Bind the event after appending
bindEvent(innerDoc);
}
}
}
}
// Check for the element every 200ms
let elementCheckInterval = setInterval(checkForElement, 200);
// Bind the event
function bindEvent(innerDoc) {
// Ensure we bind the event within the iframe's context
$(innerDoc).find(".chartContainer").mousemove(function (event) {
const candlestick = $(event.target);
// console.log(event.target);
if (candlestick.find("cq-hu-open").text() == "N/A") {
const valueSpan = $("#value_span", innerDoc);
valueSpan.css("color", "black");
valueSpan.text("\u00A0N/A");
}
else if (candlestick.length > 0) {
const openPrice = parseFloat(candlestick.find("cq-hu-open").text());
const closePrice = parseFloat(candlestick.find("cq-hu-close").text());
const percentageChange = ((closePrice - openPrice) / openPrice) * 100;
const pointsMoved = Math.abs(closePrice - openPrice);
const valueSpan = $("#value_span", innerDoc);
if (openPrice === "N/A") console.log("LOL");
let sign = " ";
if (percentageChange > 0) sign = "+";
else if (percentageChange == 0) sign = "\u00A0";
else if (percentageChange < 0) sign = "-";
valueSpan.text(sign + pointsMoved.toFixed(2) + " (" + percentageChange.toFixed(2) + "%" + ")");
if (percentageChange > 0) {
valueSpan.css("color", "#4caf50");
} else if (percentageChange == 0) {
valueSpan.css("color", "black");
} else {
valueSpan.css("color", "#df514c");
}
// console.log(pointsMoved.toFixed(2) + '(' + percentageChange.toFixed(2) + '%' + ')');
}
});
}
function overrideAfterContent(innerDoc) {
var style = document.createElement("style");
style.innerHTML = `
cq-hu-static > div > div:after {
content: "";
}
`;
innerDoc.head.appendChild(style);
}
overrideAfterContent(innerDoc);
})();