Skip to content

Instantly share code, notes, and snippets.

@SakuraKoi
Last active October 27, 2021 02:08
Show Gist options
  • Save SakuraKoi/d388e3d4d30b501ac37ce5419ab521e4 to your computer and use it in GitHub Desktop.
Save SakuraKoi/d388e3d4d30b501ac37ce5419ab521e4 to your computer and use it in GitHub Desktop.
Debank Approval - Custom token name Userscript
// ==UserScript==
// @name Debank Approve Custom Token Name
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://debank.com/profile/*/approve?*
// @icon https://www.google.com/s2/favicons?domain=debank.com
// @grant none
// ==/UserScript==
(function () {
'use strict';
function updateCustomName() {
var contacts = document.getElementsByClassName("Approve_rightIconBalance__2M60z");
for (var entry of contacts) {
if (entry.innerHTML.indexOf("unknow") != -1) {
var container = entry.children[0].children[1].children[0];
var unknownNode = container.getElementsByClassName("Approve_tag__2Gjdw")[0];
var nameNode = unknownNode.parentNode.children[0];
var addrNode = container.getElementsByTagName("a")[0];
var contactNameCustom = localStorage.getItem("contactName_" + addrNode.innerText);
if (contactNameCustom != null) {
nameNode.innerText = contactNameCustom;
} else {
nameNode.innerText = "Unknwon contact";
}
}
}
}
function editCustomName(event, addr) {
var customName = prompt("Custom token name for " + addr);
if (customName != null && customName != "") {
localStorage.setItem("contactName_" + addr, customName);
updateCustomName();
}
}
function updateTable() {
var contacts = document.getElementsByClassName("Approve_rightIconBalance__2M60z");
for (var entry of contacts) {
if (entry.innerHTML.indexOf("unknow") != -1) {
var container = entry.children[0].children[1].children[0];
var unknownNode = container.getElementsByClassName("Approve_tag__2Gjdw")[0];
var nameNode = unknownNode.parentNode.children[0];
var addrNode = container.getElementsByTagName("a")[0];
nameNode.innerText = "Unknwon contact";
unknownNode.style.setProperty("display", "none");
var btn = document.createElement("div");
btn.classList.add("Approve_tag__2Gjdw");
btn.innerText = "Edit";
nameNode.parentNode.insertBefore(btn, null);
btn.addEventListener("click", editCustomName.bind(null, event, addrNode.innerText));
}
}
updateCustomName();
}
var observeDOM = (function () {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
return function (obj, subtree, callback) {
if (!obj || obj.nodeType !== 1)
return;
if (MutationObserver) {
var mutationObserver = new MutationObserver(callback);
mutationObserver.observe(obj, {
childList: true,
subtree: subtree
});
return mutationObserver;
} else if (window.addEventListener) {
obj.addEventListener('DOMNodeInserted', callback, false);
obj.addEventListener('DOMNodeRemoved', callback, false);
}
}
})()
var interv = setInterval(function () {
var table = document.getElementsByClassName("Approve_tableContainer__3ECd9")[0];
if (table) {
clearInterval(interv);
observeDOM(table, false, updateTable);
}
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment