From 7a59d010f6d07bcfb074e60f1f06b002c4bf7b74 Mon Sep 17 00:00:00 2001 From: r Date: Thu, 3 Sep 2020 06:26:32 +0000 Subject: Fix issues related to AntiDopamine mode - Add AntiDopamine mode description - Update fluoride to support AntiDopamine mode --- mastodon/notification.go | 2 +- model/settings.go | 2 +- renderer/model.go | 14 +++++++------- service/service.go | 7 +++---- static/fluoride.js | 25 ++++++++++++++++++++----- templates/header.tmpl | 3 +++ templates/settings.tmpl | 10 +++++----- 7 files changed, 40 insertions(+), 23 deletions(-) diff --git a/mastodon/notification.go b/mastodon/notification.go index 5983396..656e6a1 100644 --- a/mastodon/notification.go +++ b/mastodon/notification.go @@ -23,7 +23,7 @@ type Notification struct { } // GetNotifications return notifications. -func (c *Client) GetNotifications(ctx context.Context, pg *Pagination, excludes ...string) ([]*Notification, error) { +func (c *Client) GetNotifications(ctx context.Context, pg *Pagination, excludes []string) ([]*Notification, error) { var notifications []*Notification params := url.Values{} for _, exclude := range excludes { diff --git a/model/settings.go b/model/settings.go index b7c77cf..03e9581 100644 --- a/model/settings.go +++ b/model/settings.go @@ -9,7 +9,7 @@ type Settings struct { AutoRefreshNotifications bool `json:"auto_refresh_notifications"` FluorideMode bool `json:"fluoride_mode"` DarkMode bool `json:"dark_mode"` - AntiDopamineMode bool `json:"anti_dopamine_mode"` + AntiDopamineMode bool `json:"anti_dopamine_mode"` } func NewSettings() *Settings { diff --git a/renderer/model.go b/renderer/model.go index 7ea8c22..4b177db 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -6,13 +6,13 @@ import ( ) type Context struct { - HideAttachments bool - MaskNSFW bool - FluorideMode bool - ThreadInNewTab bool - DarkMode bool - CSRFToken string - UserID string + HideAttachments bool + MaskNSFW bool + FluorideMode bool + ThreadInNewTab bool + DarkMode bool + CSRFToken string + UserID string AntiDopamineMode bool } diff --git a/service/service.go b/service/service.go index cc59cb6..c56d96a 100644 --- a/service/service.go +++ b/service/service.go @@ -410,12 +410,11 @@ func (svc *service) ServeNotificationPage(c *model.Client, maxID string, Limit: 20, } - dope := c.Session.Settings.AntiDopamineMode - if dope { - excludes = append(excludes, "follow", "favourite", "reblog") + if c.Session.Settings.AntiDopamineMode { + excludes = []string{"follow", "favourite", "reblog"} } - notifications, err := c.GetNotifications(ctx, &pg, excludes...) + notifications, err := c.GetNotifications(ctx, &pg, excludes) if err != nil { return } diff --git a/static/fluoride.js b/static/fluoride.js index 6c51694..e055b6d 100644 --- a/static/fluoride.js +++ b/static/fluoride.js @@ -7,11 +7,19 @@ var reverseActions = { "unretweet": "retweet" }; -function getCSRFToken() { +var csrfToken = ""; +var antiDopamineMode = false; + +function checkCSRFToken() { var tag = document.querySelector("meta[name='csrf_token']"); if (tag) - return tag.getAttribute("content"); - return ""; + csrfToken = tag.getAttribute("content"); +} + +function checkAntiDopamineMode() { + var tag = document.querySelector("meta[name='antidopamine_mode']"); + if (tag) + antiDopamineMode = tag.getAttribute("content") === "true"; } function http(method, url, body, type, success, error) { @@ -50,11 +58,13 @@ function handleLikeForm(id, f) { updateActionForm(id, forms[i], reverseActions[action]); } - var body = "csrf_token=" + encodeURIComponent(getCSRFToken()); + var body = "csrf_token=" + encodeURIComponent(csrfToken); var contentType = "application/x-www-form-urlencoded"; http("POST", "/fluoride/" + action + "/" + id, body, contentType, function(res, type) { + if (antiDopamineMode) + return; var data = JSON.parse(res); var count = data.data; if (count === 0) @@ -87,11 +97,13 @@ function handleRetweetForm(id, f) { updateActionForm(id, forms[i], reverseActions[action]); } - var body = "csrf_token=" + encodeURIComponent(getCSRFToken()); + var body = "csrf_token=" + encodeURIComponent(csrfToken); var contentType = "application/x-www-form-urlencoded"; http("POST", "/fluoride/" + action + "/" + id, body, contentType, function(res, type) { + if (antiDopamineMode) + return; var data = JSON.parse(res); var count = data.data; if (count === 0) @@ -193,6 +205,9 @@ function handleStatusLink(a) { } document.addEventListener("DOMContentLoaded", function() { + checkCSRFToken(); + checkAntiDopamineMode(); + var statuses = document.querySelectorAll(".status-container"); for (var i = 0; i < statuses.length; i++) { var s = statuses[i]; diff --git a/templates/header.tmpl b/templates/header.tmpl index 8e67353..2d76f33 100644 --- a/templates/header.tmpl +++ b/templates/header.tmpl @@ -10,6 +10,9 @@ {{if .CSRFToken}} {{end}} + {{if $.Ctx.AntiDopamineMode}} + + {{end}} {{if .AutoRefresh}} {{end}} diff --git a/templates/settings.tmpl b/templates/settings.tmpl index ab5f03c..67386a4 100644 --- a/templates/settings.tmpl +++ b/templates/settings.tmpl @@ -37,14 +37,14 @@ -
- - -
- + +
+
+ +
-- cgit v1.2.3