-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
117 lines (106 loc) · 3.26 KB
/
main.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
function get_table_data(table) {
// asks & bids : Quantity, size, bid/ask price
// sales : date, time, size, sale price
const table_arr = Array.from(table.rows).slice(1); // remove header
return table_arr.map(row => row.cells)
.map(row => Array.from(row))
.map(row => row.flatMap(cell => cell.innerText))
}
function insert_chart(selector, timeSeriesData) {
if (timeSeriesData[0].length < 4) {
return; // if "asks" or "bids" views open, skip chart insertion
}
const parentDiv = document.createElement('div');
parentDiv.style.padding = '0px 24px';
const canvas = document.createElement('canvas');
canvas.id = "myChartJS";
parentDiv.appendChild(canvas);
// chakra-modal--body-27 or chakra-modal-11
document.querySelector("#chakra-modal-11").insertBefore(parentDiv, document.querySelector(selector));
var ctx = document.getElementById("myChartJS").getContext("2d");
// Format the time series data for Chart.js
var chartData = {
labels: timeSeriesData.map(item => new Date(`${item[0]} ${item[1]}`)),
datasets: [{
label: "Shoe price",
data: timeSeriesData.map(x => parseInt(x[3].slice(1))),
backgroundColor: "rgba(54, 162, 235, 0.2)",
borderColor: "rgba(54, 162, 235, 1)",
borderWidth: 3,
}, ],
};
var chart = new Chart(ctx, {
type: "line",
data: chartData,
options: {
scales: {
x: {
type: 'time',
time: {
displayFormats: {
'minute': 'd MMM, h:m a'
},
tooltipFormat: "d MMM, H:mm a",
},
ticks: {
maxTicksLimit: 5,
},
}
},
elements: {
point: {
pointBorderWidth: 0.5, // less background at chart points
},
line: {
tension: 0.05
}
},
plugins: {
tooltip: {
callbacks: {
label: function (tooltipItem) {
return `${tooltipItem.dataset.label}: ${timeSeriesData[tooltipItem.dataIndex][3]}`
},
footer: function (tooltipItems) {
tooltipItem = tooltipItems[0];
return `Size: ${timeSeriesData[tooltipItem.dataIndex][2]}`
}
}
},
}
}
});
}
function display_chart(table) {
var table_data = get_table_data(table);
insert_chart("#chakra-modal--body-11", table_data);
}
function remove_cookie_product_visits(cookie_name) {
document.cookie = `${cookie_name}=1; expires=Sun, 31 Dec 2033 12:00:00 UTC; path=/;`;
}
const targetNode = document.body;
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
for (const node of mutation.addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
const tableNodes = node.querySelectorAll('.css-1ki54i');
if (tableNodes.length) {
for (const tableNode of tableNodes) {
display_chart(tableNode);
return;
}
}
}
}
}
}
});
observer.observe(targetNode, {
childList: true,
subtree: true
});
window.addEventListener('load', function load(e) {
window.removeEventListener('load', load, false);
remove_cookie_product_visits("stockx_product_visits")
}, false);