YouTube → SkipCut Link Rewriter

Rewrite YouTube links to SkipCut links before they are opened

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

您需要先安裝使用者腳本管理器擴展,如 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.0
// @description  Rewrite YouTube links to SkipCut links before they are opened
// @author       Opus-X
// @license      MIT
// @icon         https://www.skipcut.com/favicon.ico
// @match        *://*/*
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    function convertYouTubeToSkipCut(url) {
        try {
            const u = new URL(url);

            if (u.hostname.match(/(^|\.)youtube\.com$/)) {
                // Normal video
                if (u.pathname === '/watch' && u.searchParams.has('v')) {
                    return `https://www.skipcut.com/watch?v=${u.searchParams.get('v')}`;
                }
                // Live stream
                if (u.pathname.startsWith('/live/')) {
                    const liveId = u.pathname.split('/')[2];
                    if (liveId) {
                        return `https://www.skipcut.com/live/${liveId}`;
                    }
                }
                // Playlist
                if (u.pathname === '/playlist' && u.searchParams.has('list')) {
                    return `https://www.skipcut.com/playlist?list=${u.searchParams.get('list')}`;
                }
            }
        } catch (e) {}
        return null;
    }

    document.addEventListener('click', function (e) {
        // Only left-click without modifier keys
        if (e.button !== 0 || e.ctrlKey || e.shiftKey || e.metaKey) return;

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

        const newUrl = convertYouTubeToSkipCut(a.href);
        if (newUrl) {
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation(); // Kill YouTube's own router
            window.open(newUrl, '_blank', 'noopener');
        }
    }, true); // capture mode so we run before site handlers
})();