README.md

ATProtocol-Playground #

Scripts and tools for experimenting with ATProto and BSky.app.

Features #

  • Element Evaluator Tool: A browser-side tool for identifying and evaluating DOM elements on AtProtocol-style websites
  • BSky Cleaner Userscript: A Tampermonkey-compatible userscript to hide/remove/replace elements on bsky.app

Quick Start #

Element Evaluator Tool #

The element evaluator is a TypeScript module that scans web pages to identify elements like bookmarks, reposts, and display names, then generates rules to hide or remove them.

Using the Dev UI #

  1. Build the project:

    npm install
    npm run build
    
  2. Load the evaluator in your browser console (on any page):

    // Import and initialize the dev UI
    const script = document.createElement('script');
    script.src = 'path/to/dist/tools/element-evaluator/index.js';
    script.type = 'module';
    document.head.appendChild(script);
    
    // Then in console:
    initElementEvaluatorDevUI();
    
  3. The dev UI overlay will appear in the top-right corner with:

    • Scan Page: Click to scan the current page for candidates
    • Preview: Click "Preview" on any candidate to highlight matching elements
    • Actions: Mark candidates as hide/remove/replace rules
    • Apply Rules: Apply all rules and enable MutationObserver for SPA updates
    • Export Rules: Download rules as JSON for use in the userscript

Programmatic API #

import { scanDocument, generateRule, applyRules } from './tools/element-evaluator';

// Scan for elements
const candidates = await scanDocument({
  roles: ['bookmark', 'repost', 'displayname'],
  minConfidence: 0.5,
  includeHidden: false
});

// Generate a rule
const rule = generateRule(candidates[0], 'remove');

// Apply rules
const controller = applyRules([rule], {
  useMutationObserver: true,
  debounceMs: 300,
  debug: true
});

// Stop observing later
controller.stop();

BSky Cleaner Userscript #

A Tampermonkey userscript to automatically hide/remove elements on bsky.app.

Installation #

  1. Install Tampermonkey:

  2. Install the Script:

    • Open Tampermonkey dashboard (click extension icon → Dashboard)
    • Click "Create a new script"
    • Copy the entire contents of userscripts/bsky-cleaner.user.js into the editor
    • Save (Ctrl+S / Cmd+S)
    • The script is now active on bsky.app
  3. Customize Settings: Edit the SETTINGS block at the top of the script:

    const SETTINGS = {
      enabled: true,
      mode: 'remove', // or 'hide' or 'replace'
      removeBookmark: true,
      removeRepost: true,
      hideDisplayName: false,
      customSelectors: [
        // Add your custom rules here
      ],
      mutationObserver: true,
      debounceMs: 300,
      debug: false,
      dryRun: false
    };
    

Finding Custom Selectors #

  1. Open bsky.app in your browser
  2. Right-click the element you want to target → Inspect
  3. In DevTools, right-click the highlighted element → Copy → Copy selector
  4. Add it to customSelectors in the script:
    customSelectors: [
      { selector: "#your-copied-selector", action: "remove" }
    ]
    
  5. Save and reload bsky.app

Testing with Dry Run #

To test selectors without making changes:

  1. Set dryRun: true and debug: true in SETTINGS
  2. Open browser console (F12)
  3. Reload bsky.app
  4. Check console logs to see what would be modified
  5. Adjust selectors as needed
  6. Set dryRun: false when ready

Example Custom Rules #

customSelectors: [
  // Remove specific buttons
  { selector: "button[aria-label='Share']", action: "remove" },
  
  // Hide display names but keep structure
  { selector: ".display-name, [data-testid='displayName']", action: "hide" },
  
  // Replace text content
  { selector: ".handle", action: "replace", replaceText: "[user]" }
]

Development #

Project Structure #

.
├── tools/
│   └── element-evaluator/     # Element evaluator module
│       ├── types.ts           # TypeScript type definitions
│       ├── evaluator.ts       # Core scanning and rule logic
│       ├── dev-ui.ts          # Browser dev UI overlay
│       └── index.ts           # Main export
├── userscripts/
│   └── bsky-cleaner.user.js   # Tampermonkey userscript
├── tests/
│   └── integration/           # Puppeteer integration tests
│       ├── evaluator.test.js
│       ├── userscript.test.js
│       └── test-fixtures.html
└── package.json

Building #

npm install
npm run build

The compiled JavaScript will be in dist/.

Running Tests #

# Run all tests
npm test

# Run integration tests only
npm run test:integration

Code Quality #

# Lint code
npm run lint

# Format code
npm run format

How It Works #

Element Evaluator #

The evaluator uses heuristics to identify elements:

  1. Bookmark Detection:

    • Matches aria-label, title, or class containing "bookmark", "save"
    • Checks for button elements with bookmark-related testids
  2. Repost Detection:

    • Matches aria-label, title, or class containing "repost", "reshare", "boost"
    • Identifies share/quote buttons
  3. Display Name Detection:

    • Matches classes like "displayName", "profile-name"
    • Checks data-testid attributes
    • Validates text patterns (not handles, reasonable length)
  4. Selector Generation:

    • Uses unique IDs when available
    • Falls back to class + tag combinations
    • Adds nth-child selectors for specificity

BSky Cleaner Userscript #

The userscript:

  1. Runs on page load (document-idle)
  2. Applies rules to matching elements using querySelectorAll
  3. Watches for changes with MutationObserver (for SPA navigation)
  4. Debounces updates to avoid performance issues
  5. Supports multiple modes: hide (CSS), remove (DOM), replace (text)

Security & Privacy #

  • Browser-only execution: All code runs in your browser
  • No external requests: The userscript doesn't send data anywhere
  • No credentials required: Tools work on public pages
  • Open source: Review the code before installing

Important: Do not embed API keys, tokens, or secrets in any scripts. The tools are designed to work with publicly accessible DOM elements only.

Troubleshooting #

Userscript not working #

  1. Check Tampermonkey is enabled: Click extension icon, verify script shows "Enabled"
  2. Verify match pattern: Script only runs on *://bsky.app/* by default
  3. Check browser console: Set debug: true and look for error messages
  4. Reload the page: Some SPA changes require a full reload

Selectors not matching #

  1. Verify selector in DevTools: Use document.querySelector("your-selector") in console
  2. Check element visibility: Hidden elements won't match unless includeHidden: true
  3. Inspect dynamic content: Some elements load after page init; MutationObserver should catch them
  4. Use more specific selectors: Combine multiple attributes for reliability

Performance issues #

  1. Reduce debounce interval: Set debounceMs to a smaller value (but not too small)
  2. Disable MutationObserver: Set mutationObserver: false if page is static
  3. Limit custom selectors: Too many selectors can slow down page
  4. Use 'hide' instead of 'remove': Removing elements triggers more DOM recalculation

Contributing #

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Run npm run lint and npm run format
  6. Submit a pull request

License #

MIT - See LICENSE file

References #