(username, remark)
| 569 | |
| 570 | // 新增:实时更新好友弹窗中的内容 |
| 571 | function updateFriendsDialogWithNewUser(username, remark) { |
| 572 | const friendsDialog = document.getElementById('friends-dialog'); |
| 573 | if (!friendsDialog) return; |
| 574 | |
| 575 | // 移除可能存在的空提示 |
| 576 | const emptyDiv = friendsDialog.querySelector('div:last-child'); |
| 577 | if (emptyDiv && emptyDiv.textContent === '暂无好友') { |
| 578 | emptyDiv.remove(); |
| 579 | } |
| 580 | |
| 581 | // 获取最新的好友信息 |
| 582 | const friends = getFriends(); |
| 583 | const friend = friends.find(f => f.username === username); |
| 584 | if (!friend) return; |
| 585 | |
| 586 | // 查找或创建表格 |
| 587 | let table = friendsDialog.querySelector('table'); |
| 588 | if (!table) { |
| 589 | // 如果没有表格,创建一个 |
| 590 | table = document.createElement('table'); |
| 591 | table.style.width = '100%'; |
| 592 | table.style.borderCollapse = 'collapse'; |
| 593 | table.innerHTML = '<thead><tr>' |
| 594 | + '<th style="text-align:left;font-size:13px;width:70px;">用户名</th>' |
| 595 | + '<th style="text-align:left;font-size:13px;width:110px;">备注</th>' |
| 596 | + '<th style="text-align:left;font-size:13px;width:100px;padding-left:8px;">添加时间</th>' |
| 597 | + '<th style="width:48px;text-align:right;"></th></tr></thead>'; |
| 598 | |
| 599 | const tableWrapper = document.createElement('div'); |
| 600 | tableWrapper.style.overflowX = 'auto'; |
| 601 | tableWrapper.appendChild(table); |
| 602 | |
| 603 | const tbody = document.createElement('tbody'); |
| 604 | table.appendChild(tbody); |
| 605 | friendsDialog.appendChild(tableWrapper); |
| 606 | } |
| 607 | |
| 608 | const tbody = table.querySelector('tbody'); |
| 609 | if (!tbody) return; |
| 610 | |
| 611 | // 创建新行 |
| 612 | const tr = document.createElement('tr'); |
| 613 | tr.style.borderBottom = '1px solid #eee'; |
| 614 | tr.style.opacity = '0'; // 初始透明 |
| 615 | tr.style.transition = 'opacity 0.3s ease-in'; |
| 616 | |
| 617 | // 用户名列 |
| 618 | const tdUser = document.createElement('td'); |
| 619 | const nameLink = document.createElement('a'); |
| 620 | |
| 621 | // 从pmUrl中提取用户ID,构建主页链接 |
| 622 | let userId = null; |
| 623 | if (friend.pmUrl) { |
| 624 | const match = friend.pmUrl.match(/\/notification#\/message\?mode=talk&to=(\d+)/); |
| 625 | if (match) { |
| 626 | userId = match[1]; |
| 627 | } |
| 628 | } |
nothing calls this directly
no test coverage detected