Patreon Redirector

Adds a button to redirect from a Patreon creator page to the Kemono page

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Patreon Redirector
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Adds a button to redirect from a Patreon creator page to the Kemono page
// @author       YoureIronic
// @icon         https://www.google.com/s2/favicons?sz=128&domain=kemono.cr
// @match        https://www.patreon.com/*
// @match        https://kemono.cr/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // --- CONFIGURATION ---
    const CONFIG = {
        AUTO_REDIRECT: false, // Set this to true to redirect automatically without clicking the button
    };
    // ---------------------

    let lastUrl = location.href;

    function findCreatorId() {
        if (!location.hostname.includes('patreon.com')) return null;

        const scripts = document.getElementsByTagName('script');
        const regex = /"creator":\s*\{\s*"data":\s*\{\s*"id":\s*"(\d+)"/;

        for (let script of scripts) {
            if (script.textContent) {
                const match = script.textContent.match(regex);
                if (match) return match[1];
            }
        }

        if (window.patreon && window.patreon.bootstrap && window.patreon.bootstrap.creator) {
            return window.patreon.bootstrap.creator.data.id;
        }

        return null;
    }

    function createButton(id) {
        const existingBtn = document.getElementById('kemono-redirect-btn');
        if (existingBtn) existingBtn.remove();

        const btn = document.createElement('a');
        btn.id = 'kemono-redirect-btn';
        btn.href = `https://kemono.cr/patreon/user/${id}`;
        btn.innerText = 'Open in Kemono';
        btn.target = '_blank';

        Object.assign(btn.style, {
            position: 'fixed',
            bottom: '20px',
            right: '20px',
            zIndex: '9999',
            padding: '10px 20px',
            backgroundColor: '#FF424D',
            color: 'white',
            fontWeight: 'bold',
            borderRadius: '5px',
            boxShadow: '0 2px 5px rgba(0,0,0,0.3)',
            textDecoration: 'none',
            fontFamily: 'sans-serif',
            cursor: 'pointer'
        });

        document.body.appendChild(btn);
    }

    function init() {
        const id = findCreatorId();
        if (id) {
            console.log('Patreon Creator ID found:', id);

            if (CONFIG.AUTO_REDIRECT) {
                 window.location.replace(`https://kemono.cr/patreon/user/${id}`);
            } else {
                 createButton(id);
            }
        }
    }

    const observer = new MutationObserver(() => {
        if (location.href !== lastUrl) {
            lastUrl = location.href;
            setTimeout(init, 1000);
        }
    });

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

    setTimeout(init, 1500);
})();