Facebook Comment Sorter

areen-c
2025-04-17T09:47:21Z

Forces Facebook comments to show "All Comments" or "Newest" instead of "Most Relevant" + Auto-expand replies

Facebook Comment Sorter - Auto Sort Comments + View Replies

This userscript forces Facebook comments to always show "All Comments" or "Newest" instead of the annoying default "Most Relevant". It works on the latest Facebook interface and supports many languages.

🆕 NEW in v2.2: After a complete overhaul, the Auto Reply Expansion feature is now stable, smart, and safe to use! It automatically clicks "View X replies" so you don't have to, letting you read entire comment threads seamlessly. It's now intelligent enough to avoid clicking on post previews in your news feed.

📦 Features

Automatic Comment Sorting: Automatically selects your preferred comment sort (All or Newest)

🔥 NEW: Auto Reply Expansion: Automatically finds and clicks "View X replies" buttons so you can read full conversations without manual clicking

Smart Multi-Language Support: Works with 14+ languages including English, Indonesian, Spanish, French, German, Portuguese, Italian, Dutch, Russian, Chinese, Japanese, Arabic, Hindi

Deep API Integration: Modifies network requests to enforce server-side sorting — not just UI changes

Set and Forget: Works automatically in the background — just click "Comments" and the script handles everything, no extra steps needed

Scroll Position Memory: Keeps your reading position when replies expand so you don't lose your place

Performance Optimized: Smart delays and viewport detection to avoid overwhelming Facebook's servers

📥 Installation

1. Install a userscript manager like Tampermonkey or Violentmonkey

2. Click the Install button on this page

3. The script will start working automatically when you browse Facebook — that's it!

🛠️ Customization

Open the script and edit the CONFIG section at the top:

const CONFIG = {
    sortPreference: "all",      // "newest" or "all" - your choice
    debug: true,               // Console logging for nerds
    expandReplies: true,       // Auto-expand reply buttons (the good stuff!)
    replyExpandDelay: 1000,    // Delay between expansions in milliseconds
    viewportOnly: true         // Only expand visible replies (recommended)
};

Quick Setup Examples:

Want newest comments first? Change sortPreference: "newest"

Don't want auto reply expansion? Set expandReplies: false

Slow internet? Increase replyExpandDelay: 2000 (2 seconds)

Want to expand ALL replies even off-screen? Set viewportOnly: false

📖 How It Works

This script is pretty sophisticated and uses multiple attack vectors to make sure Facebook can't override your preferences:

Comment Sorting Magic:

1. UI Method: Identifies and clicks the right sorting option in Facebook's dropdown menu

2. API Interception: Intercepts and modifies network requests to add sorting parameters server-side

3. Persistent Override: Keeps enforcing your choice even when Facebook tries to be "smart"

Reply Expansion Intelligence:

1. Smart Pattern Detection: Recognizes reply buttons in 12+ languages using advanced text matching

Detects: "View 5 replies", "5 balasan", "Ver 5 respuestas", "5 réponses", etc.

Avoids: "Hide replies", "Load more comments", collapse buttons

2. Viewport Awareness: Only processes reply buttons you can actually see (configurable)

3. Memory Management: Remembers which buttons it already clicked to avoid loops

4. Scroll Preservation: Maintains your exact reading position when content expands

🌍 Language Support Deep Dive

Comment Sorting works with these Facebook interface languages:

English, Indonesian, Spanish, French, German, Portuguese, Italian, Dutch, Russian, Chinese (Simplified/Traditional), Japanese, Arabic, Hindi

Reply Expansion detects these reply button patterns:

English: "replies", "view replies", "X more replies", "Show X replies"

Indonesian: "balasan", "lihat balasan", "X balasan lagi", "Tampilkan X balasan"

Spanish: "respuestas", "ver respuestas", "X respuestas más"

French: "réponses", "voir réponses", "X réponses de plus"

German: "antworten", "antworten anzeigen", "X weitere antworten"

Italian: "risposte", "visualizza risposte", "X risposte in più"

Dutch: "antwoorden", "antwoorden bekijken", "X meer antwoorden"

Russian: "ответов", "показать ответы", "ещё X ответов"

Chinese: "回复", "查看回复", "X条回复"

Japanese: "返信", "返信を表示", "X件の返信"

Arabic: "ردود", "عرض الردود", "X ردود أخرى"

Hindi: "उत्तर", "उत्तर देखें", "X और उत्तर"

🔥 What's New in v2.1 - Reply Expansion Update

✨ Major New Features

Automatic Comment Reply Expansion

The feature everyone's been waiting for! No more manually clicking "View X replies" buttons.

Smart Reply Detection: Uses advanced pattern matching to find reply buttons in any supported language

Intelligent Filtering: Knows the difference between "show replies" and "hide replies" — won't collapse stuff you want to see

