2019-05-27 16:42:59 +02:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Mastodon CW toggle
|
2019-06-04 11:36:07 +02:00
|
|
|
// @description Adds a button to toggle the visibility of all statuses with content warnings on status-pages and profile-pages.
|
2019-06-06 02:00:40 +02:00
|
|
|
// @version 2019.06.06.1
|
2019-05-29 00:49:55 +02:00
|
|
|
// @author tastytea
|
|
|
|
// @copyright 2019, tastytea (https://tastytea.de/)
|
2019-05-29 01:22:16 +02:00
|
|
|
// @license GPL-3.0-only
|
2019-05-27 16:42:59 +02:00
|
|
|
// @namespace tastytea.de
|
2019-05-28 23:12:00 +02:00
|
|
|
// @homepageURL https://schlomp.space/tastytea/userscripts
|
|
|
|
// @supportURL https://schlomp.space/tastytea/userscripts/issues
|
|
|
|
// @downloadURL https://schlomp.space/tastytea/userscripts/raw/branch/main/fediverse/mastodon_cw_toggle.user.js
|
2019-05-27 16:42:59 +02:00
|
|
|
// @grant none
|
2019-05-28 23:54:41 +02:00
|
|
|
// @match https://*/users/*/statuses/*
|
2019-05-30 18:02:38 +02:00
|
|
|
// @match https://*/@*
|
2019-05-29 00:49:55 +02:00
|
|
|
// @run-at document-end
|
|
|
|
// @inject-into content
|
2019-05-27 16:42:59 +02:00
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
// Toggle the visibility of each status with CW.
|
|
|
|
function toggle()
|
|
|
|
{
|
|
|
|
for (let status of document.getElementsByClassName("e-content"))
|
|
|
|
{
|
2019-05-28 22:20:22 +02:00
|
|
|
if (status.parentElement.firstChild.firstChild.className !==
|
|
|
|
"p-summary") // Skip if status has no CW.
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-27 16:42:59 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-27 17:53:19 +02:00
|
|
|
// Add a “Toggle all CWs”-button.
|
|
|
|
function add_button()
|
2019-05-27 16:42:59 +02:00
|
|
|
{
|
2019-05-27 17:53:19 +02:00
|
|
|
// If there is no element named “column-1”, use the footer.
|
2019-05-27 16:42:59 +02:00
|
|
|
var root = document.getElementsByClassName("column-1")[0];
|
2019-05-29 03:42:00 +02:00
|
|
|
if (root === undefined)
|
2019-05-27 16:42:59 +02:00
|
|
|
{
|
2019-05-27 17:53:19 +02:00
|
|
|
root = document.getElementsByClassName("footer")[0];
|
2019-05-29 03:42:00 +02:00
|
|
|
if (root === undefined)
|
2019-05-27 17:53:19 +02:00
|
|
|
{
|
2019-06-06 02:00:40 +02:00
|
|
|
console.error("Error: no suitable parent-element found.");
|
2019-05-27 17:53:19 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-05-27 16:42:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2019-05-27 17:53:19 +02:00
|
|
|
|
|
|
|
// If there is a “Show more”-button, add our button, if we didn't do so before.
|
|
|
|
if (document.getElementsByClassName("status__content__spoiler-link").length > 0
|
|
|
|
&& document.getElementById("global-cw-toggle") === null)
|
|
|
|
{
|
|
|
|
add_button();
|
|
|
|
}
|