UserAPI Link Redirector

Redirect UserAPI links to a formatted version (single redirect)

Stan na 04-01-2024. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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