Greasy Fork

来自缓存

Greasy Fork is available in English.

悬浮按钮 - 复制URL

在指定网站页面上显示一个悬浮复制按钮,点击按钮复制当前网页的URL地址到剪切板。在const sites=的列表中添加需要显示的网站[删除这段就是显示在所有网站上]。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         悬浮按钮 - 复制URL
// @namespace   http://www.wuzhij.us.kg/
// @version      1.0
// @description  在指定网站页面上显示一个悬浮复制按钮,点击按钮复制当前网页的URL地址到剪切板。在const sites=的列表中添加需要显示的网站[删除这段就是显示在所有网站上]。
// @author       wuzhij
// @match        *://*/*
// @icon         http://www.wuzhij.us.kg/wz/copyurl.svg
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @license      GPL License
// ==/UserScript==

(function() {
    'use strict';

    const sites = [
        'example.com',
        'another-site.com',
        '自定义网站'
    ];

    function createButton() {
        const button = document.createElement('button');
        button.innerText = '复制URL';
        button.style.position = 'fixed';
        button.style.bottom = '20px';
        button.style.right = '20px';
        button.style.padding = '10px 20px';
        button.style.border = 'none';
        button.style.backgroundColor = '#ff0000';
        button.style.color = 'white';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.addEventListener('click', () => {
            navigator.clipboard.writeText(window.location.href).then(() => {
                const message = document.createElement('div');
                message.innerText = '已复制到剪切板';
                message.style.position = 'fixed';
                message.style.bottom = '70px';
                message.style.right = '20px';
                message.style.padding = '10px 20px';
                message.style.backgroundColor = 'green';
                message.style.color = 'white';
                message.style.borderRadius = '5px';
                document.body.appendChild(message);
                setTimeout(() => {
                    document.body.removeChild(message);
                }, 1000);
            }).catch(err => {
                console.error('复制失败:', err);
            });
        });
        document.body.appendChild(button);
    }

    function checkSite() {
        const currentHost = window.location.hostname;
        if (sites.some(site => currentHost.includes(site))) {
            createButton();
        }
    }

    checkSite();
})();