UserAPI Link Redirector

Redirect UserAPI links to a formatted version (single redirect)

04.01.2024 itibariyledir. En son verisyonu görün.

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

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 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.

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

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!)

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.

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

// ==UserScript==
// @name         UserAPI Link Redirector
// @version      0.6
// @description  Redirect UserAPI links to a formatted version (single redirect)
// @match        https://*.userapi.com/*
// @namespace https://greasyfork.org/users/789838
// ==/UserScript==

(function() {
    'use strict';

    // Функция для форматирования и переадресации ссылки
    function redirectUserAPILink(link) {
        // Регулярное выражение для извлечения нужных параметров из ссылки
        var regex = /https:\/\/.*?\/impg\/(.*?)(?:\/(.*?))?\?.*$/;
        var matches = link.match(regex);

        if (matches && matches.length >= 2) {
            // Формирование новой ссылки
            var newLink = 'https://pp.userapi.com/' + matches[1];
            if (matches[2]) {
                newLink += '/' + matches[2];
            }
            console.log('Redirecting to:', newLink);

            // Проверяем, была ли уже выполнена переадресация
            if (!window.location.redirected) {
                window.location.replace(newLink);
                // Устанавливаем флаг, чтобы избежать повторной переадресации
                window.location.redirected = true;
            }
        } else {
            console.log('Unable to format link:', link);
        }
    }

    // Переадресуем текущую страницу, если она соответствует фильтру
    redirectUserAPILink(window.location.href);
})();