Misskey CW toggle: reduce scope, fix CSS somewhat
Button positioning isn't great, but not awful anymore.
This commit is contained in:
parent
6a2eadc05a
commit
e9b803c50c
|
@ -1,7 +1,7 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Misskey CW toggle
|
// @name Misskey CW toggle
|
||||||
// @description Adds a button to toggle the visibility of all notes with content warnings on note-pages.
|
// @description Adds a button to toggle the visibility of all notes with content warnings on note-pages.
|
||||||
// @version 2022.05.17.1
|
// @version 2022.05.17.2
|
||||||
// @author tastytea
|
// @author tastytea
|
||||||
// @copyright 2022, tastytea (https://tastytea.de/)
|
// @copyright 2022, tastytea (https://tastytea.de/)
|
||||||
// @license GPL-3.0-only
|
// @license GPL-3.0-only
|
||||||
|
@ -20,7 +20,11 @@ let counter = 0;
|
||||||
|
|
||||||
// Toggle the visibility of each status with CW.
|
// Toggle the visibility of each status with CW.
|
||||||
function toggle() {
|
function toggle() {
|
||||||
for (let status of document.getElementsByClassName("cw")) {
|
const root = document.getElementsByClassName("_block _isolated note")[0];
|
||||||
|
if (root === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let status of root.getElementsByClassName("cw")) {
|
||||||
let button = status.getElementsByTagName("button")[0];
|
let button = status.getElementsByTagName("button")[0];
|
||||||
if (button === undefined) {
|
if (button === undefined) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -32,7 +36,7 @@ function toggle() {
|
||||||
// Add a “Toggle all CWs”-button.
|
// Add a “Toggle all CWs”-button.
|
||||||
function add_button() {
|
function add_button() {
|
||||||
// If there is no element named “column-1”, use the footer.
|
// If there is no element named “column-1”, use the footer.
|
||||||
let root = document.getElementsByClassName("_block _isolated note")[0];
|
const root = document.getElementsByClassName("_block _isolated note")[0];
|
||||||
if (root === undefined) {
|
if (root === undefined) {
|
||||||
console.error("No suitable parent-element found.");
|
console.error("No suitable parent-element found.");
|
||||||
return;
|
return;
|
||||||
|
@ -42,7 +46,7 @@ function add_button() {
|
||||||
const button = document.createElement("button");
|
const button = document.createElement("button");
|
||||||
button.setAttribute("id", "global-cw-toggle");
|
button.setAttribute("id", "global-cw-toggle");
|
||||||
button.setAttribute("class", "_button");
|
button.setAttribute("class", "_button");
|
||||||
button.setAttribute("style", "float: right; margin: 0.2em 0.5em;");
|
button.setAttribute("style", "margin-top: 0.2em; margin-right: 0.5em;");
|
||||||
button.appendChild(document.createTextNode("Toggle all CWs"));
|
button.appendChild(document.createTextNode("Toggle all CWs"));
|
||||||
|
|
||||||
root.insertBefore(button, root.firstChild);
|
root.insertBefore(button, root.firstChild);
|
||||||
|
@ -51,9 +55,14 @@ function add_button() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
|
const root = document.getElementsByClassName("_block _isolated note")[0];
|
||||||
|
if (root === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If there is a “Show content” button, add our button, if we didn't do so before.
|
// If there is a “Show content” button, add our button, if we didn't do so before.
|
||||||
if (document.getElementsByClassName("cw").length > 0
|
if (root.getElementsByClassName("cw").length > 0
|
||||||
&& document.getElementById("global-cw-toggle") === null) {
|
&& root.getElementById("global-cw-toggle") === null) {
|
||||||
add_button();
|
add_button();
|
||||||
console.debug("Global CW toggle button added");
|
console.debug("Global CW toggle button added");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue