-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfdv.js
108 lines (93 loc) · 3.4 KB
/
fdv.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
// Function to calculate and display the Fully Diluted Valuation (FDV) with dynamic coloring based on MCAP to FDV ratio
function displayFDVWithDynamicColoring() {
const rows = document.querySelectorAll(".cmc-table tbody tr");
for (const row of rows) {
const marketCapSpan = row.querySelector(
'td:nth-child(8) span[data-nosnippet="true"]'
);
const circulatingSupplyColumn = row.querySelector("td:nth-child(10)");
const fdvElementExists = row.querySelector(".custom-fdv");
if (fdvElementExists || !marketCapSpan || !circulatingSupplyColumn)
continue;
const marketCap = Number.parseFloat(
marketCapSpan.textContent.replace(/[$,]/g, "")
);
const progressBar = circulatingSupplyColumn.querySelector(
'div[class^="sc-c50b4d85-1"]'
);
let fdv;
let fdvText;
let fdvColor;
if (progressBar) {
const progressBarWidth = progressBar.clientWidth;
const containerWidth = progressBar.parentNode.clientWidth;
const completionPercentage = progressBarWidth / containerWidth;
fdv = marketCap / completionPercentage;
const ratio = ((fdv - marketCap) / marketCap) * 100;
// Determine color based on MCAP to FDV ratio
if (ratio <= 10) {
fdvColor = "var(--up-color)"; // Green
} else if (ratio <= 50) {
fdvColor = "#f6b87e"; // Yellow
} else {
fdvColor = "var(--down-color)"; // Red
}
fdvText = `FDV: <span style="color: ${fdvColor};">${Math.floor(fdv)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}</span>`;
} else {
fdvText = "FDV: ∞";
}
// Theme-dependent class selection
const pClass = document.body.classList.contains("NIGHT")
? "sc-4984dd93-0 bpmdQz"
: "sc-4984dd93-0 ihZPK";
// Create and append the FDV element
const fdvElement = document.createElement("span");
fdvElement.className = `${pClass} custom-fdv`; // Apply theme-dependent class
fdvElement.style.display = "block";
fdvElement.style.marginTop = "1px";
fdvElement.innerHTML = fdvText;
const marketCapContainer = marketCapSpan.parentNode;
if (marketCapContainer) {
marketCapContainer.appendChild(fdvElement);
}
}
}
// Initiate FDV display with dynamic coloring and observe for changes
function initFDVDynamicDisplay() {
displayFDVWithDynamicColoring();
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type === "childList") {
displayFDVWithDynamicColoring();
}
}
});
const table = document.querySelector(".cmc-table tbody");
if (table) {
observer.observe(table, { childList: true, subtree: true });
} else {
console.log("CMC table not found.");
}
// Theme change observer to update FDV elements' classes
const themeObserver = new MutationObserver(() => {
for (const fdvElement of document.querySelectorAll(".custom-fdv")) {
fdvElement.className = document.body.classList.contains("NIGHT")
? "sc-4984dd93-0 bpmdQz custom-fdv"
: "sc-4984dd93-0 ihZPK custom-fdv";
}
});
themeObserver.observe(document.body, {
attributes: true,
attributeFilter: ["class"],
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initFDVDynamicDisplay);
} else {
initFDVDynamicDisplay();
}
console.log(
"FDV Script with dynamic coloring initialized and monitoring for updates."
);