JSFiddle - React, Tailwind, and code Playground
HTML
<a href="http://url.nyc.com">http://url.nyc.com</a>
<br>
<a href="http://smodev.rye.foo.com">http://smodev.rye.foo.com</a>
<br>
<a href="http://url1.com">http://url1.com</a>
<br>
<a href="http://www.url2.com">http://www.url2.com</a>
<br>
<a href="http://www.url3.com">http://www.url3.com</a>
JavaScript
var URLChecker = (function iffe() {
var publicAPI = {
getURL: function() {
for (var i = 0; i < arguments.length; i++) {
return {
'smo': 'http://url.nyc.com',
'smodev': 'http://smodev.rye.foo.com',
'url1_sans_3w': 'http://url1.com',
'url2': 'http://www.url2.com',
'url3': 'http://www2.url3.com'
}[arguments[i]];
}
},
searchURL: function() {
var link, url;
for(var i = 0, len = arguments.length; i < len; i++) {
url = this.getURL(arguments[i]);
console.log(url, arguments[i]);
for (var j = 0, jlen = document.links.length; j < jlen; j++) {
link = document.links[j];
if (link.href.indexOf(url) !== -1) {
link.setAttribute("target", "_blank");
}
}
}
}
};
return publicAPI;
})();
URLChecker.searchURL('smo', 'smodev');