Greasy Fork

Greasy Fork is available in English.

复制链接按钮

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

当前为 2024-08-26 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴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.7
// @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(255, 255, 255, 0.3)'; // 背景色:透明白色
    button.style.color = 'black'; // 初始文字颜色:黑色
    button.style.border = 'none'; // 取消边框
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    button.style.backdropFilter = 'blur(10px)'; // 毛玻璃效果
    button.style.transition = 'background-color 0.3s, color 0.3s'; // 添加过渡效果

    // 添加按钮鼠标经过效果
    button.onmouseover = function() {
        button.style.backgroundColor = '#09BB07'; // 鼠标经过时背景色:微信绿色
        button.style.color = 'white'; // 鼠标经过时文字颜色:白色
    };
    button.onmouseout = function() {
        button.style.backgroundColor = 'rgba(255, 255, 255, 0.3)'; // 鼠标离开时背景色:透明白色
        button.style.color = 'black'; // 鼠标离开时文字颜色:黑色
    };

    // 添加按钮点击事件
    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);
})();