diff --git a/fediverse/mastodon_cw_toggle.js b/fediverse/mastodon_cw_toggle.js new file mode 100644 index 0000000..a82307d --- /dev/null +++ b/fediverse/mastodon_cw_toggle.js @@ -0,0 +1,60 @@ +// ==UserScript== +// @name Mastodon CW toggle +// @description Toggles the visibility of all statuses with content warnings. +// @namespace tastytea.de +// @version 2019-05-27 +// @grant none +// @run-at document-end +// ==/UserScript== + +// Copyright © 2019 tastytea . +// License GPLv3: GNU GPL version 3 . +// This program comes with ABSOLUTELY NO WARRANTY. This is free software, +// and you are welcome to redistribute it under certain conditions. + +// Toggle the visibility of each status with CW. +function toggle() +{ + for (let status of document.getElementsByClassName("e-content")) + { + var style = status.getAttribute("style"); + if (style.search("none") > -1) + { + style = style.replace("none", "block"); + } + else + { + style = style.replace("block", "none"); + } + status.setAttribute("style", style); + } +} + +// If there is a “Show more”-button, add our “Toggle all CWs”-button, if we +// didn't do so before. +if (document.getElementsByClassName("status__content__spoiler-link").length > 0 + && document.getElementById("global-cw-toggle") === null) +{ + // If there is no element named “column-1”, do nothing. + var root = document.getElementsByClassName("column-1")[0]; + if (root == null) + { + return; + } + + // Create a div, necessary to get the correct styling for the button. + var div = document.createElement("div"); + div.setAttribute("id", "global-cw-toggle"); + div.setAttribute("class", "status__content"); + div.setAttribute("style", "margin-bottom: 0.5em;"); + + // Create the button. + var button = document.createElement("a"); + button.setAttribute("class", "status__content__spoiler-link"); + button.appendChild(document.createTextNode("Toggle all CWs")); + + div.appendChild(button); + root.insertBefore(div, root.firstChild); + + button.onclick = toggle; +}