-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
70 lines (57 loc) · 2.53 KB
/
script.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
68
69
70
const API = 'https://nyaaapi.herokuapp.com/sukebei/real?query='
let JAVTitle = document.getElementById('video_id').getElementsByClassName('text')[0].innerText
let songInfoElement = document.getElementsByClassName('socialmedia')[0]
let torrentElement = document.createElement('div')
let torrentsCount = 0
let torrents = []
let pageCount = 0
function insertAfter(referenceNode, newNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
function inflator(torrents) {
let string = `<div id="video_reviews"><div class="header">Torrents</div><table class="table-recently-updated" width="100%"><hr class="grey"><tbody>`
for (let i = (5 * pageCount); i < ((5 * pageCount) + endLimitDiscriminator()); i++) {
string += `<tr><div class="torrents"><div>
<div><a style="font-size: 14px;" href="${torrents[i].magnet}"> ${torrents[i].title}</a><a style="font-size: 14px;"> (${torrents[i].size}) <a href="${torrents[i].link}">Ⓘ</a></div>
</span><p style="margin: 0px; margin-bottom: 10px; float:left; color: green; font-size: 14px;">${torrents[i].seeders}↑</p><p style="margin: 0px; margin-bottom: 10px; float:left; color: red; font-size: 14px;">${torrents[i].leechers}↓ </p></div>
<p style="margin: 0px; margin-bottom: 10px; font-size: 14px;">${torrents[i].time}</p></div></td></tr>`
}
string += `</tbody></table><center><a style="font-size: 14px;"><p id="torrent-current-page">${pageCount+1}/${pages()}</center><center><a onclick="pageBack();" style="font-size: 14px; margin-right: 5px; cursor: pointer;">⋘ </a><a onclick="pageNext();" style="font-size: 14px; cursor: pointer;"> ⋙</a></center>`
torrentElement.innerHTML = string
}
function pageNext() {
if (torrentsCount >= ((pageCount + 1) * 5)) {
pageCount += 1
inflator(torrents)
}
}
function pageBack() {
if (pageCount != 0) {
pageCount -= 1
inflator(torrents)
}
}
function endLimitDiscriminator() {
if (pageCount >= parseInt(torrentsCount / 5)) {
return torrentsCount % 5
} else {
return 5
}
}
function pages() {
return (parseInt(torrentsCount / 5) + 1)
}
try {
fetch(API + JAVTitle + '&sort=seeders&order=desc')
.then((response) => {
console.log(response)
response.json().then((res) => {
torrents = res.data
torrentsCount = res.count
inflator(res.data)
insertAfter(songInfoElement, torrentElement)
})
})
} catch (err) {
console.log(err)
}