Skip to content

Instantly share code, notes, and snippets.

@twanmulder
Last active February 1, 2022 13:36
Show Gist options
  • Save twanmulder/f08e0edd376479a0e5f9127ff841a167 to your computer and use it in GitHub Desktop.
Save twanmulder/f08e0edd376479a0e5f9127ff841a167 to your computer and use it in GitHub Desktop.
JS Script that extends looksrewards.org with your initial stake and the returns/difference. Replace INIT_LOOKS_STAKE with your own initial Looks stake amount.
(function () {
const INIT_EURO_INVESTMENT = 99999;
const INIT_ETH_STAKE = 99;
const INIT_LOOKS_STAKE = 9999;
let looksBalance = 0;
let ethBalance = 0;
let euroBalance = 0;
let hasSetupListeners = false;
waitForCards();
function waitForCards() {
looksBalance = 0;
ethBalance = 0;
console.log("waiting for cards");
const cards = document.querySelectorAll(".card");
if (cards.length < 12) {
setTimeout(waitForCards, 100);
} else {
waitForLooksBalance();
}
}
function waitForLooksBalance() {
console.log("waiting for LOOKS balance");
const LooksTextFields = document.querySelectorAll(".card")[6].querySelectorAll(".txt-smol");
if (LooksTextFields.length !== 2) {
setTimeout(waitForLooksBalance, 100);
} else {
const cleanedLooksValue = parseFloat(LooksTextFields[0].innerText.replace(/\(/g, "").replace(/\)/g, "").replace(/\s/g, "").replace(/LOOKS/g, "").replace(/\,/g, ""));
const cleanedLooksValueInEth = parseFloat(LooksTextFields[1].innerText.replace(/\(/g, "").replace(/\)/g, "").replace(/\s/g, "").replace(/ETH/g, "").replace(/\,/g, ""));
looksBalance = cleanedLooksValue;
ethBalance += cleanedLooksValueInEth;
waitForEthBalance();
}
}
function waitForEthBalance() {
console.log("waiting for ETH balance");
const EthTextField = document.querySelectorAll(".card")[9].querySelector(".txt-smol");
if (!EthTextField) {
setTimeout(waitForEthBalance, 100);
} else {
const cleadEthValue = parseFloat(EthTextField.innerText.replace(/\(/g, "").replace(/\)/g, "").replace(/\s/g, "").replace(/ETH/g, ""));
ethBalance += cleadEthValue;
waitForEuroBalance();
}
}
function waitForEuroBalance() {
console.log("waiting for EURO balance");
const LooksEuroField = document.querySelectorAll(".card")[6].querySelector(".card-body div:nth-child(2) div");
const EthEuroField = document.querySelectorAll(".card")[9].querySelector(".card-body div:nth-child(2) div");
const cleandLooksEuroValue = parseFloat(LooksEuroField.innerText.replace(/\s/g, "").replace(/€/g, "").replace(/\,/g, ""));
const cleanedEthEuroValue = parseFloat(EthEuroField.innerText.replace(/\s/g, "").replace(/€/g, "").replace(/\,/g, ""));
euroBalance = cleandLooksEuroValue + cleanedEthEuroValue;
renderToDom();
if (!hasSetupListeners) {
setupListeners();
hasSetupListeners = true;
}
}
function renderToDom() {
const looksEuroPrice = document.querySelectorAll(".card")[0].querySelector(".card-body div:nth-child(2)");
const cleanedLooksEuroPrice = parseFloat(looksEuroPrice.innerText.replace(/\s/g, "").replace(/€/g, "").replace(/\,/g, ""));
const container = document.querySelector(".container");
if (document.querySelector(".row--custom")) {
document.querySelector(".row--custom").remove();
}
const row = document.createElement("div");
row.classList.add("row");
row.classList.add("row--custom");
container.appendChild(row);
const initialLooksInvestment = document.createElement("div");
initialLooksInvestment.classList.add("col-md-4");
initialLooksInvestment.innerHTML = `
<div class="card mb-3">
<div class="card-body text-center">
<div>Initial Stake</div>
<div>LOOKS ${+INIT_LOOKS_STAKE.toFixed(6)}</div>
<div class="txt-smol">(at ETH ${+INIT_ETH_STAKE.toFixed(6)})</div>
</div>
</div>
`;
row.appendChild(initialLooksInvestment);
const looksDifference = +(looksBalance - INIT_LOOKS_STAKE).toFixed(6);
const looksDifferenceDiv = document.createElement("div");
const looksDifferenceCardClassname = looksDifference > 0 ? "card--green" : "card--red";
looksDifferenceDiv.className = "col-md-4";
looksDifferenceDiv.innerHTML = `
<div class="card ${looksDifferenceCardClassname} mb-3">
<div class="card-body text-center">
<div class="card-difference-title">Looks Earned</div>
<div class="card-difference">${looksDifference} <sup class="txt-smol">+${((looksDifference / INIT_LOOKS_STAKE) * 100).toFixed(2)}%</sup></div>
<div class="txt-smol">Currently worth ${(looksDifference * cleanedLooksEuroPrice).toLocaleString(undefined, {
style: "currency",
currency: "EUR",
})}</div>
</div>
</div>
`;
row.appendChild(looksDifferenceDiv);
const euroDifference = +(euroBalance - INIT_EURO_INVESTMENT).toFixed(2);
const euroDifferenceDiv = document.createElement("div");
const euroDifferenceCardClassname = euroDifference > 0 ? "card--green" : "card--red";
euroDifferenceDiv.className = "col-md-4";
euroDifferenceDiv.innerHTML = `
<div class="card ${euroDifferenceCardClassname} mb-3">
<div class="card-body text-center">
<div class="card-difference-title">Return On Investment</div>
<div class="card-difference">€${euroDifference} <sup class="txt-smol">${euroDifference > 0 ? "+" : ""}${((euroDifference / INIT_EURO_INVESTMENT) * 100).toFixed(2)}%</sup></div>
<div class="txt-smol">Current Value: ${euroBalance.toLocaleString(undefined, {
style: "currency",
currency: "EUR",
})}</div>
<div class="txt-smol">Initial Investment: ${INIT_EURO_INVESTMENT.toLocaleString(undefined, {
style: "currency",
currency: "EUR",
})}</div>
</div>
</div>
`;
row.appendChild(euroDifferenceDiv);
}
function setupListeners() {
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === "characterData") {
waitForCards();
}
});
});
const config = {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true,
};
observer.observe(document.documentElement, config);
}
const css = document.createElement("style");
css.innerHTML = `
.card--red {
border-color: rgb(127 29 29);
box-shadow: rgb(153 27 27 / 50%) 0px 25px 20px -17px, rgb(153 27 27 / 50%) 0px 4px 6px -4px;
}
.card--red sup{
color: rgb(239 68 68);
}
.card--green {
border-color: rgb(22 101 52);
box-shadow: rgb(20 83 45 / 50%) 0px 25px 20px -17px, rgb(20 83 45 / 50%) 0px 4px 6px -4px;
}
.card--green sup{
color: rgb(34 197 94);
}
`;
document.body.appendChild(css);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment