Facebook Recent

Aggiunge un pulsante per tornare alla visualizzazione dei post più recenti su Facebook

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Facebook Recent
// @author         figuccio
// @namespace      https://greasyfork.org/users/237458
// @description    Aggiunge un pulsante per tornare alla visualizzazione dei post più recenti su Facebook
// @version        3.4
// @match          https://*.facebook.com/*
// @grant          GM_addStyle
// @grant          GM_setValue
// @grant          GM_getValue
// @grant          GM_registerMenuCommand
// @exclude        https://drive.google.com/*
// @icon           https://www.google.com/s2/favicons?sz=64&domain=facebook.com
// @noframes
// @license        MIT
// ==/UserScript==
(function() {
    'use strict';

    // Funzione per correggere il collegamento alla visualizzazione dei post più recenti
    function fixBackToTopPostsLink() {
        var backButton = document.querySelector('div[role="main"] a[href="/"][aria-label]');
        if (backButton) {
            backButton.id = "aa";
            backButton.title = "Post popolari";
        }
    }

    // Funzione per aggiornare il link dell'icona Facebook alla visualizzazione dei post più recenti
    function fixFacebookIconLink() {
        var iconLinks = document.querySelectorAll("div[role='banner'] a[role='link'][href='/'], div[role='banner']+div[data-isanimatedlayout] a[role='link'][href='/']");
        if (iconLinks && iconLinks.length > 0) {
            for (var i = 0; i < iconLinks.length && i < 2; i++) {
                var link = iconLinks[i];
                link.setAttribute("href", "/?sk=h_chr");
                link.title = "Most Recent";
                link.addEventListener("click", function() {
                    window.location.href = "https://www.facebook.com/?sk=h_chr";
                });
            }
        }
    }

    // Aggiungiamo il pulsante per tornare ai post più recenti dopo 2 secondi dall'avvio dello script
    window.setTimeout(fixBackToTopPostsLink, 2000);

    // Aggiorniamo i link dell'icona Facebook ogni secondo per garantire che siano correttamente impostati
    window.setInterval(fixFacebookIconLink, 1000);
})();