From: Thorsten Date: Fri, 1 Mar 2024 21:38:18 +0000 (+0100) Subject: bugfixes X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=7ea6e6f4618fffef6f8a97e86876d52faff1339a;p=dfde%2Fhide-stuff.git bugfixes is now able to hide users again --- diff --git a/hide-stuff.user.js b/hide-stuff.user.js old mode 100755 new mode 100644 index 5ec8f3b..bec7e95 --- a/hide-stuff.user.js +++ b/hide-stuff.user.js @@ -4,7 +4,7 @@ // @namespace org.free.for.all // @match https://debianforum.de/* // @author Thorsten Sperber -// @version 0.3.2 +// @version 0.3.3 // @downloadURL https://git.aero2k.de/?p=dfde/hide-stuff.git;a=blob_plain;f=hide-stuff.user.js // @updateURL https://git.aero2k.de/?p=dfde/hide-stuff.git;a=blob_plain;f=hide-stuff.user.js // ==/UserScript== @@ -21,20 +21,20 @@ const opacity_highlight = 1.0; function get_hidden_threads() { - var storage = localStorage.getItem('hidden_threads') || "[]"; + const storage = localStorage.getItem('hidden_threads') || "[]"; return JSON.parse(storage); } function get_hidden_users() { - var storage = localStorage.getItem('hidden_users') || "[]"; + const storage = localStorage.getItem('hidden_users') || "[]"; return JSON.parse(storage); } function set_thread_visibility(visible) { - var hidden_threads = get_hidden_threads(); + const hidden_threads = get_hidden_threads(); hidden_threads.forEach(function(val) { - var thread = document.querySelector(`ul.topiclist a[href$='t=${val}']`); + const thread = document.querySelector(`ul.topiclist a[href$='t=${val}']`); if (thread) { thread.closest('li').style.display = visible ? "none" : "block"; } @@ -43,7 +43,7 @@ } function hide_thread(thread_id) { - const hidden_threads = get_hidden_threads(); + let hidden_threads = get_hidden_threads(); if (hidden_threads.indexOf(thread_id) < 0) { // and hidden_threads is a list if (!Array.isArray(hidden_threads)) {hidden_threads = [];} hidden_threads.push(thread_id); @@ -52,12 +52,11 @@ } else { console.log("Thread %s already in %s",thread_id, hidden_threads); } - // hide it within a moment - hide_threads(1000); + hide_threads(); } function unhide_thread(thread_id) { - const hidden_threads = get_hidden_threads(); + let hidden_threads = get_hidden_threads(); const idx = hidden_threads.indexOf(thread_id); if (idx >= 0) { console.debug("unhide thread", thread_id) @@ -67,7 +66,7 @@ } function hide_user(user_id) { - var hidden_users = get_hidden_users(); + let hidden_users = get_hidden_users(); if (hidden_users.indexOf(user_id) < 0) { if (!Array.isArray(hidden_users)) {hidden_users = [];} hidden_users.push(user_id); @@ -75,8 +74,7 @@ } else { console.log("User %s already in %s",user_id, hidden_users); } - // hide it within a moment - hide_users(1000); + hide_users(); } function hide_threads() { @@ -84,15 +82,13 @@ } function hide_users() { - var hidden_users = get_hidden_users(); + const hidden_users = get_hidden_users(); hidden_users.forEach(function(val) { - var threads = document.querySelectorAll(`ul.topiclist a[href$='u=${val}']`); - console.log("banning user %s", val); + const threads = document.querySelectorAll(`ul.topiclist .responsive-hide a[href$='u=${val}']`); threads.forEach(function(thread) { - if (thread) { - thread.closest('li').style.display = "none"; - } + console.debug(`hide user ${val}: thread ${thread}`); + thread.closest('li').style.display = "none"; }); }); update_info_buttons(); @@ -103,12 +99,12 @@ } function unhide_users() { - var hidden_users = get_hidden_users(); + const hidden_users = get_hidden_users(); hidden_users.forEach(function(val) { - var threads = document.querySelectorAll(`ul.topiclist a[href$='u=${val}']`); + const threads = document.querySelectorAll(`ul.topiclist .responsive-hide a[href$='u=${val}']`); threads.forEach(function(thread) { - console.log(thread); + console.debug(`unhide user ${val}: thread ${thread}`); thread.closest('li').style.display = "block"; }); }); @@ -124,7 +120,7 @@ // TODO toggle state function get_button(id, label) { - var btn = document.createElement("a"); + const btn = document.createElement("a"); btn.title = "Doppelklick zum Reset" btn.className = btn_base_classes; btn.innerHTML = `${label}`; @@ -132,7 +128,8 @@ btn.style.color = "#8f8f8f"; return btn; } - var thread_button = get_button('hidden_threads_btn', `T (${hidden_threads.length})`); + + const thread_button = get_button('hidden_threads_btn', `T (${hidden_threads.length})`); thread_button.addEventListener("click", () => { if (!thread_button.classList.contains("show_hidden")) { thread_button.className = `${btn_base_classes} show_hidden`; @@ -151,8 +148,18 @@ }); button_bar.append(thread_button); - var user_button = get_button('hidden_users_btn', `U (${hidden_users.length})`); - user_button.addEventListener("click", unhide_users); + const user_button = get_button('hidden_users_btn', `U (${hidden_users.length})`); + user_button.addEventListener("click", () => { + if (!user_button.classList.contains("show_hidden")) { + user_button.className = `${btn_base_classes} show_hidden`; + user_button.style.backgroundImage = "linear-gradient(to bottom, #fff 0%,#bbb 100%)"; + unhide_users(); + } else { + user_button.className = btn_base_classes; + user_button.style.backgroundImage = null; + hide_users(); + } + }); user_button.addEventListener("dblclick", function() { unhide_users(); localStorage.setItem("hidden_users", JSON.stringify([])); @@ -162,33 +169,16 @@ } function add_user_icons() { - /* - document.querySelectorAll(".lastpost a.username[href*='u=']").forEach(function(el) { - var trash = document.createElement('a'); - trash.innerHTML = ''; - trash.style.opacity = 0.2; - - trash.addEventListener("mouseenter", function() { trash.style.opacity = 1; }); - trash.addEventListener("mouseleave", function() { trash.style.opacity = 0.2; }); - trash.addEventListener("click", function(e) { - var user_id = el.getAttribute("href").match(/u=([0-9]+)/)[1]; - hide_user(parseInt(user_id)); - update_info_buttons(); - }); - - el.parentNode.insertBefore(trash, el.nextSibling); - }); - */ - var profile = document.querySelector('#viewprofile'); + const profile = document.querySelector('#viewprofile'); if (!profile) { return; } - var trash = document.createElement('a'); + const trash = document.createElement('a'); trash.innerHTML = ''; trash.addEventListener("mouseenter", function() { trash.style.opacity = 1; }); trash.addEventListener("mouseleave", function() { trash.style.opacity = 0.2; }); - trash.addEventListener("click", function(e) { - var user_id = profile.querySelector("a[href*='author_id']").getAttribute("href").match(/author_id=([0-9]+)/)[1]; + trash.addEventListener("click", function() { + const user_id = profile.querySelector("a[href*='author_id']").getAttribute("href").match(/author_id=([0-9]+)/)[1]; hide_user(parseInt(user_id)); update_info_buttons(); }); @@ -203,7 +193,7 @@ const thread_link = el.querySelector("a.topictitle[href^='./view']"); const thread_id = parseInt(thread_link.getAttribute("href").match(/t=([0-9]+)/)[1]); - var btn = document.createElement('a'); + const btn = document.createElement('a'); btn.className = "dfde-hide-stuff-btn" btn.style.float = "right"; btn.style.opacity = opacity_default; @@ -212,7 +202,7 @@ btn.addEventListener("mouseenter", function() { btn.style.opacity = opacity_highlight; }); btn.addEventListener("mouseleave", function() { btn.style.opacity = opacity_default; }); - btn.addEventListener("click", function(e) { + btn.addEventListener("click", function() { hidden_threads.indexOf(thread_id) >= 0 ? unhide_thread(thread_id) : hide_thread(thread_id); update_info_buttons(); // just re-add icons @@ -225,8 +215,8 @@ function update_info_buttons() { try { - var hidden_threads = get_hidden_threads(); - var hidden_users = get_hidden_users(); + const hidden_threads = get_hidden_threads(); + const hidden_users = get_hidden_users(); document.querySelector('#hidden_threads_btn').innerHTML = `T (${hidden_threads.length})`; document.querySelector('#hidden_users_btn').innerHTML = `U (${hidden_users.length})`; } catch(e) {