Greasy Fork

Greasy Fork is available in English.

Twitter fast clean link copy

Copy tweet links with one click and strip query parameters

当前为 2022-01-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Twitter fast clean link copy
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Copy tweet links with one click and strip query parameters
// @author       cro
// @match        https://*.twitter.com/*
// @icon         https://www.google.com/s2/favicons?domain=twitter.com
// @grant        none
// @license      MIT
// ==/UserScript==
/* jshint esversion: 6 */

(function()
{
    'use strict';
    let id = 'cro-copy-id';

    let make_button = function()
    {
        let button = document.createElement('button');
        button.textContent = 'copy link';
        button.onclick = function ()
        {
            let url = new URL(button.closest('article').querySelector('[href*="status"]').href);
            url.pathname = url.pathname.split('/').slice(0,4).join('/');
            navigator.clipboard.writeText(url.toString());
        };
        button.id = id;
        return button;
    };

    setInterval(function()
    {
        let nodes = document.querySelectorAll('article div[role="group"]');
        for (let node of nodes)
        {
            if (!node.querySelector(`#${id}`))
            {
                node.lastChild.append(make_button());
            }
        }
    }, 250);
})();