// ==UserScript== // @name (-FORK-) RARBG - torrent and magnet links // @namespace darkred,Micdu70 // @version 2019.4.18 // @description Adds a column with torrent and magnet links in RARBG lists // @author darkred,Micdu70 // @contributor sxe // @license MIT // @include /^(https?:)?\/\/(www\.)?(rarbg(\.(bypassed|unblockall|unblocked))?|rarbgaccessed|rarbgaccess|rarbgget|rarbgmirror|rarbgproxy|rarbgproxied|rarbgprx|rarbgs|rarbgto|rarbgunblock|proxyrarbg|unblocktorrent)\.(to|com|org|is|xyz|lol|vc|link)\/(rarbg-proxy-unblock\/)?(torrents\.php.*|catalog\/.*|top10)$/ // @grant none // @downloadURL https://update.greasyfork.icu/scripts/382000/%28-FORK-%29%20RARBG%20-%20torrent%20and%20magnet%20links.user.js // @updateURL https://update.greasyfork.icu/scripts/382000/%28-FORK-%29%20RARBG%20-%20torrent%20and%20magnet%20links.meta.js // ==/UserScript== function appendColumn(title) { var entries = document.querySelectorAll('.lista2t > tbody > tr > td:nth-child(2) '); // the initial column 'Files' after of which the extra column will be appended // creation of the extra column for (let i = 0; i < entries.length; i++) { entries[i].insertAdjacentHTML('afterend', `
>';
newColumn[i].lastChild.title = 'DL via XHR';
newColumn[i].innerHTML += '
>';
newColumn[i].lastChild.title = 'ML via XHR';
}
}
function addMouseoverListeners(links, type){
for(let i=0; i < links.length; i++) {
links[i].addEventListener('mouseover', function(event){
event.preventDefault();
let href = this.getAttribute('href');
if (href === '#') {
let tLink = this.getAttribute('data-href');
var xhr = new XMLHttpRequest();
xhr.open('GET', tLink, true); // XMLHttpRequest.open(method, url, async)
xhr.onload = function () {
let container = document.implementation.createHTMLDocument().documentElement;
container.innerHTML = xhr.responseText;
let retrievedLink;
if (type === 'dl'){
retrievedLink = container.querySelector('a[href^="/download.php"]'); // the 'magnet link' element in the retrieved page
} else {
retrievedLink = container.querySelector('a[href^="magnet:"]'); // the 'magnet link' element in the retrieved page
}
if (retrievedLink) {
links[i].setAttribute('href', retrievedLink.href);
}
};
xhr.send();
}
}, false);
}
}
appendColumn('DL ML');
var xhrDownloadLinks = document.querySelectorAll('.xhrDownloadLink');
var xhrMagnetLinks = document.querySelectorAll('.xhrMagnetLink');
addMouseoverListeners(xhrDownloadLinks, 'dl' );
addMouseoverListeners(xhrMagnetLinks, 'ml' );