-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanidb.js
43 lines (38 loc) · 1.08 KB
/
anidb.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
window.nyaaleech = {
name: function() {
var nameEl = document.body.querySelector('.g_section.info .pane.info tbody tr:first-child .value'),
name;
if (nameEl) {
name = nameEl.firstChild.nodeValue;
/* Some names contain a link. In this case the first child is the name plus a new line and a (, like here:
Uchuu Kyoudai
(<a class="shortlink" href="http://anidb.net/a8865">a8865</a>)
* We remove everything including and after the new line as it's not relevant for us.
*/
name = name.replace(/\n.*/g, '')
return name;
}
},
groups: function() {
var groupElements = document.body.querySelectorAll('.g_section.groups .grouplist td.name.group a'),
groups = [],
group,
i;
if (groupElements) {
for (i = 0; i < groupElements.length; i++) {
group = groupElements[i].firstChild.nodeValue;
if (group !== 'no group') {
groups.push(group);
}
}
}
return groups;
}
};
chrome.extension.onMessage.addListener(function(req, sender, rsp) {
var anime = {
name: nyaaleech.name(),
groups: nyaaleech.groups()
};
rsp(anime);
});