nixxo / rarbg fixer - extras

// ==UserScript==
// @name		rarbg fixer - extras
// @namespace	rarbg fixer - extras
// @homepage    https://openuserjs.org/scripts/nixxo/rarbg_fixer_-_extras
// @license     MIT
// @description	Adds Direct Torrent Download link to the torrent list and some cleaning from Azev's old script.
// @updateURL	https://openuserjs.org/install/nixxo/rarbg_fixer_-_extras.user.js
// @downloadURL	https://openuserjs.org/install/nixxo/rarbg_fixer_-_extras.user.js
// @author		Nixxo
// @version		1.2.2
// @grant		none
// @icon		https://dyncdn.me/static/20/img/logo_dark_nodomain2_optimized.png
// @include     http*://*rarbg.com/*
// @include     http*://*rarbg.to/*
// ==/UserScript==

//Changelog
//1.2.1 - removed an alert, sry
//1.2 - fixed ads link detection

/* OPTIONS */
var ADD_DL_LINK = true;

/*Since Azev discontinued his old script I picked the two feature i liked the most*/
var HIDE_RECOMMENDED	= true; // hide 'recommended'
var HIDE_DDL_ADS 		= true; // hide 'direct download' (ads)

function addDlLink(node, id, name) {
    var a, img;
    img = document.createElement('img');
    img.setAttribute('src','https://dyncdn.me/static/20/img/16x16/download.png');
    a = document.createElement('a');
    a.setAttribute('href', 'https://rarbg.com/download.php?id=' + id + '&f=' + name + '.torrent');
    a.appendChild(img);
    a.style.padding = '0 5px 0 0';
    node.insertBefore(a, node.childNodes[0]);
}

if (ADD_DL_LINK) {
	elms = document.getElementsByClassName("lista2");
	for (i=0; i < elms.length; i++) {
        var lnk = elms[i].getElementsByTagName("a");
        for (y=0; y < lnk.length; y++) {
            var mtc = lnk[y].outerHTML.match(/href\=\"\/torrent\/(.+)\"\s.+>(.+)<\/a>/);
            if (mtc) {
                addDlLink(lnk[y].parentNode,mtc[1],mtc[2] );
                break;
           }
        }
	}
}


/* hide iframes */
elms = document.getElementsByTagName("iframe");
for (i=0; i < elms.length; i++) {
	elms[i].style.display = 'none';
	elms[i].src = 'about:blank';
}

/* hide direct download links (ads) */
if (HIDE_DDL_ADS) {
	elms = document.getElementsByTagName("a");
	for (i=0; i < elms.length; i++) {
		if ( elms[i].href.indexOf('adpub.php') !=-1 ){
			elms[i].parentNode.parentNode.style.display = 'none';
			elms[i].href='#';
		}
	}
}

/* hide 'recommended' covers */
if (HIDE_RECOMMENDED) {
	if (  document.documentElement.innerHTML.indexOf('Recommended torrents') !=-1 ){
		elms = document.getElementsByClassName("lista");
		for (i=5; i <= 12; i++) {
				elms[i].style.display = 'none';
		}
	}
	elms = document.getElementsByTagName("b");
	for (i=0; i < elms.length; i++) {
		if ( elms[i].innerHTML.indexOf('Recommended torrents :') !=-1 ) elms[i].style.display = 'none';
	}
}