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 --- static/fluoride.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'static') 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]; -- cgit v1.2.3