Viewport-Aware Processing: Only expands replies visible on your screen (configurable) to save bandwidth and processing

Scroll Position Preservation: Remembers exactly where you were reading when replies expand

Performance Optimized:

Processes one reply button at a time to avoid overwhelming Facebook

Debounced scroll handling for buttery smooth performance

Configurable delays between expansions so Facebook doesn't get mad

Enhanced Configuration System

More granular control over everything:

const CONFIG = {
    sortPreference: "all",      // "newest" or "all"
    debug: true,               // See what's happening under the hood
    expandReplies: true,       // The star of the show
    replyExpandDelay: 1000,    // Fine-tune timing
    viewportOnly: true         // Bandwidth saver
};

🔧 Under-the-Hood Improvements

Better Performance: Added debouncing for scroll events and mutation observers

Memory Management: Properly clears processed reply buttons on page navigation using WeakSet

Enhanced Debugging: Added specific logs for reply expansion activities with detailed info

Code Organization: Separated reply expansion logic into dedicated, maintainable functions

Error Handling: More robust error catching and recovery

📝 Technical Nerdy Stuff

Reply Button Detection: Uses regex patterns with Unicode support for international text

Scroll Handling: Implements passive event listeners for better browser performance

State Management: Uses WeakSet for processed buttons to prevent memory leaks

Event Optimization: Throttled mutation observers to balance responsiveness with CPU usage

🐛 Bug Fixes from v2.0

FIXED: "All Comments" Selection Bug - Resolved critical issue where script would incorrectly select "Newest" when "All Comments" was configured

FIXED: Menu Item Detection - Improved detection to handle Facebook's combined title+description text format

Enhanced Text Matching: Three-tier matching strategy for better reliability

Better Error Recovery: Script now handles Facebook's A/B testing changes more gracefully

🎯 Complete Features Summary

✅ Automatic comment sorting (All Comments / Newest) with server-side enforcement

✅ Automatic reply expansion with smart detection and language support

✅ Multi-language support (14+ languages for UI, 12+ for reply detection)

✅ Smart scroll position preservation so you never lose your place

✅ Network request interception for bulletproof sorting consistency

✅ Comprehensive debug mode for troubleshooting and transparency

✅ Performance optimization with configurable delays and viewport awareness

✅ Memory leak prevention with proper cleanup and state management

🔧 Troubleshooting & Fine-Tuning

Reply Expansion Not Working?

1. Check Configuration: Make sure expandReplies: true in the CONFIG section

2. Console Debug: Look for logs starting with [FB Comment Sorter] in browser console (F12)

3. Timing Issues: Try increasing replyExpandDelay to 2000 or 3000 if Facebook is rate-limiting

4. Visibility Settings: Disable viewportOnly: false to expand all replies regardless of screen position

5. Language Detection: Check if your Facebook language is supported in the list above

Comment Sorting Not Working?

1. Clear Browser Cache: Sometimes Facebook's cached responses interfere

2. Check Network Tab: Look for modified requests with sort parameters in browser dev tools

3. Language Issues: Make sure your Facebook interface language is in the supported list

4. Facebook A/B Testing: Sometimes Facebook temporarily changes their interface - wait a day or two

Performance Issues?

1. Enable Viewport Mode: Set viewportOnly: true to reduce processing overhead

2. Increase Delays: Bump replyExpandDelay to 1500-2000ms on slower connections

3. Disable Debug: Set debug: false for production use to reduce console spam

4. Selective Expansion: You can manually disable reply expansion on heavy pages by setting expandReplies: false

🚨 Known Limitations & Warnings

Reply expansion processes one button at a time to avoid overwhelming Facebook's servers and getting rate-limited

Some Facebook A/B tests might temporarily affect functionality - this is normal, wait it out

Very long comment threads (500+ replies) might require manual intervention due to Facebook's own limits

Script might occasionally break parts of Facebook interface during major Facebook updates

Mobile Facebook app not supported - this is for desktop/mobile web only

💡 Performance Tips & Best Practices

Enable viewportOnly to reduce processing overhead and save bandwidth

Increase replyExpandDelay on slower connections or if you notice Facebook throttling

Disable debug mode for daily use to reduce console noise

Monitor browser performance - if Facebook gets sluggish, temporarily disable reply expansion

Use "All Comments" over "Newest" if you want to see the full conversation context

Refresh page if things get weird - Facebook's SPA sometimes needs a reset

⚠️ Final Warning

This script can sometimes break parts of the Facebook interface, especially during Facebook updates or when they're A/B testing new features. If anything looks off or stops working right, just disable the script temporarily.

Use at your own risk — you've been warned, but it's totally worth it for the convenience!

Enjoy reading Facebook comments the way they should be! ✌️

Version 2.1 - Now with automatic reply expansion! Perfect for deep-diving into comment threads without the constant clicking. 🚀