2019-06-07 00:22:03 +02:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Pleroma CW toggle
|
|
|
|
// @description Adds a button to toggle the visibility of all statuses with content warnings on status-pages and profile-pages.
|
2019-06-07 01:04:55 +02:00
|
|
|
// @version 2019.06.07.2
|
2019-06-07 00:22:03 +02:00
|
|
|
// @author tastytea
|
|
|
|
// @copyright 2019, tastytea (https://tastytea.de/)
|
|
|
|
// @license GPL-3.0-only
|
|
|
|
// @namespace tastytea.de
|
|
|
|
// @homepageURL https://schlomp.space/tastytea/userscripts
|
|
|
|
// @supportURL https://schlomp.space/tastytea/userscripts/issues
|
|
|
|
// @downloadURL https://schlomp.space/tastytea/userscripts/raw/branch/main/fediverse/pleroma_cw_toggle.user.js
|
|
|
|
// @grant none
|
|
|
|
// @match https://*/notice/*
|
|
|
|
// @match https://*/users/*
|
|
|
|
// @run-at document-end
|
|
|
|
// @inject-into content
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
let interval;
|
|
|
|
|
|
|
|
// Toggle the visibility of statuses with CW.
|
|
|
|
function toggle()
|
|
|
|
{
|
2019-06-07 01:04:55 +02:00
|
|
|
const main = document.getElementsByClassName("main")[0];
|
|
|
|
let hyperlinks = main.getElementsByClassName("cw-status-hider");
|
2019-06-07 00:22:03 +02:00
|
|
|
if (hyperlinks.length === 0) // If no status is hidden, hide all.
|
|
|
|
{
|
2019-06-07 01:04:55 +02:00
|
|
|
hyperlinks = main.getElementsByClassName("status-unhider");
|
2019-06-07 00:22:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let hyperlink of hyperlinks)
|
|
|
|
{
|
|
|
|
hyperlink.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_button()
|
|
|
|
{
|
2019-06-07 01:04:55 +02:00
|
|
|
const main = document.getElementsByClassName("main")[0];
|
|
|
|
|
2019-06-07 00:22:03 +02:00
|
|
|
// If conversation-heading is not there, try profile-tabs.
|
2019-06-07 01:04:55 +02:00
|
|
|
let root = main.getElementsByClassName("conversation-heading")[0];
|
2019-06-07 00:22:03 +02:00
|
|
|
if (root === undefined)
|
|
|
|
{
|
2019-06-07 01:04:55 +02:00
|
|
|
root = main.getElementsByClassName("tabs")[0];
|
2019-06-07 00:22:03 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 01:04:55 +02:00
|
|
|
// if root element and a status was found, disable interval and add button.
|
|
|
|
if (root !== undefined
|
|
|
|
&& main.getElementsByClassName("status-content").length > 0)
|
2019-06-07 00:22:03 +02:00
|
|
|
{
|
|
|
|
clearInterval(interval);
|
|
|
|
|
2019-06-07 01:04:55 +02:00
|
|
|
// Only add button if one or more statuses have a CW.
|
|
|
|
if (main.getElementsByClassName("cw-status-hider").length > 0
|
|
|
|
|| main.getElementsByClassName("status-unhider").length > 0)
|
|
|
|
{
|
|
|
|
const button = document.createElement("a");
|
|
|
|
button.setAttribute("style", "margin-left: 1em;");
|
|
|
|
button.appendChild(document.createTextNode("Toggle all CWs"));
|
|
|
|
button.setAttribute("href", "#");
|
|
|
|
button.onclick = toggle;
|
|
|
|
root.append(button);
|
|
|
|
}
|
2019-06-07 00:22:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interval = setInterval(add_button, 1000); // Try to add button every second.
|