Webpage Info Extract

Copy page info to clipboard

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);
    }
})();