Add Misskey CW toggle
This commit is contained in:
parent
c98448e7c8
commit
6a2eadc05a
|
@ -0,0 +1,62 @@
|
|||
// ==UserScript==
|
||||
// @name Misskey CW toggle
|
||||
// @description Adds a button to toggle the visibility of all notes with content warnings on note-pages.
|
||||
// @version 2022.05.17.1
|
||||
// @author tastytea
|
||||
// @copyright 2022, 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/misskey_cw_toggle.user.js
|
||||
// @grant none
|
||||
// @match https://*/notice/*
|
||||
// @run-at document-end
|
||||
// @inject-into content
|
||||
// ==/UserScript==
|
||||
|
||||
let interval;
|
||||
let counter = 0;
|
||||
|
||||
// Toggle the visibility of each status with CW.
|
||||
function toggle() {
|
||||
for (let status of document.getElementsByClassName("cw")) {
|
||||
let button = status.getElementsByTagName("button")[0];
|
||||
if (button === undefined) {
|
||||
continue;
|
||||
}
|
||||
button.click();
|
||||
}
|
||||
}
|
||||
|
||||
// Add a “Toggle all CWs”-button.
|
||||
function add_button() {
|
||||
// If there is no element named “column-1”, use the footer.
|
||||
let root = document.getElementsByClassName("_block _isolated note")[0];
|
||||
if (root === undefined) {
|
||||
console.error("No suitable parent-element found.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const button = document.createElement("button");
|
||||
button.setAttribute("id", "global-cw-toggle");
|
||||
button.setAttribute("class", "_button");
|
||||
button.setAttribute("style", "float: right; margin: 0.2em 0.5em;");
|
||||
button.appendChild(document.createTextNode("Toggle all CWs"));
|
||||
|
||||
root.insertBefore(button, root.firstChild);
|
||||
|
||||
button.onclick = toggle;
|
||||
}
|
||||
|
||||
function check() {
|
||||
// If there is a “Show content” button, add our button, if we didn't do so before.
|
||||
if (document.getElementsByClassName("cw").length > 0
|
||||
&& document.getElementById("global-cw-toggle") === null) {
|
||||
add_button();
|
||||
console.debug("Global CW toggle button added");
|
||||
}
|
||||
}
|
||||
|
||||
interval = setInterval(check, 1000); // Try to add button every second.
|
Loading…
Reference in New Issue