UserAPI Link Redirector

Redirect UserAPI links to a formatted version (single redirect)

اعتبارا من 04-01-2024. شاهد أحدث إصدار.

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

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==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);
})();