Skip to content

Instantly share code, notes, and snippets.

@tamvm
Last active November 21, 2021 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamvm/55c762679c93c587b68bc497df188f58 to your computer and use it in GitHub Desktop.
Save tamvm/55c762679c93c587b68bc497df188f58 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Tulip Garden
// @namespace https://tulip.garden
// @version 0.1
// @description Sum of equity value
// @author You
// @match https://tulip.garden/your-positions
// @icon https://www.google.com/s2/favicons?domain=tulip.garden
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
function roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2");
}
function perform() {
var elements = document.querySelectorAll(".your-positions-table__row-item .your-positions-table__row-item__cell:nth-of-type(4) > div:nth-of-type(1)");
if (elements.length == 0) {
alert("No position found");
return;
}
var arr = [];
elements.forEach(function(element) {
var equityStr = element.innerText.replace(/(\$|,)/g, "");
var equity = parseFloat(equityStr)/1000;
if (equityStr.includes("M")) {
equity = equity * 1000000;
}
arr.push(roundToTwo(equity));
});
var total = arr.reduce((a, b) => a + b);
var output = total.toFixed(2) + "\n" + arr.join("\n");
GM_setClipboard (output);
console.log(output);
}
GM_registerMenuCommand('Copy equity value', function() {
perform();
}, "r");
window.addEventListener('keypress', function(e){
if (e.ctrlKey && e.key == "t") {
perform();
}
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment