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