Greasy Fork

来自缓存

Greasy Fork is available in English.

灵动 MD 链接复制

在网页上添加一个动态按钮,鼠标接近时显示,点击后将标题和URL转换为Markdown链接并复制到剪贴板

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         灵动 MD 链接复制
// @namespace    http://tampermonkey.net/
// @version      0.3.0
// @description  在网页上添加一个动态按钮,鼠标接近时显示,点击后将标题和URL转换为Markdown链接并复制到剪贴板
// @author       RrOrange
// @homepage     https://github.com/zhiyu1998/rrorange-tampermonkey-list
// @license      MIT
// @match        *://*/*
// @grant        GM_setClipboard
// @grant        GM_notification
// ==/UserScript==

(function() {
    'use strict';

    // 创建按钮
    var button = document.createElement('button');
    button.innerText = 'Copy MD Link';
    button.style.position = 'fixed';
    button.style.bottom = '20px';
    button.style.right = '-100px'; // 默认隐藏在屏幕外
    button.style.zIndex = '10000';
    button.style.padding = '10px';
    button.style.backgroundColor = '#4f6f46';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    button.style.transition = 'right 0.3s ease'; // 平滑过渡效果

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

    // 鼠标移动事件:检测鼠标位置并控制按钮显示
    document.addEventListener('mousemove', function(event) {
        var mouseX = event.clientX;
        var windowWidth = window.innerWidth;
        if (windowWidth - mouseX < 100) { // 鼠标距离右侧小于100px时显示
            button.style.right = '20px'; // 按钮滑入
        } else if (mouseX < windowWidth - 120) { // 鼠标离开按钮区域
            button.style.right = '-100px'; // 按钮滑回隐藏
        }
    });

    // 点击事件:复制 Markdown 链接
    button.addEventListener('click', function() {
        var title = document.title;
        var url = window.location.href;
        var mdLink = '[' + title + '](<' + url + '>)';
        GM_setClipboard(mdLink);
        GM_notification({text: "Markdown链接已复制到剪贴板!", title: "成功", timeout: 2000});
    });
})();