Facebook Recent

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
})();