MediaWiki:Common.js: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 61: Line 61:
                 var node = nodes.snapshotItem(i);
                 var node = nodes.snapshotItem(i);


                 // find the person's name in the node, and surround it with a span and change the color to purple
                 // find the person's name in the node, and surround their name (in the innerhtml) with a span and change the color to purple. Make sure that the name only exists in the text, and not in the html (so we don't change the color of the link)
                 var name = node.textContent.match(/(.*?)(\s|$)/)[1];
                 var name = node.innerHTML.match(/^(.*?)\s/)[1];
                 var newNode = document.createElement('span');
                 var nameIndex = node.innerHTML.indexOf(name);
                 newNode.textContent = name;
                 var nameLength = name.length;
                 newNode.style.color = 'purple';
                var html = node.innerHTML;
                 node.replaceChild(newNode, node.firstChild);
                var text = node.textContent;
                var textIndex = text.indexOf(name);
                 var textLength = name.length;
                var startTag = '<span style="color:purple">';
                var endTag = '</span>';
                 var htmlStart = html.substring(0, nameIndex);
                var htmlEnd = html.substring(nameIndex + nameLength);
                var textStart = text.substring(0, textIndex);
                var textEnd = text.substring(textIndex + textLength);
                var newHtml = htmlStart + startTag + html.substring(nameIndex, nameIndex + nameLength) + endTag + htmlEnd;
 
                // replace the node's innerHTML with the new html
                node.innerHTML = newHtml;
                // this entire section was made by copilot cuz im too lazy to do it myself
             }
             }