YouTube Archive Me Button

Adds an "Archive Me" button to YouTube video action panels that redirects to PreserveTube.com with the current video URL.

目前為 2025-10-30 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Archive Me Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds an "Archive Me" button to YouTube video action panels that redirects to PreserveTube.com with the current video URL.
// @author       Ghosty-Tongue
// @match        *://www.youtube.com/watch?v=*
// @grant        none
// @run-at       document-idle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const ARCHIVE_URL_BASE = 'https://preservetube.com/save?url=';
    const BUTTON_ID = 'archive-me-custom-button';
    const ACTION_BUTTONS_CONTAINER_SELECTOR = '#actions';
    const LIKE_DISLIKE_SEGMENT_SELECTOR = '#segmented-like-button';

    function waitForElement(selector, callback) {
        const interval = setInterval(() => {
            const element = document.querySelector(selector);
            if (element) {
                clearInterval(interval);
                callback(element);
            }
        }, 500);
    }

    function createArchiveButton(container) {
        if (document.getElementById(BUTTON_ID)) {
            return;
        }

        const button = document.createElement('button');
        button.id = BUTTON_ID;
        button.title = ''; 

        const iconSpan = document.createElement('span');
        iconSpan.textContent = '🗃️';
        iconSpan.style.marginRight = '6px';
        iconSpan.style.fontSize = '18px';
        iconSpan.style.lineHeight = '1';

        const textSpan = document.createElement('span');
        textSpan.textContent = 'Archive Me';

        button.appendChild(iconSpan);
        button.appendChild(textSpan);

        button.style.cssText = `
            background-color: var(--yt-spec-badge-chip-background);
            color: var(--yt-spec-text-primary);
            border: none;
            padding: 8px 12px;
            border-radius: 18px;
            font-size: 14px;
            font-family: "Roboto", "Arial", sans-serif;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.1s ease-in-out;
            display: flex;
            align-items: center;
            justify-content: center;
            min-width: 0;
            line-height: 1.25;
            text-transform: none;
            white-space: nowrap;
        `;

        const defaultBg = 'var(--yt-spec-badge-chip-background)';
        const hoverBg = 'var(--yt-spec-flat-button-hover-background)'; 

        button.addEventListener('mouseover', () => {
            button.style.backgroundColor = hoverBg;
        });
        button.addEventListener('mouseout', () => {
            button.style.backgroundColor = defaultBg;
        });

        button.addEventListener('click', () => {
            const currentUrl = window.location.href;
            const encodedUrl = encodeURIComponent(currentUrl);
            const targetUrl = ARCHIVE_URL_BASE + encodedUrl;

            window.location.href = targetUrl;
        });

        const likeDislikeSegment = container.querySelector(LIKE_DISLIKE_SEGMENT_SELECTOR);

        if (likeDislikeSegment) {
            likeDislikeSegment.after(button);
            button.style.marginLeft = '8px';
        } else {
            const fallbackContainer = container.querySelector('#top-level-buttons-computed') || container;
            fallbackContainer.prepend(button);
            button.style.marginLeft = '8px';
        }
    }

    waitForElement(ACTION_BUTTONS_CONTAINER_SELECTOR, (container) => {
        const observer = new MutationObserver(() => {
            createArchiveButton(container);
        });

        observer.observe(container, { childList: true, subtree: true });

        createArchiveButton(container);
    });

})();