-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
63 lines (45 loc) · 1.64 KB
/
service-worker.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
console.log("This prints to the console of the service worker (background script)")
const allElements = document.getElementsByTagName('*');
for (let i = 0; i < allElements.length; i++) {
const element = allElements[i];
if (element.tagName === 'A') {
continue;
}
const textContent = element.textContent.trim();
console.log(textContent);
}
//highlighting the word
// // Define the word to highlight
// const wordToHighlight = "Accessories";
// // Create a regular expression to match the word globally
// const regex = new RegExp(wordToHighlight, "gi");
// // Function to inject the content script and highlight the word
// function highlightWord(tabId) {
// chrome.tabs.executeScript(tabId, {
// file: "content.js"
// }, function() {
// chrome.tabs.sendMessage(tabId, {
// action: "highlight",
// word: wordToHighlight,
// regex: regex.source
// });
// });
// }
// // Listen for a click on the browser action button
// chrome.browserAction.onClicked.addListener(function(tab) {
// // Call the highlightWord function when the button is clicked
// highlightWord(tab.id);
// });
// chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
// if (message.action === "highlight") {
// const word = message.word;
// const regex = new RegExp(`\\b${word}\\b`, "gi");
// chrome.tabs.executeScript(null, {
// code: `
// Array.from(document.getElementsByTagName("body")).forEach(function(element) {
// element.innerHTML = element.innerHTML.replace(${regex}, '<span style="background-color: yellow;">$&</span>');
// });
// `
// });
// }
// });