// ==UserScript== // @name House of Usenet - AutoThxAndDownloader // @description Auto presses thanks and triggers the download and closes tab after download. You only have to open the entry you want to download in a new tab. // @version 1.2 // @grant none // @author UnFairlight // @license MIT // @namespace unfairlight.hou.autothxanddownloader // @run-at document-end // @match https://house-of-usenet.com/showthread.php?tid=* // @downloadURL none // ==/UserScript== /* jshint esversion: 6 */ //check links in breadcrumbs if (document.querySelector("[href='forumdisplay.php?fid=13']") !== null || //Movies document.querySelector("[href='forumdisplay.php?fid=58']") !== null || //Series document.querySelector("[href='forumdisplay.php?fid=14']") !== null || //Music document.querySelector("[href='forumdisplay.php?fid=70']") !== null || //Docus document.querySelector("[href='forumdisplay.php?fid=6']") !== null || //Games document.querySelector("[href='forumdisplay.php?fid=26']") !== null //Cine ) { //presses thx btns var loopBtns = function(i, thxBtns) { console.log("btn", thxBtns[i]); if (thxBtns[i].style.display != "none") { console.log("thx btn is not hidden"); thxBtns[i].click(); let postId = thxBtns[i].id.match(/\d+/)[0]; console.log("postId", postId); let lastThx = (i + 1 >= thxBtns.length); console.log("lastThx", lastThx); setTimeout(function() { triggerDL(postId, 0, lastThx); }, getRandomDelay()); } else { console.log("thx btn is hidden"); } i++; if (i < thxBtns.length) { setTimeout(function() { loopBtns(i, thxBtns); }, getRandomDelay()); } else { } }; //clicks on download var triggerDL = function(postId, tryC, lastThx) { let post = document.querySelector("[id^='post_" + postId + "']"); console.log("post", post); let dlLink = post.querySelector("[class^='exito_thx message'] a"); if (dlLink !== null) { console.log("dlLink", dlLink); dlLink.click(); if (lastThx) { setTimeout(function() { window.close(); }, getRandomDelay()); } } else { tryC++; if ( tryC <= 5) { setTimeout(function() { triggerDL(postId, tryC, lastThx); }, getRandomDelay()); } } }; //random delay to avoid getting banned var getRandomDelay = function() { return 2001 + Math.floor(Math.random() * 1500); }; document.addEventListener("keyup", function(e) { if (e.keyCode == 68) { console.log("d pressed"); var thxBtns = document.querySelectorAll("[id^='add_thx']"); console.log("thxBtns", thxBtns); if (thxBtns.length > 0) { loopBtns(0, thxBtns); } else { console.log("No thx btns found!"); } } }); //todo: make this configurable (auto download or only on keypress d //trigger d press to start download setTimeout(function() { document.dispatchEvent(new KeyboardEvent('keyup', { 'keyCode': 68 })); }, getRandomDelay()); }