diff --git a/assets/js/settings.js b/assets/js/settings.js index f3965b29..360228ee 100644 --- a/assets/js/settings.js +++ b/assets/js/settings.js @@ -15,7 +15,6 @@ export function setupSettings() { // Local settings localCheckboxes.forEach(checkbox => { - checkbox.checked = Boolean(store.get(checkbox.id)); checkbox.addEventListener('change', () => { store.set(checkbox.id.replace('user_', ''), checkbox.checked); }); diff --git a/lib/philomena_web/controllers/channel/nsfw_controller.ex b/lib/philomena_web/controllers/channel/nsfw_controller.ex new file mode 100644 index 00000000..1469a7a3 --- /dev/null +++ b/lib/philomena_web/controllers/channel/nsfw_controller.ex @@ -0,0 +1,25 @@ +defmodule PhilomenaWeb.Channel.NsfwController do + use PhilomenaWeb, :controller + + alias Plug.Conn + + def create(conn, _params) do + conn + |> set_cookie("chan_nsfw", "true") + |> put_flash(:info, "Successfully updated channel visibility.") + |> redirect(to: Routes.channel_path(conn, :index)) + end + + def delete(conn, _params) do + conn + |> set_cookie("chan_nsfw", "false") + |> put_flash(:info, "Successfully updated channel visibility.") + |> redirect(to: Routes.channel_path(conn, :index)) + end + + # Duplicated from setting controller + defp set_cookie(conn, cookie_name, value) do + # JS wants access; max-age is set to 25 years from now + Conn.put_resp_cookie(conn, cookie_name, value, max_age: 788_923_800, http_only: false) + end +end diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index df6320a3..1437b1c5 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -485,6 +485,10 @@ defmodule PhilomenaWeb.Router do resources "/history", Page.HistoryController, only: [:index] end + scope "/channels", Channel, as: :channel do + resources "/nsfw", NsfwController, only: [:create, :delete], singleton: true + end + resources "/dnp", DnpEntryController, only: [:index, :show] resources "/staff", StaffController, only: [:index] resources "/stats", StatController, only: [:index] diff --git a/lib/philomena_web/templates/channel/index.html.slime b/lib/philomena_web/templates/channel/index.html.slime index 328e77e4..86d592f9 100644 --- a/lib/philomena_web/templates/channel/index.html.slime +++ b/lib/philomena_web/templates/channel/index.html.slime @@ -12,6 +12,15 @@ h1 Livestreams .block__header = pagination + = if @conn.cookies["chan_nsfw"] == "true" do + a href=Routes.channel_nsfw_path(@conn, :delete) data-method="delete" + i.fa.fa-eye-slash> + ' Hide NSFW streams + - else + a href=Routes.channel_nsfw_path(@conn, :create) data-method="create" + i.fa.fa-eye> + ' Show NSFW streams + .block__content = for channel <- @channels do = render PhilomenaWeb.ChannelView, "_channel_box.html", channel: channel, conn: @conn, subscriptions: @subscriptions diff --git a/lib/philomena_web/templates/setting/edit.html.slime b/lib/philomena_web/templates/setting/edit.html.slime index 6fbc9696..a7fe7e6f 100644 --- a/lib/philomena_web/templates/setting/edit.html.slime +++ b/lib/philomena_web/templates/setting/edit.html.slime @@ -104,28 +104,28 @@ h1 Content Settings .block.block--fixed.block--warning Settings on this tab are saved in the current browser. They are independent of your login. .field => label f, :hidpi, "Serve HiDPI thumbnails" - => checkbox f, :hidpi, value: @conn.cookies["hidpi"] + => checkbox f, :hidpi, checked: @conn.cookies["hidpi"] == "true" .fieldlabel: i Use high quality thumbnails on displays with a high pixel density. Requires more data than regular thumbnails. .field => label f, :serve_webm, "Serve WebM" - => checkbox f, :serve_webm, value: @conn.cookies["serve_webm"] + => checkbox f, :serve_webm, checked: @conn.cookies["serve_webm"] == "true" .fieldlabel: i Serve WebM/MP4 versions of GIF images when available. Good for lower-bandwidth connections, but the video versions may have missing start/end frames, and do not support transparency. .field => label f, :webm, "Use video thumbnails" - => checkbox f, :webm, value: @conn.cookies["webm"] + => checkbox f, :webm, checked: @conn.cookies["webm"] == "true" .fieldlabel: i Use video thumbnails for WebM videos. Does not apply to GIF images. .field => label f, :hide_uploader - => checkbox f, :hide_uploader, value: @conn.cookies["hide_uploader"] + => checkbox f, :hide_uploader, checked: @conn.cookies["hide_uploader"] == "true" .fieldlabel: i Hide the uploader and date posted information on image pages. .field => label f, :chan_nsfw, "Show NSFW channels" - => checkbox f, :chan_nsfw, value: @conn.cookies["chan_nsfw"] + => checkbox f, :chan_nsfw, checked: @conn.cookies["chan_nsfw"] == "true" .fieldlabel: i Show streams marked as NSFW on the channels page. = if staff?(@conn.assigns.current_user) do .field => label f, :hide_staff_tools - => checkbox f, :hide_staff_tools, value: @conn.cookies["hide_staff_tools"] + => checkbox f, :hide_staff_tools, checked: @conn.cookies["hide_staff_tools"] == "true" .fieldlabel: i Hide most of the staff tools (e.g. IPs, anon names) making your site appear as if you weren't staff, this is useful when browsing in public. = if !@conn.assigns.current_user do