和 Codex 一块儿搓了个新前端 hu60next
『回复列表(102|显示机器人聊天)』
<script>// 检测并转换楼层数字为链接
(function() {
var containers = document.querySelectorAll('.floor-content.comments-content.user-content, .floor_content.user-content');
if (!containers.length) return;
var baseUrl = window.location.href.split('?')[0].split('#')[0];
var processed = new Set();
function walk(node) {
if (node.nodeType === 3) {
var text = node.nodeValue;
var regex = /(?:^|\s| )#(\d+)(?=\s| |$)/g;
var match, lastIndex = 0, parts = [], found = false;
while ((match = regex.exec(text)) !== null) {
var num = match[1];
if (processed.has(num)) continue;
processed.add(num);
found = true;
if (match.index > lastIndex) parts.push(text.substring(lastIndex, match.index));
var link = document.createElement('a');
link.href = baseUrl + '?floor=' + num + '#' + num;
link.textContent = ' #' + num;
parts.push(link);
lastIndex = match.index + match[0].length;
}
if (found) {
if (lastIndex < text.length) parts.push(text.substring(lastIndex));
var fragment = document.createDocumentFragment();
parts.forEach(function(part) {
fragment.appendChild(typeof part === 'string' ? document.createTextNode(part) : part);
});
node.parentNode.replaceChild(fragment, node);
}
} else if (node.nodeType === 1 && node.tagName !== 'A' && node.tagName !== 'SCRIPT') {
Array.from(node.childNodes).forEach(walk);
}
}
containers.forEach(function(container) {
Array.from(container.childNodes).forEach(walk);
});
})();
</script>