fix not found el
This commit is contained in:
parent
d96884ab75
commit
56744403c6
|
|
@ -2,15 +2,13 @@
|
|||
import { messageApi } from "@/api/message-api.service";
|
||||
|
||||
export class TeamsChatService {
|
||||
private readonly MY_NAME = "Apactech com";
|
||||
// private readonly MY_NAME = "Apactech com";
|
||||
public lastMessage?: IMessage;
|
||||
public initialHistories: IMessage[] = [];
|
||||
|
||||
public elTags = {
|
||||
container_scroll:
|
||||
"/html/body/div[1]/div/div/div/div[5]/div[1]/div[1]/div[2]/div[1]/div[1]/div",
|
||||
conatainer_conversations:
|
||||
"/html/body/div[1]/div/div/div/div[5]/div[1]/div[1]/div[2]/div[1]/div[1]/div/div[1]",
|
||||
container_scroll: '//*[@data-testid="simple-collab-rail"]',
|
||||
conatainer_conversations: '//*[@data-testid="simple-collab-dnd-rail"]',
|
||||
container_chat: '[data-testid="message-wrapper"]',
|
||||
|
||||
root_id: '[aria-selected="true"] [id^="chat-list-item"]',
|
||||
|
|
@ -24,13 +22,13 @@ export class TeamsChatService {
|
|||
private _getImageFormEl(el: HTMLElement): HTMLImageElement[] {
|
||||
// Tìm tất cả img có data-gallery-src trong el
|
||||
let sharedImages = Array.from(
|
||||
el.querySelectorAll("img[data-gallery-src]")
|
||||
el.querySelectorAll("img[data-gallery-src]"),
|
||||
) as HTMLImageElement[];
|
||||
|
||||
// Nếu không tìm thấy thì thử tìm trong parentElement
|
||||
if (sharedImages.length === 0 && el.parentElement) {
|
||||
sharedImages = Array.from(
|
||||
el.parentElement.querySelectorAll("img[data-gallery-src]")
|
||||
el.parentElement.querySelectorAll("img[data-gallery-src]"),
|
||||
) as HTMLImageElement[];
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +172,7 @@ export class TeamsChatService {
|
|||
|
||||
// Lấy emoji
|
||||
const emojiImgs = Array.from(
|
||||
el.querySelectorAll("img[itemtype]")
|
||||
el.querySelectorAll("img[itemtype]"),
|
||||
) as HTMLImageElement[];
|
||||
const emojiAlts = emojiImgs
|
||||
.map((img) => img.getAttribute("alt") || "")
|
||||
|
|
@ -189,11 +187,11 @@ export class TeamsChatService {
|
|||
|
||||
public parseMessageElement(el: Element, isMine = false): IMessage | null {
|
||||
const timestampEl = el.querySelector(
|
||||
isMine ? ".fui-ChatMyMessage__timestamp" : ".fui-ChatMessage__timestamp"
|
||||
isMine ? ".fui-ChatMyMessage__timestamp" : ".fui-ChatMessage__timestamp",
|
||||
) as HTMLElement | null;
|
||||
|
||||
const authorEl = el.querySelector(
|
||||
isMine ? ".fui-ChatMyMessage__author" : ".fui-ChatMessage__author"
|
||||
isMine ? ".fui-ChatMyMessage__author" : ".fui-ChatMessage__author",
|
||||
) as HTMLElement | null;
|
||||
|
||||
if (!timestampEl) return null;
|
||||
|
|
@ -207,7 +205,7 @@ export class TeamsChatService {
|
|||
: Number(timestampEl.id.replace("timestamp-", ""));
|
||||
|
||||
const contentEl = document.querySelector(
|
||||
`#content-${dateTime}`
|
||||
`#content-${dateTime}`,
|
||||
) as HTMLElement | null;
|
||||
|
||||
(contentEl as any)["date_time"] = dateTime;
|
||||
|
|
@ -242,13 +240,13 @@ export class TeamsChatService {
|
|||
|
||||
extractAllMessages(): IMessage[] {
|
||||
const myMessages: IMessage[] = Array.from(
|
||||
document.querySelectorAll(".fui-ChatMyMessage")
|
||||
document.querySelectorAll(".fui-ChatMyMessage"),
|
||||
)
|
||||
.map((el) => this.parseMessageElement(el, true))
|
||||
.filter((msg): msg is IMessage => msg !== null);
|
||||
|
||||
const otherMessages: IMessage[] = Array.from(
|
||||
document.querySelectorAll(".fui-ChatMessage")
|
||||
document.querySelectorAll(".fui-ChatMessage"),
|
||||
)
|
||||
.map((el) => this.parseMessageElement(el, false))
|
||||
.filter((msg): msg is IMessage => msg !== null);
|
||||
|
|
@ -267,7 +265,7 @@ export class TeamsChatService {
|
|||
const allMessages = this.extractAllMessages();
|
||||
|
||||
const lastIndex = allMessages.findIndex(
|
||||
(msg) => msg.time === this.lastMessage?.time
|
||||
(msg) => msg.time === this.lastMessage?.time,
|
||||
);
|
||||
|
||||
const newMessages = allMessages.slice(lastIndex + 1);
|
||||
|
|
@ -302,14 +300,14 @@ export class TeamsChatService {
|
|||
}
|
||||
|
||||
private async _getConversationsInfo(
|
||||
xpath: string = this.elTags.conatainer_conversations
|
||||
xpath: string = this.elTags.conatainer_conversations,
|
||||
): Promise<ChatItem[]> {
|
||||
const result = document.evaluate(
|
||||
xpath,
|
||||
document,
|
||||
null,
|
||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
||||
null
|
||||
null,
|
||||
).singleNodeValue as HTMLElement | null;
|
||||
|
||||
if (!result) {
|
||||
|
|
@ -321,15 +319,16 @@ export class TeamsChatService {
|
|||
return [];
|
||||
}
|
||||
|
||||
// Lọc phần tử con có role="none"
|
||||
const matchedChildren = Array.from(result.children).filter(
|
||||
(child: Element) => {
|
||||
return child.getAttribute("role") === "none";
|
||||
}
|
||||
const chatItems = Array.from(
|
||||
result.querySelectorAll('[data-item-type="chat"]'),
|
||||
);
|
||||
|
||||
const data: ChatItem[] = matchedChildren.map((child: Element): ChatItem => {
|
||||
const id = child.id || null;
|
||||
const data: ChatItem[] = chatItems.map((child: Element): ChatItem => {
|
||||
const treeItemValue =
|
||||
child.getAttribute("data-fui-tree-item-value") || "";
|
||||
const lastSegment = treeItemValue.split("/").pop() || "";
|
||||
const id = lastSegment.includes("|") ? lastSegment.split("|")[1] : null;
|
||||
|
||||
const titleId = `title-chat-list-item_${id}`;
|
||||
const titleElement = document.getElementById(titleId);
|
||||
const spanText = titleElement?.innerText || null;
|
||||
|
|
@ -360,7 +359,7 @@ export class TeamsChatService {
|
|||
maxStableRounds?: number; // Số vòng scroll không thay đổi trước khi dừng
|
||||
delay?: number; // Thời gian chờ giữa mỗi lần scroll (ms)
|
||||
maxScrolls?: number; // Giới hạn số lần scroll tối đa
|
||||
}
|
||||
},
|
||||
): Promise<void> {
|
||||
const {
|
||||
maxStableRounds = 5,
|
||||
|
|
@ -373,7 +372,7 @@ export class TeamsChatService {
|
|||
document,
|
||||
null,
|
||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
||||
null
|
||||
null,
|
||||
).singleNodeValue as HTMLElement | null;
|
||||
|
||||
if (!container) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue