Replace Service Links

Replace the patreon links with kemono links for easy navigation. Strictly on Kemono.su

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Replace Service Links
// @namespace   https://github.com/Official-Husko/violentmonkey-scripts
// @match       https://kemono.su/*
// @grant       none
// @version     1.0.0
// @license     GNU GPLv3
// @author      Official Husko
// @icon        https://www.pulexart.com/uploads/7/0/1/2/70121829/3-greyfox.png
// @description Replace the patreon links with kemono links for easy navigation. Strictly on Kemono.su
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract meta content by name
    function getMetaContentByName(name) {
        const metaTag = document.querySelector(`meta[name="${name}"]`);
        return metaTag ? metaTag.getAttribute('content') : null;
    }

    // Function to extract numeric part from the right of a string
    function extractNumericPartFromRight(inputString) {
        const match = inputString.match(/(\d+)$/);
        return match ? match[1] : null;
    }

    // Get USER_ID and SERVICE_ID from meta tags
    const USER_ID = getMetaContentByName('user');
    const SERVICE_ID = getMetaContentByName('service');

    // Check if USER_ID and SERVICE_ID are available
    if (USER_ID && SERVICE_ID) {
        // Find and replace Patreon links
        document.querySelectorAll('a[href*="patreon.com/posts/"]').forEach(link => {
            const match = link.href.match(/https:\/\/(www\.)?patreon\.com\/posts\/(.+)/);
            if (match) {
                const rawPostID = match[2];
                const numericPostID = extractNumericPartFromRight(rawPostID);
                // Replace the link with the custom format
                if (numericPostID) {
                    link.href = `https://kemono.su/${SERVICE_ID}/user/${USER_ID}/post/${numericPostID}`;
                }
            }
        });
    }
})();