I am trying to create a twitter extension in which I want to add an extra button along with all other like / bookmark buttons. For that I am using appendChild and diff other functions. But they only add the button to one node , when I update another , the previous is vanished.
var btn = document.createElement("button");
btn.innerHTML = "Bookmark";
btn.id = "bookmark-btn";
function insertAfter(newNode, existingNode) {
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}
ready("article", (article) => {
const tweet = article.querySelector("div[role=group]");
insertAfter( btn, tweet.childNodes[2] )
// I also tried tweet.appendChild(btn);
});