1-Click Hide Post in Feed
A simple Tampermonkey script that adds a one-click hide button to posts on piefed.social (main feed). It uses PieFed’s native web route to hide posts and restores the scroll position after the page reloads.
Needs: https://www.tampermonkey.net/
This is an independent, unofficial userscript. Made with ChatGPT.
My personal motivation for making this: I prefer to use social media with an inbox zero approach. I want to hide everything that I have seen so that in the end my inbox is empty. (Voyager app has a nice swipe mechanism for this, but it doesn't use the hide feature of PieFed but rather remains local.)
::: spoiler tampermonkey Code
// ==UserScript==
// @name PieFed: 1-Click Hide Post
// @namespace piefed-oneclick-hide
// @version 4.1
// @description Verbirgt Beiträge über PieFeds originale Webroute und stellt die Scrollposition wieder her.
// @match https://piefed.social/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
"use strict";
const HIDE_ICON_CLASS = "fe-hide";
const scrollKey = "piefed-hide-scroll";
// Gespeicherte Scrollposition nach dem Neuladen wiederherstellen
const savedScroll = sessionStorage.getItem(scrollKey);
if (savedScroll !== null) {
sessionStorage.removeItem(scrollKey);
window.scrollTo(0, Number(savedScroll));
}
function hidePost(postId) {
const csrfMeta = document.querySelector(
'meta[name="csrf-token"]'
);
if (!csrfMeta) {
alert("PieFed Hide: CSRF-Token nicht gefunden.");
return;
}
const form = document.createElement("form");
form.method = "POST";
form.action = `/post/${postId}/hide/yes`;
form.style.display = "none";
const tokenInput = document.createElement("input");
tokenInput.type = "hidden";
tokenInput.name = "csrf_token";
tokenInput.value = csrfMeta.content;
form.appendChild(tokenInput);
document.body.appendChild(form);
// Aktuelle Scrollposition vor dem Absenden speichern
sessionStorage.setItem(
scrollKey,
String(window.scrollY)
);
form.submit();
}
function addHideIcon(teaser) {
if (teaser.dataset.oneclickHideAdded) return;
const match = teaser.id.match(/^post_(\d+)$/);
if (!match) return;
const optionsLink = teaser.querySelector(
".post_options_link"
);
if (!optionsLink) return;
const wrap = document.createElement("span");
wrap.style.display = "inline-block";
wrap.style.marginRight = "4px";
wrap.title = "Diesen Beitrag vor mir verbergen";
const link = document.createElement("a");
link.href = "#";
link.setAttribute(
"aria-label",
"Diesen Beitrag vor mir verbergen"
);
link.innerHTML =
`<span class="fe ${HIDE_ICON_CLASS}"></span>`;
link.addEventListener("click", function (event) {
event.preventDefault();
event.stopPropagation();
hidePost(match[1]);
});
wrap.appendChild(link);
optionsLink.insertBefore(wrap, optionsLink.firstChild);
teaser.dataset.oneclickHideAdded = "1";
}
function scan() {
document
.querySelectorAll("div[id^='post_'].post_teaser")
.forEach(addHideIcon);
}
scan();
const observer = new MutationObserver(scan);
observer.observe(document.body, {
childList: true,
subtree: true
});
})();
:::
5 replies
PieFed has this feature, IF you turn on "Do not display posts with which I have already interacted (opened/upvoted/downvoted)" in https://piefed.social/user/settings
More details at https://piefed.social/c/[email protected]/p/2262951/hide-mark-a-post-as-read-without-voting-on-it
Thank you for the hint. I had that activated before. But quite sometimes I do want to interact (read, vote) but to still keep it in my inbox until I am done with it. With my script I can decide distinctively whether to hide it or not , independent of interactions. But probably for most people the built-in function is enough, so very good you mentioned it here. 👍
I see rimu already mentioned. I have that setting and just now hit the read button. I love to not mark animal pictures as read so that when I refresh I see them again as I scroll through.
That's actually a good hint on the problem that I see; if it was not just pictures, but articles, you'd want to READ (open) them. But reading them would make them disappear with the setting that Rimu kindly pointed at (“Do not display posts with which I have already interacted (opened/upvoted/downvoted)”).
Yes this is correct and actually I can see why you would want it. I purposely don't interact with many pictures precisely because I would rather keep them in my feed than add a comment.