-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
193 lines (162 loc) · 6.63 KB
/
popup.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// HIGHLIGHTING DARK PATTERN
function scrapfrompage() {
try {
const validTags = ['P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'SPAN', 'DIV'];
const allElements = document.querySelectorAll(validTags.join(','));
const scrapedData = new Set();
for (let i = 0; i < allElements.length; i++) {
const element = allElements[i];
if (
element.textContent.trim() !== '' &&
!element.matches('script, style, html') &&
!element.closest('[onclick], [onmouseover], [onmouseout], [onkeydown], [onkeyup], [onfocus], [onblur], [mouseleave], [mousemove], [clientX], [clientY], [offsetX], [onresize], [onfocus], [onchange], [onmouseout], [onkeydown], [ondragstart], [ondblclick]')
) {
const textContent = element.textContent.trim();
if (textContent.length <= 70) {
scrapedData.add(textContent);
}
}
}
console.log(scrapedData);
scrapedData.forEach(data => {
fetch('http://localhost:3000/classify?text=' + encodeURIComponent(data))
.then(response => response.json())
.then(result => {
console.log(`Text: ${result.text}`);
console.log(`Predicted Label: ${result.label}`);
if (result.label === "1" && result.text.split(' ').length > 3) {
const tagsToHighlight = ['span', 'div'];
tagsToHighlight.forEach(tag => {
document.querySelectorAll(tag).forEach(element => {
const regex = new RegExp(`\\b(${result.text})\\b`, "gi");
element.innerHTML = element.innerHTML.replace(regex, (match) =>
`<span style="border: 3px solid red; padding: 2px; background-color: yellow; font-weight: bold; color:black;">${match}</span>`);
});
});
}
})
.catch(err => {
console.error(`Error: ${err}`);
});
});
} catch (err) {
console.error(`Error: ${err}`);
}
}
const scrap = document.getElementById('run');
scrap.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: scrapfrompage,
});
});
function tracker() {
const trackElement = document.getElementById('price');
if (trackElement) {
const track = trackElement.value; // Use .value instead of .innerHTML for input elements
// Make a POST request to your server
fetch('http://localhost:3000/track', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ trackData: track }),
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Server response:', data);
// Check if the request was successful
if (data.status === 'success') {
// Extract the first element of the seleniumResult array
const firstElement = data.seleniumResult[0]+data.seleniumResult[1]+data.seleniumResult[2];
// Display the result in the HTML element with id "result"
const resultElement = document.getElementById('result');
resultElement.textContent = firstElement;
} else {
console.error('Error:', data.message);
}
})
.catch(error => {
console.error('Fetch error:', error);
});
} else {
console.error('Element with id "price" not found');
}
}
const con = document.getElementById('track');
con.addEventListener('click', tracker);
// AD BLOCKER
let adblockStatus = {}; // Object to keep track of adblock status for each URL
document.addEventListener('DOMContentLoaded', () => {
const adblock = document.getElementById('blk');
adblock.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
toggleAdblock(tab.id, tab.url);
});
});
async function toggleAdblock(tabId, tabUrl) {
if (adblockStatus[tabUrl] === undefined) {
adblockStatus[tabUrl] = true; // Adblock is initially turned on
}
const shouldBlock = !adblockStatus[tabUrl]; // Invert the current status
adblockStatus[tabUrl] = shouldBlock; // Update the status
const url = new URL(tabUrl);
const domain = url.hostname;
chrome.scripting.executeScript({
target: { tabId: tabId },
func: setBlockStatus,
args: [domain, shouldBlock],
});
}
function setBlockStatus(domain, shouldBlock) {
if (shouldBlock) {
addblck(domain);
}
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('uploadButton').addEventListener('click', function () {
const fileInput = document.getElementById('imageInput');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
const img = document.createElement('img');
img.src = event.target.result;
img.style.maxWidth = '200px'; // Limit image width for preview
const previewDiv = document.getElementById('preview');
previewDiv.innerHTML = '';
previewDiv.appendChild(img);
};
reader.readAsDataURL(file);
} else {
alert('Please select an image file.');
}
});
});
function addblck(domain) {
console.log(`Blocking domain: ${domain}`);
const blockedDomains = [
'googlesyndication.com',
'pagead2.googlesyndication.com',
'googleads.g.doubleclick.net',
'linkbucks.com',
'adf.ly',
'doubleclick.com',
'doubleclicksolutions.com',
'doubleclick.net',
'googleadservices.com',
'ads.github.com',
];
console.log("Blocking started");
const url = new URL(domain);
const domainname = url.hostname;
if (blockedDomains.includes(domainname)) {
return { cancel: true }
}
}