I have a chrome extension written in pure JS which is basically composed of functions which append data to links on the page.
An example of the functions which basically just appends a click integer to the link element passed in from another function:
function addCounttoLinks(link, counts) {
var clicks = counts.split(":")[1].split(",")[0].trim();
var count = document.createTextNode((" (" + clicks + ")"));
var dspan = document.createElement("span");
dspan.appendChild(count);
dspan.style.fontSize = "10px"; dspan.style.textAlign = "center";
link.appendChild(dspan);
}
What is the most efficient way to execute/unexecute these functions, so that I can implement a "on/off" button for the user to click which would add/remove the data appended by the extension. Is the only solution to write functions to remove the previously created elements?