-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfbads_pull_data.js
66 lines (65 loc) · 2.26 KB
/
fbads_pull_data.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
(function () {
var getParams = function (url) {
var params = {};
var parser = document.createElement('a');
parser.href = url;
var query = parser.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
params[pair[0]] = decodeURIComponent(pair[1]);
}
return params;
};
var hrefs = document.getElementsByClassName('_99s5');
var logos_object = {
"sx_0800b2": "Facebook",
"sx_7ec8d4": "Instagram",
"sx_8a5fa4": "Audience Network",
"sx_79eef9": "Messenger"
};
var data = '';
var length = hrefs.length;
for (var i = 0; i < length; i++) {
var parentEl = hrefs[i];
var obj = {};
obj.date = parentEl.querySelector('div ._9cd3 span').innerHTML.replace('Started running on ', '');
obj.ad_id = parentEl.querySelector('div ._9cd3 ._4rhp').innerHTML.replace('ID: ', '');
obj.status = parentEl.querySelector('div ._9cd2').innerHTML;
obj.acn = '';
if(parentEl.querySelector('div ._7jyr')){
obj.acn = parentEl.querySelector('div ._7jyr').innerText;
}
obj.logos = [];
var logEl = parentEl.querySelectorAll('._2fyi span i');
for (var j = 0; j < logEl.length; j++) {
var _lcls = logEl[j].getAttribute('class').split(' ');
for (var k = _lcls.length - 1; k >= 0; k--) {
if (logos_object[_lcls[k]]) {
obj.logos[j] = logos_object[_lcls[k]];
break;
} else{
obj.logos[j] = _lcls[k];
break;
}
}
}
try {
var aurl = parentEl.querySelector('._4yee').getAttribute('href');
} catch (e) {
continue;
}
if (typeof aurl == "undefined") {
continue;
}
var urlParams = getParams(aurl);
if (typeof urlParams.u == "undefined") {
continue;
}
var url = new window.URL(urlParams['u']);
url.searchParams.delete('fbclid');
obj.url = url.toString();
data += JSON.stringify(obj) + '\n';
}
console.log(data);
})();