// ==UserScript==
// @name RARBG Advanced Filters [BETA]
// @namespace http://tampermonkey.net/
// @version 1.13
// @description Additional filters
// @author Kxmode
// @match *://rarbg.to/*
// @grant none
// @require //ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @downloadURL none
// ==/UserScript==
$(document).ready(function() {
// .PLAN:
// - Grid layout
// - torrent category, IMDB, icons sorting
// - Hides torrents with seeders equal to or lower than 10
// - Large grid icon
// - Minimalist layout: e.g. torrent thumbnail, name, # of seeders
// - show or hide advanced filters based on this button's event (looks like: [ << ], next to search input)
// - filter counter
// Default Values
showhideadvsearch('show');
var showIcons;
var showTorrentThumbnails; // TODO: child of showIcons (=true)
var showMoviesTVFilters;
var showPorn;
var minRating;
function ToggleFilter(target, data, bool)
{
var targetID = target.replace("#","");
if (bool) {
$(target).find("i").removeClass("fa-eye-slash").addClass("fa-eye");
$(target).removeClass("disabled");
$(target).attr(data, "true");
window.localStorage.setItem(targetID, true);
}
else
{
$(target).find("i").removeClass("fa-eye").addClass("fa-eye-slash");
$(target).addClass("disabled");
$(target).attr(data, "false");
window.localStorage.setItem(targetID, false);
}
}
$("#searchTorrent").parent().addClass("new-search");
// Removes extra space between Recommended torrents and search bar (Unsure what they're for)
$("#searchTorrent").parent().parent().find("div:nth-of-type(2)").remove();
for(var i = 1; i <= 4; i++)
{
$("#searchTorrent").parent().parent().find("br:nth-of-type(1)").remove();
}
$("head").append( '');
$("head").append( "');
var AdvancedFiltersHTML = '
\n' +
'
\n' +
'
Thumbnails
\n' +
'
Torrent Images
\n' + // Eventually make this a child of Show Thumbnails
'
Media Filters
\n' + // Eventually break this up
'
Porn
\n' +
'
\n' +
'
\n' +
'
Min Rating
\n' + // Not working with decimal values
'
\n' +
'
\n' +
'Update Page with Filters\n' +
'
\n' +
'
\n' +
'
';
// #shadvbutton - show / hide advanced filters based on this button's event. Button looks like: [ << ]
$("#searchTorrent").parent().append(AdvancedFiltersHTML);
showIcons = ((window.localStorage.getItem("jQIcons") == "false") ? false : true);
ToggleFilter("#jQIcons", "data-thumbs", showIcons);
showTorrentThumbnails = ((window.localStorage.getItem("jQTorrentThumbnails") == "false") ? false : true);
ToggleFilter("#jQTorrentThumbnails", "data-torrent-thumbs", showTorrentThumbnails);
showMoviesTVFilters = ((window.localStorage.getItem("jQMoviesTVFilters") == "false") ? false : true);
ToggleFilter("#jQMoviesTVFilters", "data-tvmovie", showMoviesTVFilters);
showPorn = ((window.localStorage.getItem("jQShowPorn") == "false") ? false : true);
ToggleFilter("#jQShowPorn", "data-porn", showPorn);
$("#jQIcons").on("click", function() {
showIcons = ($(this).attr("data-thumbs") == "false") ? true : false;
ToggleFilter("#jQIcons", "data-thumbs", showIcons);
});
$("#jQTorrentThumbnails").on("click", function() {
showTorrentThumbnails = ($(this).attr("data-torrent-thumbs") == "false") ? true : false;
ToggleFilter("#jQTorrentThumbnails", "data-torrent-thumbs", showTorrentThumbnails);
});
$("#jQMoviesTVFilters").on("click", function() {
showMoviesTVFilters = ($(this).attr("data-tvmovie") == "false") ? true : false;
ToggleFilter("#jQMoviesTVFilters", "data-tvmovie", showMoviesTVFilters);
});
$("#jQShowPorn").on("click", function() {
showPorn = ($(this).attr("data-porn") == "false") ? true : false;
ToggleFilter("#jQShowPorn", "data-porn", showPorn);
});
// Hides torrents with IMDB ratings equal to or lower than minRating
if (window.localStorage.getItem("minimum-rating") > 0) {
var mr = window.localStorage.getItem("minimum-rating");
$("#jQminRating").find("input").attr("value", mr);
minRating = mr;
}
else
{
$("#jQminRating").find("input").attr("value", 0);
}
$(".jQUpdateFilters").on("click", function () {
var minRating = $("#jQminRating").parent().find("input").val();
window.localStorage.setItem("minimum-rating", minRating);
location.reload();
});
// Hides Porn link
if (!showPorn)
{
$.each($(".tdlinkfull2"), function() {
var targetText = $(this).text().toLowerCase();
if (targetText == "xxx")
{
$(this).parent().parent().remove();
}
});
$.each($(".divadvscat a"), function() {
var targetText = $(this).text().toLowerCase();
if(targetText == "xxx (18+)")
{
$(this).parent().remove();
}
});
}
// Hides torrents with seeders equal to or lower than 10 [TODO: make this a form input filter]
// use inArray method from work (Configurator height normalizer)
/*
if (parseInt(title.indexOf("720p")) > 0)
{
$(this).parents(".lista2").remove();
}
*/
/*
* BEGIN: CATEGORY SPECIFIC =================================================================================================
*/
// Iterates through line items
$.each($(".lista a"), function(index, value) {
var title = $(this).attr("title");
var icon = $(this).find("img").attr("src");
/*
* BEGIN: MOVIES AND TV =================================================================================================
*/
if (showMoviesTVFilters)
{
// Skips torrents without titles
if (title !== undefined)
{
// Loop through every span tag inside the lista class anchor tag
$.each($("span"), function(index, value) {
var ratings = $(this).text();
var imdb = ratings.indexOf("IMDB: ") + 6;
// Continue if this span has IMDB rating information
if (ratings !== undefined && imdb !== -1)
{
var rateValue = parseFloat(ratings.substring(imdb,ratings.length-3));
// Continue if this IMDB rating is a number
if (!isNaN(rateValue))
{
$(this).attr("style", "display: block;");
// Continue if the torrent's rating is equal to or less than the minRating
if (rateValue <= minRating)
{
$(this).parents(".lista2").remove();
}
}
}
});
// Hides low-quality KORSUB torrents [TODO: make this a form checkbox filter]
if (parseInt(title.indexOf("KORSUB")) > 0)
{
$(this).parents(".lista2").remove();
}
// Hides 720p torrents [TODO: make this a form checkbox filter]
if (parseInt(title.indexOf("720p")) > 0)
{
$(this).parents(".lista2").remove();
}
}
}
/*
* BEGIN: PORNOGRAPHY =================================================================================================
*/
if (!showPorn)
{
// Hides from list
if (title !== undefined)
{
title = title.indexOf("XXX");
if (title >= 0)
{
$(this).parents(".lista2").remove();
}
}
// Hides based on icon
if (icon !== undefined)
{
icon = icon.indexOf("cat_new4.gif");
if (icon >= 0)
{
$(this).parents(".lista2").remove();
}
}
}
});
/*
* BEGIN: NON-CATEGORY =================================================================================================
*/
// Hides the icons
if (!showIcons)
{
$(".lista2t tr td:nth-of-type(1)").attr("style","display:none;");
}
else
{
// TODO: Make child of showIcons (=true)
if (showTorrentThumbnails)
{
$.each($(".lista2t .lista2"), function() {
var anchor = $(this);
$.each(anchor.find(".lista"), function() {
var image = $(this).find("a");
var target = anchor.find(":nth-child(1) a");
if (image.attr("onmouseover") !== undefined)
{
var href = image.attr("href");
var sourceThumb = image.attr("onmouseover");
var val1 = sourceThumb.lastIndexOf("//dyncdn.me/");
var val2 = sourceThumb.indexOf("\' border=0>')")-1;
var imageID = sourceThumb.substring(val1,val2);
var thumbnailImage = "
";
image.removeAttr("onmouseover").removeAttr("onmouseout");
target.find("img").replaceWith(thumbnailImage);
target.attr("href", href);
anchor.find("td:nth-child(1)").attr( "align", "center" );
}
});
});
}
}
/*
TODO: Filter counter [ALPHA]
$(".container-sales").prepend("\n" +
"
\n" +
"357 products shown\n" +
"135 products hidden\n" +
"\n" +
"
\n" +
"
");
*/
});