Greasy Fork 还支持 简体中文。

复制链接按钮

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();