Fix issues related to AntiDopamine mode

- Add AntiDopamine mode description
- Update fluoride to support AntiDopamine mode
This commit is contained in:
r 2020-09-03 06:26:32 +00:00
parent 28695fb8e6
commit 7a59d010f6
7 changed files with 40 additions and 23 deletions

View File

@ -23,7 +23,7 @@ type Notification struct {
} }
// GetNotifications return notifications. // 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 var notifications []*Notification
params := url.Values{} params := url.Values{}
for _, exclude := range excludes { for _, exclude := range excludes {

View File

@ -410,12 +410,11 @@ func (svc *service) ServeNotificationPage(c *model.Client, maxID string,
Limit: 20, Limit: 20,
} }
dope := c.Session.Settings.AntiDopamineMode if c.Session.Settings.AntiDopamineMode {
if dope { excludes = []string{"follow", "favourite", "reblog"}
excludes = append(excludes, "follow", "favourite", "reblog")
} }
notifications, err := c.GetNotifications(ctx, &pg, excludes...) notifications, err := c.GetNotifications(ctx, &pg, excludes)
if err != nil { if err != nil {
return return
} }

View File

@ -7,11 +7,19 @@ var reverseActions = {
"unretweet": "retweet" "unretweet": "retweet"
}; };
function getCSRFToken() { var csrfToken = "";
var antiDopamineMode = false;
function checkCSRFToken() {
var tag = document.querySelector("meta[name='csrf_token']"); var tag = document.querySelector("meta[name='csrf_token']");
if (tag) if (tag)
return tag.getAttribute("content"); csrfToken = tag.getAttribute("content");
return ""; }
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) { function http(method, url, body, type, success, error) {
@ -50,11 +58,13 @@ function handleLikeForm(id, f) {
updateActionForm(id, forms[i], reverseActions[action]); 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"; var contentType = "application/x-www-form-urlencoded";
http("POST", "/fluoride/" + action + "/" + id, http("POST", "/fluoride/" + action + "/" + id,
body, contentType, function(res, type) { body, contentType, function(res, type) {
if (antiDopamineMode)
return;
var data = JSON.parse(res); var data = JSON.parse(res);
var count = data.data; var count = data.data;
if (count === 0) if (count === 0)
@ -87,11 +97,13 @@ function handleRetweetForm(id, f) {
updateActionForm(id, forms[i], reverseActions[action]); 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"; var contentType = "application/x-www-form-urlencoded";
http("POST", "/fluoride/" + action + "/" + id, http("POST", "/fluoride/" + action + "/" + id,
body, contentType, function(res, type) { body, contentType, function(res, type) {
if (antiDopamineMode)
return;
var data = JSON.parse(res); var data = JSON.parse(res);
var count = data.data; var count = data.data;
if (count === 0) if (count === 0)
@ -193,6 +205,9 @@ function handleStatusLink(a) {
} }
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
checkCSRFToken();
checkAntiDopamineMode();
var statuses = document.querySelectorAll(".status-container"); var statuses = document.querySelectorAll(".status-container");
for (var i = 0; i < statuses.length; i++) { for (var i = 0; i < statuses.length; i++) {
var s = statuses[i]; var s = statuses[i];

View File

@ -10,6 +10,9 @@
{{if .CSRFToken}} {{if .CSRFToken}}
<meta name="csrf_token" content="{{.CSRFToken}}"> <meta name="csrf_token" content="{{.CSRFToken}}">
{{end}} {{end}}
{{if $.Ctx.AntiDopamineMode}}
<meta name="antidopamine_mode" content="{{$.Ctx.AntiDopamineMode}}">
{{end}}
{{if .AutoRefresh}} {{if .AutoRefresh}}
<meta http-equiv="refresh" content="30"> <meta http-equiv="refresh" content="30">
{{end}} {{end}}

View File

@ -37,14 +37,14 @@
<input id="fluoride-mode" name="fluoride_mode" type="checkbox" value="true" {{if .Settings.FluorideMode}}checked{{end}}> <input id="fluoride-mode" name="fluoride_mode" type="checkbox" value="true" {{if .Settings.FluorideMode}}checked{{end}}>
<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> <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>
<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"> <div class="settings-form-field">
<input id="anti-dopamine-mode" name="anti_dopamine_mode" type="checkbox" <input id="anti-dopamine-mode" name="anti_dopamine_mode" type="checkbox"
value="true" {{if .Settings.AntiDopamineMode}}checked{{end}}> 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> </div>
<button type="submit"> Save </button> <button type="submit"> Save </button>
</form> </form>