From 4dfe33bd4cc692e055a3f32ba4d699c385047163 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 26 Jan 2023 10:51:29 +0100 Subject: [PATCH] make Misskey CW toggle work with Misskey 13 --- fediverse/misskey_cw_toggle.user.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fediverse/misskey_cw_toggle.user.js b/fediverse/misskey_cw_toggle.user.js index da90f33..c8a92fb 100644 --- a/fediverse/misskey_cw_toggle.user.js +++ b/fediverse/misskey_cw_toggle.user.js @@ -1,9 +1,9 @@ // ==UserScript== // @name Misskey CW toggle // @description Adds a button to toggle the visibility of all notes with content warnings on note-pages. -// @version 2022.07.13.1 +// @version 2023.1.26.1 // @author tastytea -// @copyright 2022, tastytea (https://tastytea.de/) +// @copyright 2022-2023, tastytea (https://tastytea.de/) // @license GPL-3.0-only // @namespace tastytea.de // @homepageURL https://schlomp.space/tastytea/userscripts @@ -18,9 +18,17 @@ let interval; let counter = 0; +function get_root() { + const root = document.getElementsByClassName("lxwezrsl note")[0]; // MK 13 + if (root === undefined) { + root = document.getElementsByClassName("_block note")[0]; // MK 12 + } + return root; +} + // Toggle the visibility of each status with CW. function toggle() { - const root = document.getElementsByClassName("_block note")[0]; + const root = get_root() if (root === undefined) { return; } @@ -35,7 +43,7 @@ function toggle() { // Add a “Toggle all CWs”-button. function add_button() { - let root = document.getElementsByClassName("_block note")[0]; + const root = get_root() if (root === undefined) { console.error("No suitable parent-element found."); return; @@ -54,7 +62,7 @@ function add_button() { } function check() { - const root = document.getElementsByClassName("_block note")[0]; + const root = get_root() if (root === undefined) { return; }