The scenario is via a browser extension (Add-On) a link's Text of unknown length on a page is changed to another textual value. The new Textual value must be the same length as the original ensuring that the site's formatting is not altered in any way.
However, I just can't wrap my head around the logic - and I am not a Javascript coder which does not help any.
var GenerateNewLinkText = function(txt) {
var tLen = txt.length; // text original Length
var ls = "404";
var lm1 = "Removed";
var lm2 = "7ASecond";
var ll = "Removed By 7ASecond";
var nText = "[";
var letterCounter = 0;
for (var idx = 0; idx < (tLen-2); idx++) {
if (tLen < 5) {
nText += ".";
}
else if (tLen >= 5 || tLen < 9) {
var extraChars = tLen - ls;
}
}
nText += "]";
return nText;
}
UPDATE 1
link text prior to change could be like these examples
1) Download (8 chars) 2) Click to Download (17 chars) 3) Preview (7 chars) 4) http://somedomain.com/jhdfshjkhk (32 Characters)
link text after change would be 1) [ 404 ] (8 chars) 2) [ Removed ] (17 chars) 3) [ 404 ] (7 Chars) 4) [ Removed By 7ASecond ] (32 Chars)
The above code is incomplete but does show the idea I am attempting. Any and all help would be appreciated!