Created
December 22, 2021 15:37
-
-
Save maxsam4/a3ed6ddcf1d3a097ede43ab7fbf554c8 to your computer and use it in GitHub Desktop.
Coingecko portfolio tracker userscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Coingecko portfolio on Twitter | |
// @namespace https://mudit.blog/ | |
// @version 0.1 | |
// @description Replaces the What’s happening / Trending widget on Twitter with a Coingecko portfolio | |
// @author Mudit Gupta | |
// @match https://twitter.com/* | |
// @icon https://www.google.com/s2/favicons?domain=twitter.com | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js | |
// @grant GM_xmlhttpRequest | |
// @run-at document-idle | |
// ==/UserScript== | |
const coingeckoPortfolio = "https://www.coingecko.com/en/portfolios/public/BAh7BjoRcG9ydGZvbGlvX2lkaQPd5Hk=--90554ff6fc432f72ea28ac26d8426a7aa543dcdf"; | |
GM_xmlhttpRequest( { | |
method: "GET", | |
url: coingeckoPortfolio, | |
onload: parseResponse, | |
onerror: function(e) { console.error('**** error ', e); }, | |
onabort: function(e) { console.error('**** abort ', e); }, | |
ontimeout: function(e) { console.error('**** timeout ', e); } | |
} ); | |
function parseResponse(response) { | |
const parser = new DOMParser (); | |
const ajaxDoc = parser.parseFromString(response.responseText, "text/html"); | |
const statRows = ajaxDoc.querySelectorAll("table > tbody > tr"); | |
const newStatTable = $(statRows).map(function(){ | |
const tblRow = $(this); | |
const coinName = $(tblRow).find("td:eq(2)").text().trim(); | |
const coinPrice = $(tblRow).find("td:eq(3)").text().trim(); | |
return [[coinName, coinPrice]]; | |
}).get(); | |
console.log(newStatTable); | |
setTimeout(function() { | |
const coingeckoPortfolio = "https://www.coingecko.com/en/portfolios/public/BAh7BjoRcG9ydGZvbGlvX2lkaQOuBxs=--34bbcee155d70511b99ef37410eb94fc974b9925"; | |
const targetWidget = document.querySelector('[aria-label="Timeline: Trending now"]'); | |
let html = "<table>"; | |
for (const coin of newStatTable) { | |
html += `<tr><td>${coin[0]}</td><td>${coin[1]}</td></tr>`; | |
} | |
html += "</table>"; | |
targetWidget.innerHTML = html; | |
}, 2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment