Skip to content

Commit

Permalink
Support for hiding works by rating.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Off committed Apr 18, 2021
1 parent fa21bc1 commit 7d79565
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 15 deletions.
20 changes: 20 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,25 @@
"hidden_aw_quick_hide_key_tooltip":
{
"message": "Set what method you'd like to use to quickly hide authors, fandoms and tags."
},

"hidden_aw_max_rating":
{
"message": "Maximum Rating"
},

"hidden_aw_max_rating_tooltip":
{
"message": "Hides works that exceed the maximum rating"
},

"hidden_aw_consider_not_rated_explicit":
{
"message": "Consider \"Not Rated\" Works Explicit"
},

"hidden_aw_consider_not_rated_explicit_tooltip":
{
"message": "When enabled, works that are marked \"Not Rated\" will be considered explicit.\n\nWhen disabled, these works will be shown regardless of the maximum rating."
}
}
57 changes: 44 additions & 13 deletions js/features/hide-works.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@

for(let work of works)
{
let ratingElement = work.querySelector(".rating");

let rating = 0;
switch(ratingElement.classList[0])
{
case "rating-notrated":
rating = settings.hidden_aw_consider_not_rated_explicit ? 3 : 0;
break;

case "rating-general-audience":
rating = 0;
break;

case "rating-teen":
rating = 1;
break;

case "rating-mature":
rating = 2;
break;
case "rating-explicit":
rating = 3;
break;

default:
break;
}

let exceedsMaxRating = rating > settings.hidden_aw_max_rating;

let authorLinks = work.querySelectorAll(`a[rel="author"]`);

let blockedAuthorMatches = [];
Expand Down Expand Up @@ -87,23 +117,24 @@

const showReasons = await Setting.get("hidden_aw_show_reasons");

if(blockedAuthorMatches.length > 0 || blockedFandomMatches.length > 0 || tooManyFandoms || blockedTagMatches.length > 0)
if(exceedsMaxRating || blockedAuthorMatches.length > 0 || blockedFandomMatches.length > 0 || tooManyFandoms || blockedTagMatches.length > 0)
{
let blockReasons = [];
if(showReasons)
{
if(settings.hide_specific_authors && blockedAuthorMatches.length > 0)
blockReasons.push("Author" + (blockedAuthorMatches.length != 1 ? "s" : "") + ": " + blockedAuthorMatches.join(", "));

if(settings.hide_specific_fandoms && blockedFandomMatches.length > 0)
blockReasons.push("Fandom" + (blockedFandomMatches.length != 1 ? "s" : "") + ": " + blockedFandomMatches.join(", "));

if(settings.hide_multiple_fandoms && tooManyFandoms)
blockReasons.push("Too Many Fandoms");
if(exceedsMaxRating)
blockReasons.push("Rating: " + ratingElement.innerText);

if(settings.hide_specific_tags && blockedTagMatches.length > 0)
blockReasons.push("Tag" + (blockedTagMatches.length != 1 ? "s" : "") + ": " + blockedTagMatches.join(", "));
}
if(settings.hide_specific_authors && blockedAuthorMatches.length > 0)
blockReasons.push("Author" + (blockedAuthorMatches.length != 1 ? "s" : "") + ": " + blockedAuthorMatches.join(", "));

if(settings.hide_specific_fandoms && blockedFandomMatches.length > 0)
blockReasons.push("Fandom" + (blockedFandomMatches.length != 1 ? "s" : "") + ": " + blockedFandomMatches.join(", "));

if(settings.hide_multiple_fandoms && tooManyFandoms)
blockReasons.push("Too Many Fandoms");

if(settings.hide_specific_tags && blockedTagMatches.length > 0)
blockReasons.push("Tag" + (blockedTagMatches.length != 1 ? "s" : "") + ": " + blockedTagMatches.join(", "));

if(blockReasons.length == 0)
continue;
Expand Down
36 changes: 34 additions & 2 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,38 @@ new Setting(
});

// Hidden Authors & Works
new Setting(
{
id: "hidden_aw_max_rating",
category: browser.i18n.getMessage("hidden_authors_and_works"),
title: browser.i18n.getMessage("hidden_aw_max_rating"),
type: "select",
tooltip: browser.i18n.getMessage("hidden_aw_max_rating_tooltip"),
defaultValue: 3,
requiresReload: true,
extraData:
{
options:
[
{ value: 0, text: "General Audiences" },
{ value: 1, text: "Teen And Up Audiences" },
{ value: 2, text: "Mature" },
{ value: 3, text: "Explicit (All Works)" },
],
},
});

new Setting(
{
id: "hidden_aw_consider_not_rated_explicit",
category: browser.i18n.getMessage("hidden_authors_and_works"),
title: browser.i18n.getMessage("hidden_aw_consider_not_rated_explicit"),
type: "checkbox",
tooltip: browser.i18n.getMessage("hidden_aw_consider_not_rated_explicit_tooltip"),
requiresReload: true,
defaultValue: true,
});

new Setting(
{
id: "hidden_aw_quick_hide_key",
Expand All @@ -110,7 +142,7 @@ new Setting(
type: "select",
tooltip: browser.i18n.getMessage("hidden_aw_quick_hide_key_tooltip"),
defaultValue: "disabled",
requiresReload: false,
requiresReload: true,
extraData:
{
options:
Expand Down Expand Up @@ -173,8 +205,8 @@ new Setting(
title: browser.i18n.getMessage("multiple_fandoms_threshold"),
type: "number",
tooltip: browser.i18n.getMessage("multiple_fandoms_threshold_tooltip"),
requiresReload: true,
defaultValue: 2,
requiresReload: true,
extraData:
{
min: 2,
Expand Down

0 comments on commit 7d79565

Please sign in to comment.