Hide NSFW content by default
This commit is contained in:
parent
79027c4c75
commit
1653d4fb4c
@ -33,7 +33,7 @@ struct SearchTemplate {
|
|||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
pub async fn find(req: HttpRequest) -> HttpResponse {
|
pub async fn find(req: HttpRequest) -> HttpResponse {
|
||||||
let nsfw_results = if cookie(&req, "hide_nsfw") != "on" { "&include_over_18=on" } else { "" };
|
let nsfw_results = if cookie(&req, "show_nsfw") == "on" { "&include_over_18=on" } else { "" };
|
||||||
let path = format!("{}.json?{}{}", req.path(), req.query_string(), nsfw_results);
|
let path = format!("{}.json?{}{}", req.path(), req.query_string(), nsfw_results);
|
||||||
let sub = req.match_info().get("sub").unwrap_or("").to_string();
|
let sub = req.match_info().get("sub").unwrap_or("").to_string();
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub struct SettingsForm {
|
|||||||
layout: Option<String>,
|
layout: Option<String>,
|
||||||
wide: Option<String>,
|
wide: Option<String>,
|
||||||
comment_sort: Option<String>,
|
comment_sort: Option<String>,
|
||||||
hide_nsfw: Option<String>,
|
show_nsfw: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
@ -33,8 +33,8 @@ pub async fn get(req: HttpRequest) -> HttpResponse {
|
|||||||
pub async fn set(_req: HttpRequest, form: Form<SettingsForm>) -> HttpResponse {
|
pub async fn set(_req: HttpRequest, form: Form<SettingsForm>) -> HttpResponse {
|
||||||
let mut res = HttpResponse::Found();
|
let mut res = HttpResponse::Found();
|
||||||
|
|
||||||
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "hide_nsfw"];
|
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "show_nsfw"];
|
||||||
let values = vec![&form.theme, &form.front_page, &form.layout, &form.wide, &form.comment_sort, &form.hide_nsfw];
|
let values = vec![&form.theme, &form.front_page, &form.layout, &form.wide, &form.comment_sort, &form.show_nsfw];
|
||||||
|
|
||||||
for (i, name) in names.iter().enumerate() {
|
for (i, name) in names.iter().enumerate() {
|
||||||
match values[i] {
|
match values[i] {
|
||||||
|
@ -127,7 +127,7 @@ pub struct Preferences {
|
|||||||
pub front_page: String,
|
pub front_page: String,
|
||||||
pub layout: String,
|
pub layout: String,
|
||||||
pub wide: String,
|
pub wide: String,
|
||||||
pub hide_nsfw: String,
|
pub show_nsfw: String,
|
||||||
pub comment_sort: String,
|
pub comment_sort: String,
|
||||||
pub subs: Vec<String>,
|
pub subs: Vec<String>,
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ pub fn prefs(req: HttpRequest) -> Preferences {
|
|||||||
front_page: cookie(&req, "front_page"),
|
front_page: cookie(&req, "front_page"),
|
||||||
layout: cookie(&req, "layout"),
|
layout: cookie(&req, "layout"),
|
||||||
wide: cookie(&req, "wide"),
|
wide: cookie(&req, "wide"),
|
||||||
hide_nsfw: cookie(&req, "hide_nsfw"),
|
show_nsfw: cookie(&req, "show_nsfw"),
|
||||||
comment_sort: cookie(&req, "comment_sort"),
|
comment_sort: cookie(&req, "comment_sort"),
|
||||||
subs: cookie(&req, "subscriptions").split('+').map(String::from).filter(|s| s != "").collect(),
|
subs: cookie(&req, "subscriptions").split('+').map(String::from).filter(|s| s != "").collect(),
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
|
|
||||||
{% if post.flags.nsfw && prefs.hide_nsfw == "on" %}
|
{% if post.flags.nsfw && prefs.show_nsfw != "on" %}
|
||||||
{% else if post.title != "Comment" %}
|
{% else if post.title != "Comment" %}
|
||||||
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
|
@ -42,9 +42,9 @@
|
|||||||
{% call utils::options(prefs.comment_sort, ["confidence", "top", "new", "controversial", "old"], "confidence") %}
|
{% call utils::options(prefs.comment_sort, ["confidence", "top", "new", "controversial", "old"], "confidence") %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="hide_nsfw">
|
<div id="show_nsfw">
|
||||||
<label for="hide_nsfw">Hide NSFW posts:</label>
|
<label for="show_nsfw">Show NSFW posts:</label>
|
||||||
<input type="checkbox" name="hide_nsfw" {% if prefs.hide_nsfw == "on" %}checked{% endif %}>
|
<input type="checkbox" name="show_nsfw" {% if prefs.show_nsfw == "on" %}checked{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p id="settings_note"><b>Note:</b> settings are saved in browser cookies. Clearing your cookie data will reset them.</p>
|
<p id="settings_note"><b>Note:</b> settings are saved in browser cookies. Clearing your cookie data will reset them.</p>
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
<div id="posts">
|
<div id="posts">
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
{% if !(post.flags.nsfw && prefs.hide_nsfw == "on") %}
|
{% if !(post.flags.nsfw && prefs.show_nsfw != "on") %}
|
||||||
<hr class="sep" />
|
<hr class="sep" />
|
||||||
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<div id="posts">
|
<div id="posts">
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
|
|
||||||
{% if post.flags.nsfw && prefs.hide_nsfw == "on" %}
|
{% if post.flags.nsfw && prefs.show_nsfw != "on" %}
|
||||||
{% else if post.title != "Comment" %}
|
{% else if post.title != "Comment" %}
|
||||||
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
||||||
<p class="post_header">
|
<p class="post_header">
|
||||||
|
Loading…
Reference in New Issue
Block a user