🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

Copy Title Alt+T

Press Alt+T to copy title and url like this `# ${TITLE}\n${URL}` and Alt+Shift+T to copy the markdown style link `[${TITLE}]( ${URL} )`

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name            Copy Title Alt+T
// @name:zh         Alt+T 复制Markdown格式标题和地址快速分享
// @name:en         Alt+T Copy Title and Link as Markdown Style
// @description     Press Alt+T to copy title and url like this `# ${TITLE}\n${URL}` and Alt+Shift+T to copy the markdown style link `[${TITLE}]( ${URL} )`
// @description:zh  按 Alt+T 复制 Markdown 格式的链接 `[${TITLE}]( ${URL} )` and Alt+Shift+T 复制 标题和地址 `# ${TITLE}\n${URL}`
// @namespace       https://userscript.snomiao.com/
// @version         0.7.3
// @author          [email protected]
// @match           *://*/*
// @grant           none
// ==/UserScript==

(function () {
    'use strict';
    var textCopy = (content) => {
        const input = document.createElement('textarea');
        input.setAttribute('readonly', 'readonly');
        input.setAttribute('value', content);
        input.innerHTML = content;
        input.setAttribute(
            'style',
            'position: fixed; top:0; left:0;z-index: 9999'
        );
        document.body.appendChild(input);
        input.select();
        input.setSelectionRange(0, input.value.length);

        let ok = false;
        if (document.execCommand('copy')) {
            document.execCommand('copy');
            ok = true;
        }
        document.body.removeChild(input);
        ok && alert('Title Copied\n' + content);
        ok || alert('copy title failed, please check browser version');
        return ok || false;
    };
    var TitleGet = () => {
        const LongestTitle = [
            document.title,
            document.querySelector('h1')?.innerText || '',
        ]
            .map((str) => str.replace(/\r?\n.*/g, ''))
            .sort((a, b) => a.length - b.length)
            .pop();
        return LongestTitle;
    };
    window.addEventListener(
        'keydown',
        (e) => {
            if (e.altKey && !e.shiftKey && !e.ctrlKey && e.code == 'KeyT') {
                textCopy(`[${TitleGet()}]( ${location.href} )`);
                e.preventDefault();
                e.stopPropagation();
            }
            if (e.altKey && e.shiftKey && !e.ctrlKey && e.code == 'KeyT') {
                textCopy(`# ${TitleGet()}\n${location.href}`);
                e.preventDefault();
                e.stopPropagation();
            }
        },
        false
    );
})();