-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
55 lines (48 loc) · 1.84 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
chrome.runtime.sendMessage({
from: 'content',
subject: 'showPageAction'
});
chrome.runtime.onMessage.addListener(function (msg, sender, response) {
// First, validate the message's structure
if ((msg.from === 'popup') && (msg.subject === 'CountInfo')) {
// Collect the necessary data
// (For your specific requirements `document.querySelectorAll(...)`
// should be equivalent to jquery's `$(...)`)
var viewsCount = 0;
var showsCount = 0;
var likesCount = 0
var count = 0;
$('.publication-card-item__stat-main-text').each(function(ind, item){
if (($(item).text() == 'просмотров') || ($(item).text() == 'просмотра') || ($(item).text() == 'просмотр')) {
count = $(item).parent().find('.publication-card-item__stat-main-count').text();
if (count.endsWith('тыс.')){
count = parseInt(count.slice(0, count.length-5))*1000;
} else {
count = parseInt(count);
}
viewsCount = viewsCount + count;
}
if (($(item).text() == 'показов в ленте') || ($(item).text() == 'показ в ленте')) {
count = $(item).parent().find('.publication-card-item__stat-main-count').text();
if (count.endsWith('тыс.')){
count = parseInt(count.slice(0, count.length-5))*1000;
} else {
count = parseInt(count);
}
showsCount = showsCount + count;
}
});
$('.publication-card-item__stat-likes').each(function(ind, item){
count = parseInt($(item).find('.publication-card-item__stat-count').text());
likesCount = likesCount + count;
});
var info = {
views: viewsCount,
shows: showsCount,
likes: likesCount
}
// Directly respond to the sender (popup),
// through the specified callback */
response(info);
}
});