OnlyFans/Fansly to Coomer Redirect

Redirects OnlyFans/Fansly profiles to Coomer.su

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         OnlyFans/Fansly to Coomer Redirect
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Redirects OnlyFans/Fansly profiles to Coomer.su
// @author       droopy
// @match        *://onlyfans.com/*
// @match        *://fansly.com/*
// @match        *://*.fansly.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    function handleOnlyFans() {
        const path = window.location.pathname;
        const profilePattern = /^\/([^\/]+)$/;
        const match = path.match(profilePattern);

        if (match) {
            const username = match[1];
            window.location.replace('https://coomer.su/onlyfans/user/' + username);
        }
    }

    function handleFansly() {
        const originalFetch = window.fetch;
        window.fetch = async function(url, options) {
            if (url.includes('apiv3.fansly.com/api/v1/account?usernames=')) {
                try {
                    const response = await originalFetch(url, options);
                    const clonedResponse = response.clone();
                    const data = await clonedResponse.json();

                    // Compatibility fix: Replace optional chaining with traditional checks
                    if (data && data.response && data.response[0] && data.response[0].id) {
                        const accountId = data.response[0].id;
                        window.location.replace('https://coomer.su/fansly/user/' + accountId);
                    }
                    return response;
                } catch (error) {
                    console.error('Error intercepting Fansly API:', error);
                    return originalFetch(url, options);
                }
            }
            return originalFetch(url, options);
        };

        const fanslyPathMatch = window.location.pathname.match(/^\/([^\/]+)\/posts/);
        if (fanslyPathMatch) {
            const username = fanslyPathMatch[1];
            fetch('https://apiv3.fansly.com/api/v1/account?usernames=' + username + '&ngsw-bypass=true');
        }
    }

    if (window.location.hostname.includes('onlyfans.com')) {
        handleOnlyFans();
    } else if (window.location.hostname.includes('fansly.com')) {
        handleFansly();
    }
})();