aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-09-03 06:26:32 +0000
committerr <r@freesoftwareextremist.com>2020-09-03 06:29:03 +0000
commit7a59d010f6d07bcfb074e60f1f06b002c4bf7b74 (patch)
treee39adf5e43b74a2c2c66e7e5b38592108b6545f3
parent28695fb8e6b299389347fc8c42f7dc3923b42f24 (diff)
downloadbloat-7a59d010f6d07bcfb074e60f1f06b002c4bf7b74.tar.gz
bloat-7a59d010f6d07bcfb074e60f1f06b002c4bf7b74.zip
Fix issues related to AntiDopamine mode
- Add AntiDopamine mode description - Update fluoride to support AntiDopamine mode
-rw-r--r--mastodon/notification.go2
-rw-r--r--model/settings.go2
-rw-r--r--renderer/model.go14
-rw-r--r--service/service.go7
-rw-r--r--static/fluoride.js25
-rw-r--r--templates/header.tmpl3
-rw-r--r--templates/settings.tmpl10
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}}
<meta name="csrf_token" content="{{.CSRFToken}}">
{{end}}
+ {{if $.Ctx.AntiDopamineMode}}
+ <meta name="antidopamine_mode" content="{{$.Ctx.AntiDopamineMode}}">
+ {{end}}
{{if .AutoRefresh}}
<meta http-equiv="refresh" content="30">
{{end}}
diff --git a/templates/settings.tmpl b/templates/settings.tmpl
index ab5f03c..67386a4 100644
--- a/templates/settings.tmpl
+++ b/templates/settings.tmpl
@@ -38,13 +38,13 @@
<label for="fluoride-mode"> Enable <abbr title="Enable JavaScript based functionality, e.g., like/retweet without page reload and reply preview on thread page">fluoride mode</abbr> </label>
</div>
<div class="settings-form-field">
- <input id="dark-mode" name="dark_mode" type="checkbox" value="true" {{if .Settings.DarkMode}}checked{{end}}>
- <label for="dark-mode"> Use dark theme </label>
- </div>
- <div class="settings-form-field">
<input id="anti-dopamine-mode" name="anti_dopamine_mode" type="checkbox"
value="true" {{if .Settings.AntiDopamineMode}}checked{{end}}>
- <label for="anti-dopamine-mode"> Remove addictive social media features </label>
+ <label for="anti-dopamine-mode"> Enable <abbr title="Remove like/retweet/unread notification count and disable like/retweet/follow notifications">anti-dopamine mode</abbr> </label>
+ </div>
+ <div class="settings-form-field">
+ <input id="dark-mode" name="dark_mode" type="checkbox" value="true" {{if .Settings.DarkMode}}checked{{end}}>
+ <label for="dark-mode"> Use dark theme </label>
</div>
<button type="submit"> Save </button>
</form>