Facebook Post Extender

Shows all posts from a searched user, prioritizing unseen posts.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Advertisement:

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

Advertisement:

// ==UserScript==
// @name         Facebook Post Extender
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Shows all posts from a searched user, prioritizing unseen posts.
// @author       You
// @match        https://www.facebook.com/*
// @grant        GM_addStyle
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==

(function() {
    'use strict';

    // Configuration
    const targetUserID = '100000603742441'; // Replace with the target User ID
    const loadInterval = 2000; // Time between attempts to load more posts (milliseconds)
    const maxPostsToLoad = 50; // Maximum number of additional posts to load.

    // GM_addStyle to fix some facebook styling issues
    GM_addStyle(`
        .fbPostLoader {
            margin-top: 10px;
            text-align: center;
            cursor: pointer;
        }
    `);

    // Function to load more posts
    function loadMorePosts(userId) {
        const moreLink = document.querySelector('a[href*="more"]'); // Typical "See More" link
        if (!moreLink) {
            console.log("No more 'See More' link found.");
            return;
        }

        moreLink.click();

        setTimeout(() => { //Give the post time to load
            const posts = document.querySelectorAll('div[data-testid="post"]');
            if(posts.length >= maxPostsToLoad){
              console.log("Max posts loaded.");
              return;
            }
            loadMorePosts(userId);
        }, loadInterval);
    }

    // Function to fetch posts directly using the Graph API
    function fetchPostsFromGraphAPI(userId, after) {
        $.ajax({
            url: `/v15.0/${userId}/posts?fields=id,message,created_time,likes.summary(true),comments.summary(true)&limit=25&after=${after}`,
            dataType: 'json',
            success: function(response) {
                if (response.data && response.data.length > 0) {
                    const postsContainer = document.querySelector('div[data-testid="root"]'); // Find container
                    response.data.forEach(postData => {
                        const postElement = document.createElement('div');
                        postElement.setAttribute('data-testid', 'post');
                        postElement.innerHTML = `
                            <div class="fbPost">
                                <p>${postData.message || ''}</p>
                                <p>Created: ${postData.created_time}</p>
                                <p>Likes: ${postData.likes.summary.total_count}</p>
                                <p>Comments: ${postData.comments.summary.total_count}</p>
                            </div>
                        `;
                        postsContainer.insertBefore(postElement, postsContainer.firstChild); //Insert at beginning
                    });

                    if (response.paging && response.paging.cursors && response.paging.cursors.after) {
                        fetchPostsFromGraphAPI(userId, response.paging.cursors.after);
                    }
                }
            }
        });
    }


    // Main function to execute after page loads
    function main() {
        const searchInput = document.querySelector('input[name="q"]'); // Get the search input.
        if (searchInput) {
            searchInput.addEventListener('keyup', function(event) {
                if (event.key === 'Enter') { // Trigger on Enter keypress
                    setTimeout(() => {  //Wait for the search results to load
                       const profileLinks = document.querySelectorAll('a[href*="/profile.php?id="]');

                       profileLinks.forEach(link => {
                           const userId = link.href.match(/id=(\d+)/)[1];
                           if (userId === targetUserID) {
                               console.log(`Target user found with ID: ${userId}`);
                               //Load more posts from the more link if present
                               loadMorePosts(userId);
                               //Fetch posts using the Graph API
                               fetchPostsFromGraphAPI(userId, '');
                           }
                       });
                    }, 1500); // Wait a bit for search results to load
                }
            });
        }
    }

    // Run the main function
    main();

})();