You can try replacing every instance of a comma or period with an html <a>
tag containing your url. This question explains a good format of replacing text in a webpage, shown below. In your case, you would want to use two commands (after defining a function similar to the one below). First, replaceTextOnPage('.', '<a>your link here</a>');
and second replaceTextOnPage(',', '<a>your link here</a>');
. Thus, you would replace every comma (,)
with one link, and every period (.)
with another (or the same link, if you wish). I hope this helps!
function replaceTextOnPage(from, to){
getAllTextNodes().forEach(function(node){
node.nodeValue = node.nodeValue.replace(new RegExp(quote(from), 'g'), to);
});
function getAllTextNodes(){
var result = [];
(function scanSubTree(node){
if(node.childNodes.length)
for(var i = 0; i < node.childNodes.length; i++)
scanSubTree(node.childNodes[i]);
else if(node.nodeType == Node.TEXT_NODE)
result.push(node);
})(document);
return result;
}
function quote(str){
return (str+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
}