toolkit - Theo

toolkit

Stan na 15-10-2025. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         toolkit - Theo
// @namespace    http://tampermonkey.net/
// @version      2025-10-15
// @description  toolkit
// @author       Theo·Chan
// @license      AGPL
// @match        *://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function () {
    'use strict';
    console.log('toolkit - Theo');
    //--------------------------复制为Markdown链接----------------------------------------------------//
    // 注册右键菜单项
    GM_registerMenuCommand('复制为Markdown链接', () => {
        const markdownLink = `[${document.title}](${window.location.href})`;
        console.log(markdownLink);
        // 复制到剪贴板
        copyText(markdownLink);
    });
    function copyText(markdownLink) {
        let _nav = window.navigator;
        // 优先使用 Clipboard API
        if (_nav.isPrototypeOf('clipboard') && _nav.clipboard && window.isSecureContext) {
            _nav.clipboard.writeText(markdownLink)
                .then(() => createToast("已复制为Markdown链接"))
                .catch(() => fallbackCopy(markdownLink));
        } else {
            fallbackCopy(markdownLink);
        }
    }

    function fallbackCopy(text) {
        const textarea = document.createElement("textarea");
        textarea.value = text;
        document.body.appendChild(textarea);
        textarea.select();
        try {
            document.execCommand("copy");
            createToast("已复制为Markdown链接:<br/>" + text);
        } catch (err) {
            createToast("复制失败,请手动复制:<br/>" + text, false, 10000);
        }
        document.body.removeChild(textarea);
    }

    // 创建提示框元素
    const createToast = (content, isSuccess = true, timeOut = 1500) => {
        const toast = document.createElement('div');
        toast.innerHTML = content;
        toast.style = `
            position: fixed;
            word-break: break-all;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            padding: 12px 24px;
            color: ${isSuccess ? '#4CAF50' : '#F44336'};
            border-radius: 4px;
            z-index: 99999;
            opacity: 1;
            background-color: ${isSuccess ? 'rgb(34 57 54 / 80%)' : 'rgb(254 225 164 / 80%)'};
            transition: opacity 0.5s ease-out;
        `;
        document.body.appendChild(toast);

        // 触发淡出
        setTimeout(() => {
            toast.style.opacity = 0;
            toast.addEventListener('transitionend', () => {
                toast.remove();
            }, { once: true });
        }, timeOut); // 显示 1.5 秒后开始淡出

        return toast;
    };

}) ();