Discord & Spotify URL Redirector

Automatically redirects Discord and Spotify URLs to desktop apps

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Discord & Spotify URL Redirector
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Automatically redirects Discord and Spotify URLs to desktop apps
// @author       You
// @match        *://discord.com/channels/*
// @match        *://open.spotify.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    
    const currentUrl = window.location.href;
    
    // Discord redirect
    if (currentUrl.startsWith('https://discord.com/channels/')) {
        const newUrl = currentUrl.replace('https://discord.com/channels/', 'discord://discord.com/channels/');
        window.location.replace(newUrl);
    }
    
    // Spotify redirect
    if (currentUrl.startsWith('https://open.spotify.com/')) {
        // Преобразуем URL вида https://open.spotify.com/track/ID в spotify:track:ID
        const spotifyUrl = new URL(currentUrl);
        const pathParts = spotifyUrl.pathname.split('/').filter(part => part.length > 0);
        
        if (pathParts.length >= 2) {
            const type = pathParts[0]; // track, album, artist, playlist и т.д.
            const id = pathParts[1];
            const newUrl = `spotify:${type}:${id}`;
            window.location.replace(newUrl);
        }
    }
})();