Last active
September 11, 2018 15:16
-
-
Save 14eyes/7f80cfa828c1b77b9b9f357fd80b57e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name AB Download All Button | |
// @match https://animebytes.tv/torrents* | |
// @match https://animebytes.tv/better.php?action=* | |
// @exclude *id=* | |
// @grant none | |
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js | |
// ==/UserScript== | |
function getUrlVars() { | |
var vars = {}; | |
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { | |
vars[key] = value; | |
}); | |
return vars; | |
} | |
function getUrlParam(parameter, defaultvalue){ | |
var urlparameter = defaultvalue; | |
if(window.location.href.indexOf(parameter) > -1){ | |
urlparameter = getUrlVars()[parameter]; | |
} | |
return urlparameter; | |
} | |
var dllinks = []; | |
function getnewlinks() { | |
var dllinks = []; | |
var links = document.links; | |
for(var i=0; i<(links.length - 1); i++) { | |
if (links[i].href.includes("/download/") && links[i+1].className.indexOf('snatched-torrent')) { | |
dllinks.push(links[i].href); | |
//console.debug(links[i]); | |
} | |
} | |
var asize = document.getElementsByClassName('torrent_size'); | |
var tsize = 0; | |
for (let i=1; i<(asize.length); i++) { | |
var nsize = parseFloat(asize[i].innerText.replace(/[^0-9\.]+/g, "")); | |
if (!isNaN(nsize) && !JSON.stringify(asize[i].parentElement.cells[0].children[1].className).includes('snatched-torrent')) { | |
console.log(nsize); | |
if (asize[i].innerText.includes('MiB')) { | |
nsize = nsize * 1024; | |
} else if (asize[i].innerText.includes('GiB')) { | |
nsize = nsize * 1048576; | |
} else if (asize[i].innerText.includes('TiB')) { | |
nsize = nsize * 1073742000; | |
} | |
tsize = tsize + nsize; | |
console.log(nsize); | |
} | |
}if (tsize > 1073742000) {tsize = tsize / 1073742000; var stype = ' TiB'; | |
}else if (tsize > 1048576) {tsize = tsize / 1048576; stype = ' GiB'; | |
}else if (tsize > 1024) {tsize = tsize / 1024; stype = ' MiB'; | |
}else {stype = ' KiB';} | |
dlbutton.textContent = 'Download All (' + dllinks.length +')' + '[' + Math.round(tsize*100)/100 + stype + ']'; | |
} | |
var dlbutton = document.createElement('a'); | |
var refresh = document.createElement('a'); | |
dlbutton.href = '#'; | |
//refresh.href = '#'; | |
dlbutton.className = 'page-link'; | |
refresh.className = 'page-link'; | |
refresh.textContent = 'Refresh links'; | |
var isbetterpage = document.getElementById('torrent_table'); | |
if (document.querySelector('div.pagenums') !== null) { | |
document.querySelector('div.pagenums').appendChild(dlbutton); | |
document.querySelector('div.pagenums').appendChild(refresh); | |
} else if (window.location.href.indexOf('/torrents') !== -1) { | |
document.querySelector('div#browse_nav_bottom').appendChild(dlbutton); | |
document.querySelector('div#browse_nav_bottom').appendChild(refresh); | |
dlbutton.style= 'float: right;'; | |
refresh.style= 'float: right;'; | |
} else { | |
document.querySelector('div#searchbars').appendChild(dlbutton); | |
document.querySelector('div#searchbars').appendChild(refresh); | |
dlbutton.style= 'text-align: center'; | |
refresh.style= 'text-align: center'; | |
} | |
getnewlinks(); | |
//console.debug(dllinks); | |
function getTorrentId(torrentLink) { | |
return /\/torrent\/(\d+)\//.exec(torrentLink)[1]; | |
} | |
refresh.onclick = getnewlinks; | |
dlbutton.onclick = function openlinks() { | |
var dllinks = []; | |
var links = document.links; | |
for(var i=0; i<(links.length - 1); i++) { | |
if (links[i].href.includes("/download/") && links[i+1].className.indexOf('snatched-torrent')) { | |
dllinks.push(links[i].href); | |
//console.debug(links[i]); | |
} | |
} | |
var zip = new JSZip(); | |
for (i = 0; i < dllinks.length; ++i) { | |
zip.file(getTorrentId(dllinks[i]) + '.torrent', fetch(dllinks[i]).then(function(r) { | |
//console.log('Downloaded ' + r.url); | |
return r.blob(); | |
}), {binary: true}); | |
} | |
zip.generateAsync({type:"blob"}).then(function (blob) { | |
saveAs(blob, "ab_torrents.zip"); | |
}); | |
}; | |
// ==UserScript== | |
// @name Load Next Page (AB) | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Loads the next page with torrents | |
// @author DrPepper | |
// @match https://animebytes.tv/torrents.php* | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
var nextPage = parseInt(getUrlParam('page','1')); | |
function loadNextPage(tpage) { | |
nextPage++; | |
console.debug('loading page:'+ nextPage); | |
var xhr = new XMLHttpRequest(); | |
if (tpage == 1) { | |
xhr.open('GET', 'https://animebytes.tv/torrents.php?page=' + nextPage + | |
'&sort='+ (getUrlParam('sort','relevance')) + | |
'&way=' + (getUrlParam('way','desc')) + | |
'&searchstr='+ (getUrlParam('searchstr','')) + | |
'&showhidden=' + (getUrlParam('showhidden','0')) + | |
'&hentai=' + (getUrlParam('hentai','0')) + | |
'&tags=' + (getUrlParam('tags','')) + | |
'&search_type=' + (getUrlParam('search_type','title')) + | |
'&year=' + (getUrlParam('year','')) + | |
'&year2=' + (getUrlParam('year2','')) + | |
'&tags_type=' + (getUrlParam('tags_type','0')) + | |
'&action=' + (getUrlParam('action','advanced')) + | |
'&releasegroup=' + (getUrlParam('releasegroup','')) + | |
'&freeleech=' + (getUrlParam('freeleech','0')) + | |
'&exclusive=' + (getUrlParam('exclusive','0')) + | |
'&airing=' + (getUrlParam('airing','2')) + | |
'&epcount=' + (getUrlParam('epcount','')) + | |
'&epcount2=' + (getUrlParam('epcount2','')) + | |
'&artbooktitle=' + (getUrlParam('artbooktitle','')) | |
); | |
} else { | |
xhr.open('GET', 'https://animebytes.tv/torrents2.php?page=' + nextPage + | |
'&sort='+ (getUrlParam('sort','relevance')) + | |
'&way=' + (getUrlParam('way','desc')) + | |
'&artistnames='+ (getUrlParam('artistnames','')) + | |
'&showhidden=' + (getUrlParam('showhidden','0')) + | |
'&groupname=' + (getUrlParam('groupname','')) + | |
'&tags=' + (getUrlParam('tags','')) + | |
'&year=' + (getUrlParam('year','')) + | |
'&year2=' + (getUrlParam('year2','')) + | |
'&tags_type=' + (getUrlParam('tags_type','0')) + | |
'&freeleech=' + (getUrlParam('freeleech','0')) + | |
'&seriesnames=' + (getUrlParam('seriesnames','')) + | |
'&exclusive=' + (getUrlParam('exclusive','0')) + | |
'&remastertitle=' + (getUrlParam('remastertitle','')) | |
); | |
} | |
xhr.responseType = 'document'; | |
xhr.onload = function() { | |
if (xhr.readyState === xhr.DONE) | |
if (xhr.status === 200) { | |
let data = xhr.responseXML; | |
let container = document.getElementsByClassName('thin')[0]; | |
let nodes = data.getElementsByClassName('group_cont'); | |
[...nodes].forEach(node => container.insertBefore(node, container.lastElementChild)); | |
} | |
}; | |
xhr.send(null); | |
} | |
if (window.location.href.indexOf('/torrents') !== -1) { | |
let div = document.createElement('div'); | |
let button = document.createElement('input'); | |
let text_input = document.createElement('input'); | |
text_input.type = 'text'; | |
text_input.id = 'panumtl'; | |
text_input.value = '1'; | |
text_input.name = 'panumtl'; | |
button.className = 'page-link'; | |
button.type = 'button'; | |
button.value = 'Load More'; | |
button.onclick = function (){ | |
var pagestl = parseInt(document.getElementById('panumtl').value); | |
//console.log(pagestl); | |
for (var i = 0; i < pagestl; i++) { | |
if (window.location.href.indexOf('/torrents2.php') !== -1){ | |
loadNextPage(2); | |
} else { | |
loadNextPage(1); | |
} | |
} | |
getnewlinks(); | |
}; | |
div.style = 'text-align: center'; | |
div.appendChild(button); | |
div.appendChild(text_input); | |
document.getElementById('content').appendChild(div); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment