Webpage Info Extract

Copy page info to clipboard

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

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

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         Webpage Info Extract
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Copy page info to clipboard
// @author       Grok + Human
// @match        *://*/*
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    // 注册菜单命令
    GM_registerMenuCommand('Copy Title and URL as Markdown', copyToClipboard);

    function copyToClipboard() {
        // 使用window.top获取顶级窗口
        const topWindow = window.top;
        // 获取顶级窗口的标题
        const title = topWindow.document.title;
        // 获取顶级窗口的URL
        const url = topWindow.location.href;
        // 创建Markdown格式的链接
        const markdownText = `[${title}](${url})`;

        // 创建临时textarea元素来实现复制
        const tempTextarea = document.createElement('textarea');
        tempTextarea.value = markdownText;
        tempTextarea.style.position = 'fixed';
        tempTextarea.style.opacity = '0';
        document.body.appendChild(tempTextarea);

        // 选择文本并复制
        tempTextarea.select();
        try {
            document.execCommand('copy');
            // alert('Markdown link copied to clipboard:\n' + markdownText);
        } catch (err) {
            alert('Failed to copy: ' + err);
        }

        // 清理
        document.body.removeChild(tempTextarea);
    }
})();