-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
36 lines (30 loc) · 1009 Bytes
/
Copy pathcontent.js
File metadata and controls
36 lines (30 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let targetTexts = [];
// 저장된 키워드 불러오기
chrome.storage.sync.get("keywords", (data) => {
if (data.keywords) targetTexts = data.keywords;
});
// storage 변경 감지
chrome.storage.onChanged.addListener((changes) => {
if (changes.keywords) targetTexts = changes.keywords.newValue;
});
// 중복 알림 방지를 위한 Set
let alertedTexts = new Set();
// DOM 변화 감시
const observer = new MutationObserver(() => {
const bodyText = document.body.innerText;
targetTexts.forEach(text => {
if (bodyText.includes(text) && !alertedTexts.has(text)) {
alert(`Found: ${text}`);
alertedTexts.add(text); // 중복 알림 방지
}
});
});
// body 하위 모든 DOM 변화 감지
observer.observe(document.body, { childList: true, subtree: true });
// 초기 로딩 시도 감지
targetTexts.forEach(text => {
if (document.body.innerText.includes(text)) {
alert(`발견됨: ${text}`);
alertedTexts.add(text);
}
});