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
witchsky-community-post-button.js
edited
1// ==UserScript==
2// @name Witchsky Community Post Button
3// @namespace http://tampermonkey.net/
4// @version 0
5// @author Ducky
6// @match https://witchsky.app/*
7// @grant none
8// @run-at document-end
9// ==/UserScript==
10
11(function () {
12 'use strict';
13
14 function pluralize(word) {
15 return word + 's';
16 }
17
18 async function getLatestReply() {
19 const postUri = 'at://did:web:didd.uk/app.bsky.feed.post/3meypfff2rs2b';
20 const apiUrl = `https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread?uri=${encodeURIComponent(postUri)}`;
21
22 try {
23 const response = await fetch(apiUrl);
24 const data = await response.json();
25 const replies = data.thread?.replies;
26
27 if (!replies || replies.length === 0) return;
28
29 // Sort replies by createdAt date (newest first)
30 const sortedReplies = replies.sort((a, b) => {
31 const dateA = new Date(a.post.record.createdAt);
32 const dateB = new Date(b.post.record.createdAt);
33 return dateB - dateA; // Descending order
34 });
35
36 const latestReply = sortedReplies[0].post.record.text.trim();
37 const words = latestReply.split(/\s+/);
38
39 if (words.length === 1) {
40 const word = words[0];
41
42 // Get existing storage
43 const storage = JSON.parse(localStorage.getItem('BSKY_STORAGE') || '{}');
44
45 // Initialize postReplacement if needed
46 if (!storage.postReplacement) storage.postReplacement = {};
47
48 // Update values
49 storage.postReplacement.postName = word;
50 storage.postReplacement.postsName = pluralize(word);
51
52 // Save back to localStorage
53 localStorage.setItem('BSKY_STORAGE', JSON.stringify(storage));
54 }
55 } catch (error) {
56 // Fail silently as requested
57 }
58 }
59
60 // Run immediately
61 getLatestReply();
62})();