// @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==
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";
}
}
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);
} 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)
}
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);
} 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() {
}
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();
}
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";
});
});
// 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 = `<span id='${id}'>${label}</span>`;
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`;
});
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([]));
}
function add_user_icons() {
- /*
- document.querySelectorAll(".lastpost a.username[href*='u=']").forEach(function(el) {
- var trash = document.createElement('a');
- trash.innerHTML = '<i class="icon fa-trash fa-fw icon-gray icon-md"></i>';
- 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 = '<i class="icon fa-trash fa-fw icon-gray icon-xl"></i>';
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();
});
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;
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
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) {