Greasy Fork

Greasy Fork is available in English.

复制链接按钮

在右下角添加一个按钮,点击后复制当前网页链接,并显示提示信息

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         复制链接按钮
// @namespace    http://tampermonkey.net/
// @version      1.8
// @description  在右下角添加一个按钮,点击后复制当前网页链接,并显示提示信息
// @author       KaidQiao
// @match        *://*/*
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 创建按钮元素
    let button = document.createElement('button');
    button.innerText = '复制链接';
    button.style.position = 'fixed';
    button.style.bottom = '20px';
    button.style.right = '20px';
    button.style.zIndex = '1000';
    button.style.padding = '10px';
    button.style.backgroundColor = 'rgba(169, 169, 169, 0.6)'; // 初始背景色:透明灰色
    button.style.color = 'white'; // 文字颜色:白色
    button.style.border = 'none'; // 取消边框
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    button.style.backdropFilter = 'blur(10px)'; // 毛玻璃效果
    button.style.transition = 'background-color 0.3s'; // 背景色过渡效果

    // 添加鼠标经过事件
    button.addEventListener('mouseover', function() {
        button.style.backgroundColor = 'rgba(9, 187, 7, 0.8)'; // 鼠标经过背景色:透明绿色
    });

    // 添加鼠标离开事件
    button.addEventListener('mouseout', function() {
        button.style.backgroundColor = 'rgba(169, 169, 169, 0.6)'; // 鼠标离开背景色:透明灰色
    });

    // 添加按钮点击事件
    button.onclick = function() {
        let url = window.location.href;
        GM_setClipboard(url, 'text');
        
        // 创建并显示提示信息
        let tooltip = document.createElement('div');
        tooltip.innerText = '链接已复制';
        tooltip.style.position = 'fixed';
        tooltip.style.bottom = '60px';
        tooltip.style.right = '20px';
        tooltip.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
        tooltip.style.color = 'white';
        tooltip.style.padding = '5px 10px';
        tooltip.style.borderRadius = '3px';
        tooltip.style.zIndex = '1001';
        document.body.appendChild(tooltip);

        // 3秒后移除提示信息
        setTimeout(function() {
            tooltip.remove();
        }, 3000);
    };

    // 将按钮添加到页面上
    document.body.appendChild(button);
})();