@Fox
d79e653c-983c-4f27-8c5c-d0eadc4b30e4-image.png
Thank you, my brother, your actions are really extraordinary and able to solve my problem according to my expectations, once again thank you, my brother.
I want to use JavaScript to solve the problem of finding keywords on a web page. I open a web page and want to check 3 requirements:
I have tried many different ways, but I still encounter an issue with the following case:
Example text to check: "Vietnam"
Keyword to check: "vi"
The methods I tried all resulted in: "true"
However, I want the result to be "false" when the keyword is a part of another word. Please help me.
// Lấy nội dung của trang web và chuyển về chữ thường
var pageContent = document.body.innerHTML.toLowerCase();
// Từ khoá cần kiểm tra và chuyển về chữ thường
var keyword = [[KEY_SEARCH]];
// Tạo biểu thức chính quy để kiểm tra từ khoá trong các liên kết và anchor text
var linkRegex = new RegExp(>[^<]\b${keyword}\b[^<]<a[^>]>|>[^<]\b${keyword}\b[^<]*</a>, 'ig');
// Kiểm tra từ khoá trong các liên kết và anchor text
var keywordInLinks = linkRegex.test(pageContent);
// Loại bỏ các thẻ <a> sau khi đã kiểm tra
var pageContentWithoutLinks = pageContent.replace(linkRegex, ">");
// Kiểm tra từ khoá trong văn bản ngoài các liên kết (với word boundary)
var keywordInText = new RegExp(\b${keyword}\b, 'g').test(pageContentWithoutLinks);
[[XUAT_HIEN_TRONG_LINK]] = keywordInLinks
[[XUAT_HIEN_TRONG_VAN_BAN]] = keywordInText