和 Codex 一块儿搓了个新前端 hu60next
『回复列表(125|隐藏机器人聊天)』
<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>
还有,你们觉得翻页的过渡动画观感好吗?我不太喜欢,运动速度太快让人眼花缭乱,而且帖子内容多的话用时也很久,不如直接一步到位跳转到应该去的位置。
关键是运动的次数太多了,随便做点什么就一直滚来滚去:
明明点了输入框末尾,但是上传的附件却出现在了开头。
解决方法请参考以下代码(在找不到编辑点的时候应该追加到末尾而非开头):
function insertText(obj, str) {
if (document.selection) {
var sel = document.selection.createRange();
sel.text = str;
} else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
var startPos = obj.selectionStart,
endPos = obj.selectionEnd,
cursorPos = startPos,
tmpStr = obj.value;
obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
cursorPos += str.length;
obj.selectionStart = obj.selectionEnd = cursorPos;
} else {
obj.value += str;
}
}
还有关于定位点的一个想法:我会想在翻页之后继续看到翻页器。这样有两个好处:
还有,虎绿林的@消息链接是可以定位到具体楼层的
https://hu60.cn/q.php/bbs.topic.107456.html?floor=112#112
新前端丢失了这个能力。
我顺便说一下,如果前端尊重用户在个人中心里的楼层排序设置,那就不能用page=xxx定位楼层,要用floor=xxx,然后前端自己算出来在当前的配置下是在第几页。不对,不用前端算,直接把floor=xxx&pageSize=xxx传给JSON API就行了,后端会算好然后给出对应的页。
目前的新消息提醒只有一个按钮,但是我有新的@消息,点进去之后却还是默认进入私信,但我没有新私信,就会很困惑。应该有什么类型的消息就点进哪个页面。还有前端应该知道用户每种类型消息的未读数量,在导航栏是不是也可以显示一下未读气泡。(气泡已经有了。)
还有,私信目前也不能直接回复,也没有聊天模式,比较不方便。
其实之前有人建议我把聊天模式作为私信的唯一显示模式,就是首页只显示谁给你发消息以及最后一条消息,展开直接是你和他的聊天记录。我一直没去改接口。
还有,@我的的图标也是@,就成了@@我的,有点不和谐。可能改个名比较好,比如“提醒”。Jhin主题的顶部用的就是“提醒”。