YouTube → SkipCut Link Rewriter

Rewrite YouTube links to SkipCut links before they are opened

目前為 2025-08-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTube → SkipCut Link Rewriter
// @namespace    https://greasyfork.org/nl/users/1197317-opus-x
// @version      1.03
// @description  Rewrite YouTube links to SkipCut links before they are opened
// @author       Opus-X
// @license      MIT
// @icon         https://www.skipcut.com/favicon.ico
// @match        *://*/*
// @exclude      *://skipcut.com/*
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    // Convert a YouTube URL to the corresponding SkipCut URL
    function convertYouTubeToSkipCut(url) {
        // Quick check to avoid parsing non-YouTube links
        if (!url.includes('youtube.com') && !url.includes('youtu.be')) return null;

        try {
            const u = new URL(url);
            const { hostname, pathname, searchParams } = u;

            // Handle normal YouTube domain
            if (hostname.match(/(^|\.)youtube\.com$/)) {
                // Regular video links: /watch?v=...
                if (pathname === '/watch' && searchParams.has('v')) {
                    return `https://www.skipcut.com/watch?v=${searchParams.get('v')}`;
                }

                // Live streams: /live/<id>
                if (pathname.startsWith('/live/')) {
                    const liveId = pathname.split('/')[2];
                    if (liveId) return `https://www.skipcut.com/live/${liveId}`;
                }

                // Playlists: /playlist?list=...
                if (pathname === '/playlist' && searchParams.has('list')) {
                    return `https://www.skipcut.com/playlist?list=${searchParams.get('list')}`;
                }
            }

            // Handle youtu.be short links: https://youtu.be/<id>
            if (hostname === 'youtu.be') {
                const videoId = pathname.slice(1); // remove leading "/"
                if (videoId) return `https://www.skipcut.com/watch?v=${videoId}`;
            }

        } catch (e) {
            // Ignore invalid URLs
        }

        return null; // Not a YouTube link we can convert
    }

    // Intercept clicks on the page
    document.addEventListener('click', e => {
        // Only handle left-clicks without modifier keys
        if (e.button !== 0 || e.ctrlKey || e.shiftKey || e.metaKey) return;

        const a = e.target.closest('a[href]'); // Find closest link
        if (!a) return;

        const newUrl = convertYouTubeToSkipCut(a.href);
        if (!newUrl) return;

        // Prevent normal navigation
        e.preventDefault();
        e.stopImmediatePropagation(); // Stop site scripts like YouTube router

        // Open the SkipCut version in a new tab
        window.open(newUrl, '_SKIPCUT', 'noopener,noreferrer');
    }, true); // Capture phase to run before site handlers
})();