Hey, so I'm injecting a button into webpage like this:
function AddButton()
{
const nameBoxPath = "/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[2]/div/div/div/div/div/div/div/div/div/div[1]/div/div/div[1]/div";
var nameBox = document.evaluate(nameBoxPath,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
if(nameBox !== null)
{
var button = document.querySelectorAll(".copy_contact_button")
if(button.length > 0)
{
alert("Button already exists");
}
else
{
alert("Button created");
var btn = document.createElement("button");
btn.classList.add("copy_contact_button");
btn.appendChild(document.createTextNode("Copy"));
btn.addEventListener('click', function()
{
alert("event");
window.postMessage({ type: "FROM_PAGE_TO_CONTENT_SCRIPT", text: "Hello from the webpage!" }, "*");
});
nameBox?.appendChild(btn);
}
}
else
{
}
}