feat(pref): add ability to hide NSFW content
This commit is contained in:
@@ -40,3 +40,4 @@ replaceSoundCloud = "sc.kuuro.net"
|
||||
proxyVideos = true
|
||||
hlsPlayback = false
|
||||
infiniteScroll = false
|
||||
hideNsfw = true
|
||||
|
||||
@@ -23,6 +23,7 @@ proc parseUser(js: JsonNode; id=""): User =
|
||||
media: js{"media_count"}.getInt,
|
||||
verifiedType: parseEnum[VerifiedType](js{"verified_type"}.getStr("None")),
|
||||
protected: js{"protected"}.getBool,
|
||||
sensitive: "sensitive" in js{"profile_interstitial_type"}.getStr("") or js{"possibly_sensitive"}.getBool,
|
||||
joinDate: js{"created_at"}.getTime
|
||||
)
|
||||
|
||||
@@ -225,6 +226,7 @@ proc parseTweet(js: JsonNode; jsCard: JsonNode = newJNull()): Tweet =
|
||||
text: js{"full_text"}.getStr,
|
||||
time: js{"created_at"}.getTime,
|
||||
hasThread: js{"self_thread"}.notNull,
|
||||
sensitive: js{"possibly_sensitive"}.getBool,
|
||||
available: true,
|
||||
user: User(id: js{"user_id_str"}.getStr),
|
||||
stats: TweetStats(
|
||||
|
||||
@@ -82,6 +82,9 @@ genPrefs:
|
||||
squareAvatars(checkbox, false):
|
||||
"Square profile pictures"
|
||||
|
||||
hideNsfw(checkbox, true):
|
||||
"Hide NSFW content"
|
||||
|
||||
Media:
|
||||
mp4Playback(checkbox, true):
|
||||
"Enable mp4 video playback (only for gifs)"
|
||||
|
||||
@@ -103,6 +103,7 @@ type
|
||||
media*: int
|
||||
verifiedType*: VerifiedType
|
||||
protected*: bool
|
||||
sensitive*: bool
|
||||
suspended*: bool
|
||||
joinDate*: DateTime
|
||||
|
||||
@@ -214,6 +215,7 @@ type
|
||||
time*: DateTime
|
||||
reply*: seq[string]
|
||||
pinned*: bool
|
||||
sensitive*: bool
|
||||
hasThread*: bool
|
||||
available*: bool
|
||||
tombstone*: string
|
||||
|
||||
@@ -120,6 +120,10 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
|
||||
link(rel="preload", type="font/woff2", `as`="font",
|
||||
href="/fonts/fontello.woff2?61663884", crossorigin="anonymous")
|
||||
|
||||
if prefs.hideNsfw:
|
||||
style:
|
||||
verbatim ".nsfw { display: none !important; }"
|
||||
|
||||
proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs;
|
||||
titleText=""; desc=""; ogTitle=""; rss=""; video="";
|
||||
images: seq[string] = @[]; banner=""): string =
|
||||
|
||||
@@ -13,7 +13,8 @@ proc renderStat(num: int; class: string; text=""): VNode =
|
||||
text insertSep($num, ',')
|
||||
|
||||
proc renderUserCard*(user: User; prefs: Prefs): VNode =
|
||||
buildHtml(tdiv(class="profile-card")):
|
||||
let class = if user.sensitive: "profile-card nsfw" else: "profile-card"
|
||||
buildHtml(tdiv(class=class)):
|
||||
tdiv(class="profile-card-info"):
|
||||
let
|
||||
url = getPicUrl(user.getUserPic())
|
||||
|
||||
@@ -56,7 +56,8 @@ proc renderThread(thread: Tweets; prefs: Prefs; path: string): VNode =
|
||||
index=i, last=(i == thread.high), showThread=show)
|
||||
|
||||
proc renderUser(user: User; prefs: Prefs): VNode =
|
||||
buildHtml(tdiv(class="timeline-item")):
|
||||
let class = if user.sensitive: "timeline-item nsfw" else: "timeline-item"
|
||||
buildHtml(tdiv(class=class)):
|
||||
a(class="tweet-link", href=("/" & user.username))
|
||||
tdiv(class="tweet-body profile-result"):
|
||||
tdiv(class="tweet-header"):
|
||||
|
||||
@@ -277,6 +277,9 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0;
|
||||
if index == -1 or last:
|
||||
divClass = "thread-last " & class
|
||||
|
||||
if tweet.sensitive:
|
||||
divClass.add " nsfw"
|
||||
|
||||
if not tweet.available:
|
||||
return buildHtml(tdiv(class=divClass & "unavailable timeline-item")):
|
||||
tdiv(class="unavailable-box"):
|
||||
|
||||
Reference in New Issue
Block a user