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.)

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
});
})();

you are viewing a single comment's thread
view the rest of the comments
[–] [S] 1 point 3 weeks ago (1 child)

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)”).

  • source
  • parent
  • hideshow 1 child comment