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 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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);
    });

})();