FBTitle Fix

Replaces generic Facebook tab title with the actual page or group name

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         FBTitle Fix
// @namespace    https://github.com/2u841r/FBTitle-Fix
// @version      1.0.0
// @description  Replaces generic Facebook tab title with the actual page or group name
// @author       Zubair Ibn Zamir
// @license      MIT 
// @match        *://*.facebook.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict';

  function getPageName() {
    const h1btn = document.querySelector('h1 div[role="button"]');
    if (h1btn) {
      const text = h1btn.childNodes[0]?.textContent?.trim();
      if (text) return text;
    }
    const h1 = document.querySelector('h1');
    if (h1) {
      const text = h1.textContent?.trim();
      if (text) return text;
    }
    return null;
  }

  function updateTitle() {
    const name = getPageName();
    if (name && !document.title.startsWith(name)) {
      document.title = name + ' | Facebook';
    }
  }

  const observer = new MutationObserver(() => updateTitle());
  observer.observe(document.body, { childList: true, subtree: true });

  const _pushState = history.pushState.bind(history);
  history.pushState = function (...args) {
    _pushState(...args);
    setTimeout(updateTitle, 500);
  };

  window.addEventListener('popstate', () => setTimeout(updateTitle, 500));

  updateTitle();
})();