Copy Title Alt+T

Press Alt+T to copy title and url like this `# ${TITLE}\n${URL}`

目前為 2020-04-15 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Copy Title Alt+T
// @namespace    https://userscript.snomiao.com/
// @version      0.1
// @description  Press Alt+T to copy title and url like this `# ${TITLE}\n${URL}`
// @author       [email protected]
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    var 复制文本 = (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, 9999);
        console.log('test')
        if (document.execCommand('copy')) {
            document.execCommand('copy');
            var ok = true
        }
        document.body.removeChild(input);
        return ok || false
    };
    var 取标题 = () => {
        var 标题列 = [...document.querySelectorAll('h1')]
        return 标题列.length == 1 && 标题列[0].innerText.trim() || document.title || ''
    }
    window.addEventListener('keydown', (e) => {
        if (!(e.altKey && e.code == 'KeyT')) return;
        var 标题地址 = `# ${取标题()}\n${location.href}`
        复制文本(标题地址)
            ? alert(标题地址 + '\n copyied!')
            : alert('copy title failed, please check browser version')
    })
})();