// ==UserScript==
// @name RARBG Advanced Filters [No Porn Edition]
// @namespace http://tampermonkey.net/
// @version 1.55
// @description Just like RARBG Advanced Filters with the benefit of permanently removing pornography for those who would rather not see such content. Forked off of v1.42.
// @author Kxmode
// @contributor darkred
// @license MIT
// @include /^(https?:)?\/\/(www\.)?(proxy|unblocked)?rarbg((2018|2019|2020|2021)?|access(ed)?|cdn|core|data|enter|get|go|index|mirror(ed)?|p2p|prox(ied|ies|y)|prx|to(r|rrents)?|unblock(ed)?|way|web)\.(to|com|org|is)\/((index\d{2}|torrents)\.php.*|catalog\/.*|s\/.*|tv\/.*|top10)$/
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @run-at document-idle
// @downloadURL none
// ==/UserScript==
const $ = (window).$;
$(function() {
// Define general variables
var nonStandardUrlParams = (GetParameterByName("category%5B%5D") !== null || GetParameterByName("category[]") !== null) ? true : false,
arrayCurrentUrlParams = -1,
showAdvancedOptions = false,
showIcon,
showTorrentThumbnail, // TODO: child of showIcon (=true)
showMoviesTVFilters,
genreFilter = "",
currentUrlNormal,
currentUrlAbnormal,
i;
// Define Category specific filters
var minRating,
searchGenre,
gameGroup,
musicGenre,
showKORSUB,
show720p;
// Define array of known RARBG categories
var arrayMovies = ["movies", 14, 17, 42, 44, 45, 46, 47, 48, 50, 51, 52, 54].map(String),
arrayTVShows = [18, 41, 49].map(String),
arrayGames = [27, 28, 29, 30, 31, 32, 40].map(String),
arrayMusic = [23, 24, 25, 26].map(String),
arraySoftware = [33, 34, 43].map(String),
arrayNonPorn = [14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52].map(String);
// Define conditional checks
var isCategoryMovies,
isCategoryTVShows,
isCategoryGames,
isCategoryMusic,
isCategorySoftware,
isCategoryNonPorn;
// Define booleans
var categoryMoviesArray,
categoryTVShowsArray,
categoryGamesArray,
categoryMusicArray,
categorySoftwareArray,
categoryNonPornArray;
// This logic normalizes RARBG's inconsistent URL parameter types (e.g. category=movies, category%5B%5D=48, category=1;18;41;49;, and category[]=42)
if (nonStandardUrlParams)
{
currentUrlNormal = new RegExp("[\?&]category%5B%5D=([^]*)").exec(window.location.href); // Grab all URL parameters %5B%5D
currentUrlAbnormal = new RegExp("[\?&]category\[[^\[\]]*\]=([^]*)").exec(window.location.href); // Grab all URL parameters []
if (currentUrlNormal === null && currentUrlAbnormal === null) // If neither unique parameter exists, then stop this logic, and return nothing
{
return null;
}
else // Otherwise...
{
if (currentUrlAbnormal !== null) // If URL parameters is [] (abnormal)
{
arrayCurrentUrlParams = String(currentUrlAbnormal).match(/(=)\w+/g).map(String); // Create an array of values separated by the equal sign
}
else // Otherwise conclude URL parameters are normal (%5B%5D)
{
arrayCurrentUrlParams = String(currentUrlNormal).match(/(=)\w+/g).map(String); // Create an array of values separated by the equal sign
}
for (i = 0; i < arrayCurrentUrlParams.length; i++) // Iterate through array look for equal signs
{
arrayCurrentUrlParams[i] = arrayCurrentUrlParams[i].replace("=", ""); // Remove the equal sign from the array
}
}
}
else if (GetParameterByName("category") !== null || arrayCurrentUrlParams.length > -1) // Otherwise this is a standard URL parameter
{
arrayCurrentUrlParams = GetParameterByName("category").split(";").map(String); // Create an array of values separated by the semicolon
}
// Compares current url parameters with known RARBG categories. If the value is greater than -1 we have at least one match.
if (GetParameterByName("category") !== null || arrayCurrentUrlParams.length > -1)
{
// Navigate through each array to find and set the match to true. For now there can only be one match.
for (i = 0; i < arrayCurrentUrlParams.length; i++)
{
isCategoryMovies = arrayMovies.indexOf(arrayCurrentUrlParams[i]);
categoryMoviesArray = (isCategoryMovies !== -1) ? true : false;
}
for (i = 0; i < arrayCurrentUrlParams.length; i++)
{
isCategoryTVShows = arrayTVShows.indexOf(arrayCurrentUrlParams[i]);
categoryTVShowsArray = (isCategoryTVShows !== -1) ? true : false;
}
for (i = 0; i < arrayCurrentUrlParams.length; i++)
{
isCategoryGames = arrayGames.indexOf(arrayCurrentUrlParams[i]);
categoryGamesArray = (isCategoryGames !== -1) ? true : false;
}
for (i = 0; i < arrayCurrentUrlParams.length; i++)
{
isCategoryMusic = arrayMusic.indexOf(arrayCurrentUrlParams[i]);
categoryMusicArray = (isCategoryMusic !== -1) ? true : false;
}
for (i = 0; i < arrayCurrentUrlParams.length; i++)
{
isCategorySoftware = arraySoftware.indexOf(arrayCurrentUrlParams[i]);
categorySoftwareArray = (isCategorySoftware !== -1) ? true : false;
}
for (i = 0; i < arrayCurrentUrlParams.length; i++)
{
isCategoryNonPorn = arrayNonPorn.indexOf(arrayCurrentUrlParams[i]);
categoryNonPornArray = (isCategoryNonPorn !== -1) ? true : false;
}
}
// Method to grab the Parameter name and value (Note: single use only. See line 60 for multiple URL parameters and if needed move to function.)
function GetParameterByName(name, url) {
// credit: https://stackoverflow.com/a/901144 (Modified by Kxmode)
// Used under StackOverflow's standard CC BY-SA 3.0 license
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp('[?&]' + name + '(=([^]*)|&|#|$|((%\d\D)*\D\d*))'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// Method to activate and deactive filters inside the Advanced Filter's HTML box
function ToggleFilter(target, data, bool, optional)
{
optional = (optional !== undefined) ? true : false;
var targetID = target.replace("#","");
if (bool)
{
if (!optional)
{
$(target).find("i").removeClass("fa-eye-slash").addClass("fa-eye");
$(target).removeClass("disabled");
}
$(target).attr(data, "true");
window.localStorage.setItem(targetID, true);
}
else
{
if (!optional)
{
$(target).find("i").removeClass("fa-eye").addClass("fa-eye-slash");
$(target).addClass("disabled");
}
$(target).attr(data, "false");
window.localStorage.setItem(targetID, false);
}
}
// Method to show and hide the Advanced Filter's HTML box
function ToggleAdvancedFilters(bool, isClicked)
{
isClicked = (isClicked !== undefined) ? true : false;
var parentTarget = $(".new-search form");
var target = $(".advanced-search");
if (GetParameterByName("category") !== null && isClicked === false)
{
$("#shadvbutton").attr("data-shadvbutton", "true");
window.localStorage.setItem("shadvbutton", true);
parentTarget.removeAttr("style");
parentTarget.removeClass("disabled");
target.show();
}
else if (GetParameterByName("category") === null && isClicked === false)
{
$("#shadvbutton").attr("data-shadvbutton", "false");
window.localStorage.setItem("shadvbutton", false);
parentTarget.attr("style", "width: 100%; border-right: 1px solid #9faabc;");
target.hide();
}
else
{
if (bool) {
if (typeof showhideadvsearch !== "undefined") { showhideadvsearch('show'); }
parentTarget.removeAttr("style");
parentTarget.removeClass("disabled");
target.show();
} else {
parentTarget.attr("style", "width: 100%; border-right: 1px solid #9faabc;");
target.hide();
}
}
}
$("#searchTorrent").parent().addClass("new-search");
// Removes extra space between Recommended torrents and search bar
$("#searchTorrent").parent().parent().find("div:nth-of-type(2)").remove();
for(i = 1; i <= 4; i++)
{
$("#searchTorrent").parent().parent().find("br:nth-of-type(1)").remove();
}
// Fixes a bug in this script affecting the formatting of IMDB searches (?imdb=tt0448115) in darkred's "RARBG - various tweaks";
if ($(".new-search").next().attr("class") === undefined)
{
$(".new-search").next().find("table tr td:last-child").addClass("advanced-search-formatting-fix");
$(" ").insertBefore(".advanced-search-formatting-fix b:nth-of-type(-n+5)");
}
// Attaches FontAwesome script to display active and inactive "eye" icons. fontawesome.io for more info.
$("head").append( '');
// Attaches CSS for the custom Advanced Filters HTML box.
$("head").append( '');
// Creates the HTML for category specific filters
if (GetParameterByName("category") === null || categorySoftwareArray)
{
genreFilter = '