Onlyfans/Fansly "leak" finder

Checks some sites for OF/Fansly "leaks"

// ==UserScript==
// @name         Onlyfans/Fansly "leak" finder
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Checks some sites for OF/Fansly "leaks"
// @author       You
// @match        https://onlyfans.com/*
// @match        *coomer.su/*
// @match        *fapello.com/*
// @match        https://fansly.com/*
// @grant        GM.xmlHttpRequest
// @license      Unlicense
// ==/UserScript==

(function() {
    'use strict';

    function getUsernameFromUrl() {
        let username = '';
        if (window.location.hostname === 'onlyfans.com') {
            const urlParts = window.location.pathname.split('/');
            username = urlParts[1];
        } else if (window.location.hostname === 'fansly.com') {
            const matches = window.location.pathname.match(/^\/([^/]+)/);
            if (matches) {
                username = matches[1];
            }
        }
        return username;
    }

    function fetchUserProfileFansly(username, retryCount = 0) {
        const apiUrl = `https://apiv3.fansly.com/api/v1/account?usernames=${username}`;

        GM.xmlHttpRequest({
            method: 'GET',
            url: apiUrl,
            onload: function(response) {
                if (response.status === 200) {
                    const data = JSON.parse(response.responseText);
                    if (data.success && data.response.length > 0) {
                        const id = data.response[0].id;
                        fetchUserProfileCoomer(id, "fansly")
                    } else {
                        console.log(`User ${username} not found`);
                    }
                } else {
                    console.error('Network response was not ok:', response.status);
                    if (retryCount < 5) {
                        console.log(`Retrying... Attempt ${retryCount + 1}`);
                        setTimeout(() => fetchUserProfileFansly(username, retryCount + 1), 1000);
                    } else {
                        console.error('Max retry attempts reached');
                    }
                }
            },
            onerror: function(error) {
                console.error('Error fetching data:', error);
            }
        });
    }


    function fetchUserProfileCoomer(username, service, retryCount = 0) {
        const apiUrl = `https://coomer.su/api/v1/${service}/user/${username}/profile`;

        GM.xmlHttpRequest({
            method: 'GET',
            url: apiUrl,
            onload: function(response) {
                if (response.status === 200) {
                    const data = JSON.parse(response.responseText);
                    const profileUrl = `https://coomer.su/${service}/user/${username}`;
                    addLinkToMenu(profileUrl, 'Coomer.su');
                } else if (response.status === 404) {
                    console.log(`User ${username} not found`);
                } else {
                    console.error('Network response was not ok:', response.status);
                    if (retryCount < 5) {
                        console.log(`Retrying... Attempt ${retryCount + 1}`);
                        setTimeout(() => fetchUserProfileCoomer(username, retryCount + 1), 1000);
                    } else {
                        console.error('Max retry attempts reached');
                    }
                }
            },
            onerror: function(error) {
                console.error('Error fetching data:', error);
            }
        });
    }

    function fetchUserProfileFapello(username, retryCount = 0) {
        const apiUrl = `https://fapello.com/${username}/`;

        GM.xmlHttpRequest({
            method: 'GET',
            url: apiUrl,
            onload: function(response) {
                if (response.finalUrl === apiUrl) {
                    const profileUrl = `https://fapello.com/${username}/`;
                    addLinkToMenu(profileUrl, 'Fapello');
                } else {
                    console.log(`Request was redirected`);
                }
            },
            onerror: function(error) {
                console.error('Error fetching data:', error);
                if (retryCount < 5) {
                    console.log(`Retrying... Attempt ${retryCount + 1}`);
                    setTimeout(() => fetchUserProfileFapello(username, retryCount + 1), 1000);
                } else {
                    console.error('Max retry attempts reached');
                }
            }
        });
    }

function addLinkToMenu(link, displayText) {
    if (window.location.hostname === 'fansly.com') {
        const followButton = document.querySelector('.follow-profile');
        if (followButton) {
            let menuElement = followButton.cloneNode(true);

            // Remove all event listeners by creating a new element with the same attributes and children
            let newMenuElement = followButton.cloneNode(false);
            while (menuElement.firstChild) {
                newMenuElement.appendChild(menuElement.firstChild);
            }
            newMenuElement.querySelector("xd-localization-string").innerText = displayText

            // Create a new <a> element to wrap the new menu element
            const aElement = document.createElement('a');
            aElement.setAttribute('href', link);
            aElement.appendChild(newMenuElement);

            followButton.after(aElement);
        } else {
            console.error('Follow button not found');
        }
    } else {
        const menuElement = document.querySelector('.l-header__menu.m-native-custom-scrollbar.m-scrollbar-y.m-invisible-scrollbar');
        if (menuElement) {
            const aElement = document.createElement('a');
            aElement.setAttribute('href', link);
            aElement.textContent = displayText;
            aElement.style.marginRight = "10px";

            // Check if there are already links in the menu
            const existingLinks = menuElement.querySelectorAll('a');
            if (existingLinks.length > 0) {
                const lineBreak = document.createElement('br');
                menuElement.appendChild(lineBreak);
            }

            menuElement.appendChild(aElement);
        } else {
            console.error('Menu element not found');
        }
    }
}





    function waitForElement(selector, callback) {
        const observer = new MutationObserver((mutations, observer) => {
            const element = document.querySelector(selector);
            if (element) {
                observer.disconnect();
                callback(element);
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    const username = getUsernameFromUrl();
    if (window.location.hostname === 'fansly.com' && username) {
        waitForElement('.profile-details', () => {
            fetchUserProfileFansly(username);
            fetchUserProfileCoomer(username,"fapello");
            fetchUserProfileFapello(username);
        });
    } else {
        waitForElement('.l-header__menu.m-native-custom-scrollbar.m-scrollbar-y.m-invisible-scrollbar', () => {
            fetchUserProfileCoomer(username,"onlyfans");
            fetchUserProfileFapello(username);
        });
    }
})();