111 lines
No EOL
3.6 KiB
JavaScript
111 lines
No EOL
3.6 KiB
JavaScript
// ==UserScript==
|
|
// @name AB Quick Download
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 1.1
|
|
// @description Download a page worth of torrents from AB
|
|
// @author metonym
|
|
// @match https://animebytes.tv/torrents.php*
|
|
// @match https://animebytes.tv/better/single*
|
|
// @match https://animebytes.tv/torrents2.php*
|
|
// @match https://animebytes.tv/alltorrents.php*
|
|
// @match https://animebytes.tv/collage.php*
|
|
// @exclude https://animebytes.tv/torrents*action=editgroup*
|
|
// @grant none
|
|
// @icon https://animebytes.tv/favicon.ico
|
|
// ==/UserScript==
|
|
const TIME_TO_WAIT = 1500;
|
|
|
|
function delete_download_buttons() {
|
|
const buttons = document.querySelectorAll("a.nym_download_button");
|
|
console.log(buttons);
|
|
buttons.forEach((button) => {
|
|
button.parentNode.removeChild(button);
|
|
});
|
|
}
|
|
|
|
function create_download_buttons() {
|
|
var dl_links = document.querySelectorAll('a[title="Download torrent"]');
|
|
var snatched_links = document.querySelectorAll("a.snatched-torrent");
|
|
|
|
let snatched = []
|
|
snatched_links.forEach((elm, i, arr) => {
|
|
let torrent_id = elm.href.split("torrentid=")[1];
|
|
snatched.push(torrent_id);
|
|
});
|
|
|
|
|
|
if (!dl_links.length || dl_links.length === 0) {
|
|
return;
|
|
}
|
|
|
|
let all_links = [];
|
|
let not_snatched_links = [];
|
|
dl_links.forEach((elm) => {
|
|
let torrent_id = elm.href.split("/")[4];
|
|
if (!snatched.includes(torrent_id)) {
|
|
not_snatched_links.push(elm);
|
|
}
|
|
all_links.push(elm);
|
|
});
|
|
|
|
if (!all_links.length || all_links.length === 0) {
|
|
return;
|
|
}
|
|
|
|
let linkboxes = document.querySelectorAll("div .linkbox");
|
|
|
|
let open_all_dl_links_button = document.createElement("a");
|
|
open_all_dl_links_button.href = "#open_all_dl_links";
|
|
open_all_dl_links_button.className = "nym_download_button";
|
|
open_all_dl_links_button.onclick = () => { open_dl_links(all_links) };
|
|
open_all_dl_links_button.innerText = ` [Download ${all_links.length} torrents]`;
|
|
linkboxes[0].prepend(open_all_dl_links_button);
|
|
|
|
let open_not_snatched_dl_links_button = document.createElement("a");
|
|
if (not_snatched_links.length > 0) {
|
|
open_not_snatched_dl_links_button.className = "nym_download_button";
|
|
open_not_snatched_dl_links_button.href = "#open_not_snatched_dl_links";
|
|
open_not_snatched_dl_links_button.onclick = () => { open_dl_links(not_snatched_links) };
|
|
open_not_snatched_dl_links_button.innerText = `[Download ${not_snatched_links.length} not snatched torrents]`;
|
|
linkboxes[0].prepend(open_not_snatched_dl_links_button);
|
|
}
|
|
|
|
if (linkboxes.length > 1) {
|
|
let button_copy = open_all_dl_links_button.cloneNode(true);
|
|
button_copy.onclick = () => { open_dl_links(all_links) };
|
|
linkboxes[linkboxes.length - 1].append(button_copy);
|
|
|
|
if (not_snatched_links.length > 0) {
|
|
button_copy = open_not_snatched_dl_links_button.cloneNode(true);
|
|
button_copy.onclick = () => { open_dl_links(not_snatched_links) };
|
|
linkboxes[linkboxes.length - 1].append(button_copy);
|
|
}
|
|
}
|
|
}
|
|
|
|
function open_dl_links(links) {
|
|
links.forEach((link, i) => {
|
|
link.setAttribute('download', '')
|
|
setTimeout(() => link.click(), TIME_TO_WAIT * i);
|
|
});
|
|
}
|
|
|
|
function entry() {
|
|
'use strict';
|
|
|
|
// Your code here...
|
|
const table = document.getElementById('torrent_table');
|
|
create_download_buttons();
|
|
|
|
// listen for any updates if more rows were dynamically added
|
|
const observer = new MutationObserver(() => {
|
|
delete_download_buttons();
|
|
create_download_buttons();
|
|
});
|
|
|
|
if (table != undefined) {
|
|
observer.observe(table.getElementsByTagName('tbody')[0], {childList: true});
|
|
}
|
|
};
|
|
|
|
entry(); |