Facebook Group Sort by CHRONOLOGICAL NEW POSTS

Forces Facebook groups to sort posts by "CHRONOLOGICAL" automatically

  1. // ==UserScript==
  2. // @name Facebook Group Sort by CHRONOLOGICAL NEW POSTS
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Forces Facebook groups to sort posts by "CHRONOLOGICAL" automatically
  6. // @author CHATgpt
  7. // @include *facebook.com/groups/*
  8. // @match *://*.facebook.com/groups/*
  9. // @exclude *facebook.com/reel/*
  10. // @exclude *facebook.com/photo/*
  11. // @exclude *facebook.com/?filter=groups*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Function to update sorting if not already set
  19. function updateSorting() {
  20. const url = new URL(window.location.href);
  21. if (!url.searchParams.has("sorting_setting")) {
  22. url.searchParams.set("sorting_setting", "CHRONOLOGICAL");
  23. window.location.replace(url.href);
  24. }
  25. }
  26.  
  27. // Run once when the script loads
  28. updateSorting();
  29.  
  30. // Observe URL changes (Facebook uses dynamic navigation)
  31. let lastUrl = location.href;
  32. const observer = new MutationObserver(() => {
  33. if (location.href !== lastUrl) {
  34. lastUrl = location.href;
  35. updateSorting();
  36. }
  37. });
  38.  
  39. // Start observing changes to the page
  40. observer.observe(document, { subtree: true, childList: true });
  41. })();