-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
67 lines (58 loc) · 1.98 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
59
60
61
62
63
64
65
66
67
// 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 `$(...)`.)
var photoCards = document.querySelectorAll(".food.card.feed-item");
var photoInfo = [];
photoCards.forEach((element) => {
var photoWrapper = element.querySelector(".food-image");
var photoId = /\/f\/([^']*)/.exec(
photoWrapper.querySelector("a").href
)[1];
console.log(photoId);
var photoLink = /([^']*)\?/.exec(
photoWrapper.querySelector("img").src
)[1];
console.log(photoLink);
var photoPlace = element.querySelector(".card-item-set--link-title")
.textContent;
var photoAddress = element.querySelector(".card-item-set--link-subtitle")
.textContent;
console.log(photoPlace.trim());
console.log(photoAddress.trim());
photoInfo.push({
id: photoId,
link: photoLink,
place: photoPlace.trim(),
address: photoAddress.trim(),
});
});
var domInfo = {
photoInfo: photoInfo,
};
response(domInfo);
// Directly respond to the sender (popup),
// through the specified callback.
}
if (msg.from === "popup" && msg.subject === "baseInfo") {
var baseInfo = {
total: document.querySelector(".profile-page__stats > ul > li")
.textContent,
profile: /.com\/@([^']*)\//.exec(location.href)[1],
link: /([^']*)\/timeline/.exec(location.href)[1],
};
// Directly respond to the sender (popup),
// through the specified callback.
response(baseInfo);
}
});