Something went wrong. Try again.
A userscript that changes the "post"/"posts" button for Witchsky based on the replies (single word, top level) of at://did:web:didd.uk/app.bsky.feed.post/3meypfff2rs2b
Something went wrong. Try again.
2.1 kB · 62 lines · Created 8mo ago
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// ==UserScript==// @name Witchsky Community Post Button// @namespace http://tampermonkey.net/// @version 0// @author Ducky// @match https://witchsky.app/*// @grant none// @run-at document-end// ==/UserScript==
(function () { 'use strict';
function pluralize(word) { return word + 's'; }
async function getLatestReply() { const postUri = 'at://did:web:didd.uk/app.bsky.feed.post/3meypfff2rs2b'; const apiUrl = `https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread?uri=${encodeURIComponent(postUri)}`;
try { const response = await fetch(apiUrl); const data = await response.json(); const replies = data.thread?.replies;
if (!replies || replies.length === 0) return;
// Sort replies by createdAt date (newest first) const sortedReplies = replies.sort((a, b) => { const dateA = new Date(a.post.record.createdAt); const dateB = new Date(b.post.record.createdAt); return dateB - dateA; // Descending order });
const latestReply = sortedReplies[0].post.record.text.trim(); const words = latestReply.split(/\s+/);
if (words.length === 1) { const word = words[0];
// Get existing storage const storage = JSON.parse(localStorage.getItem('BSKY_STORAGE') || '{}');
// Initialize postReplacement if needed if (!storage.postReplacement) storage.postReplacement = {};
// Update values storage.postReplacement.postName = word; storage.postReplacement.postsName = pluralize(word);
// Save back to localStorage localStorage.setItem('BSKY_STORAGE', JSON.stringify(storage)); } } catch (error) { // Fail silently as requested } }
// Run immediately getLatestReply();})();