-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
58 lines (51 loc) · 1.78 KB
/
content.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
// Inform the background page that
// this tab is initialized.
chrome.runtime.sendMessage({
from: "content",
subject: "init",
});
// Listen for messages from the popup.
chrome.runtime.onMessage.addListener((msg, sender, response) => {
// First, validate the message's structure.
if (msg.from === "popup" && msg.subject === "capture") {
window.scrollTo(0, document.body.scrollHeight);
// Collect the necessary data.
// (For your specific requirements `document.querySelectorAll(...)`
// should be equivalent to jquery's `$(...)`.)
setTimeout(() => {
var photoSquares = document.querySelectorAll(".v1Nh3.kIKUG._bz0w");
var photoLinks = [];
photoSquares.forEach((element) =>
photoLinks.push(element.querySelector("a").href)
);
var domInfo = {
total: document.querySelector(".g47SY").textContent,
photos: photoLinks,
profile: /.com\/([^']*)\//.exec(location.href)[1],
};
response(domInfo);
}, 3000);
return true;
// Directly respond to the sender (popup),
// through the specified callback.
}
if (msg.from === "popup" && msg.subject === "baseInfo") {
var baseInfo = {
total: document.querySelector(".g47SY").textContent,
profile: /.com\/([^']*)\//.exec(location.href)[1],
};
// Directly respond to the sender (popup),
// through the specified callback.
response(baseInfo);
}
if (msg.from === "popup" && msg.subject === "scrollDown") {
window.scrollTo(0, document.body.scrollHeight);
// var baseInfo = {
// total: document.querySelector(".g47SY").textContent,
// profile: /.com\/([^']*)\//.exec(location.href)[1],
// };
// Directly respond to the sender (popup),
// through the specified callback.
response(null);
}
});