网页新型鼠标右键菜单样式

前言

这个是wordpress系统的右键菜单美化,搬用于星空知。

效果图

右键美化

美化教程

美化前别忘了修改代码中的网址哦!直接搜索 www.daenyx.com 替换成你的
如果用的子比主题请打开子比后台设置 全局功能-自定义代码-底部html 把下面代码复制下去

子比主题

<style type="text/css">
    /* 基础样式重置 */
    a {
        text-decoration: none;
        color: inherit;
    }
    
    /* 菜单容器 - 修复版 */
div.usercm {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(15px) saturate(180%);
    -webkit-backdrop-filter: blur(15px) saturate(180%);
    font-size: 14px;
    width: 160px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    position: absolute;
    display: none;
    z-index: 10000;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    
    /* 新的描边方案 */
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        0 0 0 0px rgba(44, 123, 229, 0); /* 初始状态 */
}

/* 鼠标悬停时通过box-shadow添加描边 */
div.usercm:hover {
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        0 0 0 2px rgba(44, 123, 229, 0.5);
}
    
    /* 菜单列表 */
    div.usercm ul {
        list-style: none;
        margin: 0;
        padding: 5px 0;
    }
    
    /* 菜单项 */
    div.usercm ul li {
        margin: 0;
        padding: 0;
        transition: all 0.2s ease;
    }
    
    /* 菜单链接 */
    div.usercm ul li a {
        color: #555;
        padding: 10px 20px; /* 增加内边距 */
        display: flex;
        align-items: center;
        transition: all 0.2s ease;
    }
    
    /* 菜单图标 */
    div.usercm ul li a i {
        width: 20px;
        margin-right: 12px;
        text-align: center;
        color: #666;
    }
    
    /* 悬停效果 */
    div.usercm ul li:hover {
        background: rgba(100, 149, 237, 0.2); /* 更强的悬停效果 */
    }
    
    div.usercm ul li a:hover {
        color: #2c7be5;
    }
    
    div.usercm ul li a:hover i {
        color: #2c7be5;
    }
    
    /* 分隔线 */
div.usercm ul li.divider {
    height: 1px;
    background: transparent;
    border-top: 1px dashed #2c7be5;
    margin: 8px 15px;
    opacity: 0.6;
}

div.usercm ul li.divider:hover {
    opacity: 1;
}
    
    /* 禁用状态 */
    a.disabled {
        color: rgba(204, 204, 204, 0.7) !important; /* 半透明禁用状态 */
        cursor: not-allowed;
    }
    
    a.disabled:hover {
        background-color: transparent !important;
    }
    
      /* 透明风格的顶部导航容器 */
    .quick-nav {
        display: flex;
        justify-content: space-around;
        padding: 10px 10px;
        background: transparent; /* 完全透明背景 */
        border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* 极细的分隔线 */
        margin-bottom: 5px;
    }
    
    /* 透明导航按钮基础样式 */
    .quick-nav a {
        padding: 8px 12px;
        border-radius: 6px;
        transition: all 0.25s ease;
        color: rgba(85, 85, 85, 0.9); /* 半透明文字 */
        font-size: 15px;
        background: transparent; /* 透明背景 */
    }
    
    /* 悬停效果 - 优雅的淡入背景 */
    .quick-nav a:hover {
        background: rgba(100, 149, 237, 0.15); /* 轻微蓝色背景 */
        color: #2c7be5; /* 悬停时文字变蓝 */
    }
    
    /* 点击效果 */
    .quick-nav a:active {
        background: rgba(100, 149, 237, 0.25); /* 点击时背景加深 */
        transform: scale(0.98); /* 轻微缩小效果 */
    }
    
    /* 图标动画 */
    .quick-nav a i {
        transition: transform 0.2s ease;
    }
    
    .quick-nav a:hover i {
        transform: scale(1.1); /* 悬停时图标轻微放大 */
    }
    
    /* 按钮边框动画 (可选) */
    .quick-nav a {
        position: relative;
    }
    
    .quick-nav a::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 6px;
        border: 1px solid transparent;
        transition: border-color 0.3s ease;
    }
    
    .quick-nav a:hover::after {
        border-color: rgba(100, 149, 237, 0.3); /* 悬停时显示淡淡边框 */
    }
    
    .copy-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 10001;
    white-space: nowrap;
    }
</style>


<div class="usercm" style="display: none;">
    <!-- 新增的顶部导航图标 -->
    <div class="quick-nav">
        <a href="javascript:history.go(-1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  title="返回上一页"><i class="fa fa-arrow-left"></i></a>
        <a href="javascript:history.go(1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  title="返回下一页"><i class="fa fa-arrow-right"></i></a>
        <a href="javascript:smoothScrollToTop();" rel="external nofollow"  rel="external nofollow"  title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    </div>
    
    <ul>
        <li><a href="https://www.daenyx.com/links"><i class="fa fa-meh-o fa-fw"></i><span>成为邻居</span></a></li>
        <li class="divider"></li>
        <li><a href="javascript:void(0);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  onclick="getSelect();"><i class="fa fa-copy"></i><span>复制内容</span></a></li>
        <li><a href="javascript:window.location.reload();" rel="external nofollow"  rel="external nofollow" ><i class="fa fa-refresh fa-fw"></i><span>刷新页面</span></a></li>
        <li class="divider"></li>
        <li><a href="https://www.daenyx.com/"><i class="fa fa-home"></i><span>返回首页</span></a></li>
        <li><a href="javascript:history.go(1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ><i class="fa fa-arrow-right"></i><span>前进</span></a></li>
        <li><a href="javascript:history.go(-1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ><i class="fa fa-arrow-left"></i><span>后退</span></a></li>
        <li class="divider"></li>
        <li><a href="javascript:void(0);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  onclick="copyPageUrl();"><i class="fa fa-link"></i><span>复制地址</span></a></li>
        <li><a href="javascript:void(0);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  onclick="baiduSearch();"><i class="fa fa-search"></i><span>搜索选中内容</span></a></li>
    </ul>
</div>

<script type="text/javascript">
//顶部
let scrollAnimationId = null;

function smoothScrollToTop() {
    
    if (scrollAnimationId) {
        cancelAnimationFrame(scrollAnimationId);
    }
    
    const startPosition = window.pageYOffset;
    const startTime = performance.now();
    const duration = 800; // 动画持续时间(ms)
    
    const animateScroll = (currentTime) => {
        const elapsed = currentTime - startTime;
        const progress = Math.min(elapsed / duration, 1);
        
        // 使用缓动函数使滚动更自然
        const easeProgress = easeOutCubic(progress);
        
        window.scrollTo(0, startPosition * (1 - easeProgress));
        
        if (progress < 1) {
            scrollAnimationId = requestAnimationFrame(animateScroll);
        } else {
            scrollAnimationId = null;
        }
    };
    
    // 缓动函数 - 平滑减速
    function easeOutCubic(t) {
        return (--t) * t * t + 1;
    }
    
    // 监听用户滚动中断
    const handleUserScroll = () => {
        if (scrollAnimationId) {
            cancelAnimationFrame(scrollAnimationId);
            scrollAnimationId = null;
            window.removeEventListener('wheel', handleUserScroll);
            window.removeEventListener('touchmove', handleUserScroll);
        }
    };
    
    window.addEventListener('wheel', handleUserScroll, { passive: true });
    window.addEventListener('touchmove', handleUserScroll, { passive: true });
    
    scrollAnimationId = requestAnimationFrame(animateScroll);
}

    // 保持原有功能不变
    (function(a) {
        a.extend({
            mouseMoveShow: function(b) {
                var d = 0,
                    c = 0,
                    h = 0,
                    k = 0,
                    e = 0,
                    f = 0;
                    
                var menu = a(b);
                var isMenuShowing = false;
                var isOnImage = false;
                var imageUrl = '';
                
                // 创建提示框元素
                var tooltip = $('<div class="copy-tooltip">复制成功</div>').css({
                    'position': 'absolute',
                    'background': 'rgba(0,0,0,0.7)',
                    'color': 'white',
                    'padding': '5px 10px',
                    'border-radius': '4px',
                    'font-size': '12px',
                    'opacity': '0',
                    'transition': 'opacity 0.3s',
                    'pointer-events': 'none',
                    'z-index': '10001'
                }).appendTo('body');
                
                // 添加CSS过渡效果
                menu.css({
                    'transition': 'left 0.3s ease, top 0.3s ease'
                });
                
                // 检测是否在图片上
                function checkIfOnImage(target) {
                    var imgElement = target.closest('img');
                    if (imgElement) {
                        isOnImage = true;
                        imageUrl = imgElement.src;
                        // 修改"成为邻居"为"复制图片链接"
                        menu.find('a[href="https://www.daenyx.com/links"] i')
                            .removeClass('fa-meh-o')
                            .addClass('fa-link');
                        menu.find('a[href="https://www.daenyx.com/links"] span')
                            .text('复制此图片');
                    } else {
                        isOnImage = false;
                        imageUrl = '';
                        // 恢复"成为邻居"
                        menu.find('a[href="https://www.daenyx.com/links"] i')
                            .removeClass('fa-link')
                            .addClass('fa-meh-o');
                        menu.find('a[href="https://www.daenyx.com/links"] span')
                            .text('成为邻居');
                    }
                }
                
                // 复制图片链接函数
                function copyImageUrl() {
                    if (!isOnImage || !imageUrl) return false;
                    
                    try {
                        var tempInput = document.createElement('input');
                        tempInput.value = imageUrl;
                        document.body.appendChild(tempInput);
                        tempInput.select();
                        var success = document.execCommand('copy');
                        document.body.removeChild(tempInput);
                        
                        if (success) {
                            // 显示提示框
                            var menuPos = menu.offset();
                            tooltip.css({
                                'left': menuPos.left + menu.outerWidth() + 10,
                                'top': menuPos.top
                            }).stop().css('opacity', 1)
                              .delay(1500)
                              .animate({opacity: 0}, 500);
                            return true;
                        } else {
                            throw new Error('复制失败');
                        }
                    } catch (err) {
                        tooltip.text('复制失败').css({
                            'background': 'rgba(255,0,0,0.7)',
                            'left': menu.offset().left + menu.outerWidth() + 10,
                            'top': menu.offset().top
                        }).stop().css('opacity', 1)
                          .delay(1500)
                          .animate({opacity: 0}, 500);
                        return false;
                    }
                }
                
                a(window).mousemove(function(g) {
                    d = a(window).width();
                    c = a(window).height();
                    h = g.clientX;
                    k = g.clientY;
                    e = g.pageX;
                    f = g.pageY;
                    
                    // 调整位置防止超出窗口
                    h + menu.width() >= d && (e = e - menu.width() - 5);
                    k + menu.height() >= c && (f = f - menu.height() - 5);
                    
                    a("html").on({
                        contextmenu: function(c) {
                            if (3 == c.which) {
                                checkIfOnImage(c.target);
                                
                                if (isMenuShowing) {
                                    // 菜单已显示,平滑移动到新位置
                                    menu.css({
                                        left: e,
                                        top: f
                                    });
                                } else {
                                    // 菜单未显示,显示菜单
                                    menu.css({
                                        left: e,
                                        top: f
                                    }).show();
                                    isMenuShowing = true;
                                }
                                c.preventDefault(); // 阻止默认右键菜单
                            }
                        },
                        click: function() {
                            menu.hide();
                            isMenuShowing = false;
                        }
                    });
                });
                
                // 修改"成为邻居"的点击事件
                menu.on('click', 'a[href="https://www.daenyx.com/links"]', function(e) {
                    if (isOnImage && imageUrl) {
                        e.preventDefault();
                        copyImageUrl();
                        menu.hide();
                        isMenuShowing = false;
                    }
                });
                
                // 新增:滚动时隐藏菜单
                a(window).scroll(function() {
                    menu.hide();
                    isMenuShowing = false;
                });
            },
            disabledContextMenu: function() {
                window.oncontextmenu = function() {
                    return !1
                }
            }
        })
    })(jQuery);
 
    function getSelect() {
        "" == (window.getSelection ? window.getSelection() : document.selection.createRange().text) ? layer.msg("请先选择要复制的内容!") : document.execCommand("Copy")
    }
    
    function baiduSearch() {
        var a = window.getSelection ? window.getSelection() : document.selection.createRange().text;
        "" == a ? layer.msg("请先选择要搜索的内容!") : window.open("https://www.daenyx.com/?s=" + a)
    }
    
    $(function() {
        for (var a = navigator.userAgent, b = "Android;iPhone;SymbianOS;Windows Phone;iPad;iPod".split(";"), d = !0, c = 0; c < b.length; c++) if (0 < a.indexOf(b[c])) {
            d = !1;
            break
        }
        d && ($.mouseMoveShow(".usercm"), $.disabledContextMenu())
    });
    
    // 复制当前页面地址函数
    function copyPageUrl() {
    try {
        var tempInput = document.createElement('input');
        tempInput.value = window.location.href;
        document.body.appendChild(tempInput);
        tempInput.select();
        var success = document.execCommand('copy');
        document.body.removeChild(tempInput);
        
        if (success) {
            // 显示提示框
            var menu = $('.usercm');
            var tooltip = $('.copy-tooltip').text('已复制页面地址');
            var menuPos = menu.offset();
            tooltip.css({
                'left': menuPos.left + menu.outerWidth() + 10,
                'top': menuPos.top
            }).stop().css('opacity', 1)
              .delay(1500)
              .animate({opacity: 0}, 500);
            return true;
        } else {
            throw new Error('复制失败');
        }
    } catch (err) {
        $('.copy-tooltip').text('复制失败').css({
            'background': 'rgba(255,0,0,0.7)',
            'left': $('.usercm').offset().left + $('.usercm').outerWidth() + 10,
            'top': $('.usercm').offset().top
        }).stop().css('opacity', 1)
          .delay(1500)
          .animate({opacity: 0}, 500);
        return false;
    }
}
    
    
</script>

其他主题

<style type="text/css">
    /* 基础样式重置 */
    a {
        text-decoration: none;
        color: inherit;
    }
    
    /* 菜单容器 - 修复版 */
div.usercm {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(15px) saturate(180%);
    -webkit-backdrop-filter: blur(15px) saturate(180%);
    font-size: 14px;
    width: 160px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    position: absolute;
    display: none;
    z-index: 10000;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    
    /* 新的描边方案 */
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        0 0 0 0px rgba(44, 123, 229, 0); /* 初始状态 */
}

/* 鼠标悬停时通过box-shadow添加描边 */
div.usercm:hover {
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        0 0 0 2px rgba(44, 123, 229, 0.5);
}
    
    /* 菜单列表 */
    div.usercm ul {
        list-style: none;
        margin: 0;
        padding: 5px 0;
    }
    
    /* 菜单项 */
    div.usercm ul li {
        margin: 0;
        padding: 0;
        transition: all 0.2s ease;
    }
    
    /* 菜单链接 */
    div.usercm ul li a {
        color: #555;
        padding: 10px 20px; /* 增加内边距 */
        display: flex;
        align-items: center;
        transition: all 0.2s ease;
    }
    
    /* 菜单图标 */
    div.usercm ul li a i {
        width: 20px;
        margin-right: 12px;
        text-align: center;
        color: #666;
    }
    
    /* 悬停效果 */
    div.usercm ul li:hover {
        background: rgba(100, 149, 237, 0.2); /* 更强的悬停效果 */
    }
    
    div.usercm ul li a:hover {
        color: #2c7be5;
    }
    
    div.usercm ul li a:hover i {
        color: #2c7be5;
    }
    
    /* 分隔线 */
div.usercm ul li.divider {
    height: 1px;
    background: transparent;
    border-top: 1px dashed #2c7be5;
    margin: 8px 15px;
    opacity: 0.6;
}

div.usercm ul li.divider:hover {
    opacity: 1;
}
    
    /* 禁用状态 */
    a.disabled {
        color: rgba(204, 204, 204, 0.7) !important; /* 半透明禁用状态 */
        cursor: not-allowed;
    }
    
    a.disabled:hover {
        background-color: transparent !important;
    }
    
      /* 透明风格的顶部导航容器 */
    .quick-nav {
        display: flex;
        justify-content: space-around;
        padding: 10px 10px;
        background: transparent; /* 完全透明背景 */
        border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* 极细的分隔线 */
        margin-bottom: 5px;
    }
    
    /* 透明导航按钮基础样式 */
    .quick-nav a {
        padding: 8px 12px;
        border-radius: 6px;
        transition: all 0.25s ease;
        color: rgba(85, 85, 85, 0.9); /* 半透明文字 */
        font-size: 15px;
        background: transparent; /* 透明背景 */
    }
    
    /* 悬停效果 - 优雅的淡入背景 */
    .quick-nav a:hover {
        background: rgba(100, 149, 237, 0.15); /* 轻微蓝色背景 */
        color: #2c7be5; /* 悬停时文字变蓝 */
    }
    
    /* 点击效果 */
    .quick-nav a:active {
        background: rgba(100, 149, 237, 0.25); /* 点击时背景加深 */
        transform: scale(0.98); /* 轻微缩小效果 */
    }
    
    /* 图标动画 */
    .quick-nav a i {
        transition: transform 0.2s ease;
    }
    
    .quick-nav a:hover i {
        transform: scale(1.1); /* 悬停时图标轻微放大 */
    }
    
    /* 按钮边框动画 (可选) */
    .quick-nav a {
        position: relative;
    }
    
    .quick-nav a::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 6px;
        border: 1px solid transparent;
        transition: border-color 0.3s ease;
    }
    
    .quick-nav a:hover::after {
        border-color: rgba(100, 149, 237, 0.3); /* 悬停时显示淡淡边框 */
    }
    
    .copy-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 10001;
    white-space: nowrap;
    }
</style>


<div class="usercm" style="display: none;">
    <!-- 新增的顶部导航图标 -->
    <div class="quick-nav">
        <a href="javascript:history.go(-1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  title="返回上一页"><i class="fa fa-arrow-left"></i></a>
        <a href="javascript:history.go(1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  title="返回下一页"><i class="fa fa-arrow-right"></i></a>
        <a href="javascript:smoothScrollToTop();" rel="external nofollow"  rel="external nofollow"  title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    </div>
    
    <ul>
        <li><a href="https://www.daenyx.com/links"><i class="fa fa-meh-o fa-fw"></i><span>成为邻居</span></a></li>
        <li class="divider"></li>
        <li><a href="javascript:void(0);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  onclick="getSelect();"><i class="fa fa-copy"></i><span>复制内容</span></a></li>
        <li><a href="javascript:window.location.reload();" rel="external nofollow"  rel="external nofollow" ><i class="fa fa-refresh fa-fw"></i><span>刷新页面</span></a></li>
        <li class="divider"></li>
        <li><a href="https://www.daenyx.com/"><i class="fa fa-home"></i><span>返回首页</span></a></li>
        <li><a href="javascript:history.go(1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ><i class="fa fa-arrow-right"></i><span>前进</span></a></li>
        <li><a href="javascript:history.go(-1);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ><i class="fa fa-arrow-left"></i><span>后退</span></a></li>
        <li class="divider"></li>
        <li><a href="javascript:void(0);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  onclick="copyPageUrl();"><i class="fa fa-link"></i><span>复制地址</span></a></li>
        <li><a href="javascript:void(0);" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  onclick="baiduSearch();"><i class="fa fa-search"></i><span>搜索选中内容</span></a></li>
    </ul>
</div>

<script type="text/javascript">
//顶部
let scrollAnimationId = null;

function smoothScrollToTop() {
    
    if (scrollAnimationId) {
        cancelAnimationFrame(scrollAnimationId);
    }
    
    const startPosition = window.pageYOffset;
    const startTime = performance.now();
    const duration = 800; // 动画持续时间(ms)
    
    const animateScroll = (currentTime) => {
        const elapsed = currentTime - startTime;
        const progress = Math.min(elapsed / duration, 1);
        
        // 使用缓动函数使滚动更自然
        const easeProgress = easeOutCubic(progress);
        
        window.scrollTo(0, startPosition * (1 - easeProgress));
        
        if (progress < 1) {
            scrollAnimationId = requestAnimationFrame(animateScroll);
        } else {
            scrollAnimationId = null;
        }
    };
    
    // 缓动函数 - 平滑减速
    function easeOutCubic(t) {
        return (--t) * t * t + 1;
    }
    
    // 监听用户滚动中断
    const handleUserScroll = () => {
        if (scrollAnimationId) {
            cancelAnimationFrame(scrollAnimationId);
            scrollAnimationId = null;
            window.removeEventListener('wheel', handleUserScroll);
            window.removeEventListener('touchmove', handleUserScroll);
        }
    };
    
    window.addEventListener('wheel', handleUserScroll, { passive: true });
    window.addEventListener('touchmove', handleUserScroll, { passive: true });
    
    scrollAnimationId = requestAnimationFrame(animateScroll);
}

    // 保持原有功能不变
    (function(a) {
        a.extend({
            mouseMoveShow: function(b) {
                var d = 0,
                    c = 0,
                    h = 0,
                    k = 0,
                    e = 0,
                    f = 0;
                    
                var menu = a(b);
                var isMenuShowing = false;
                var isOnImage = false;
                var imageUrl = '';
                
                // 创建提示框元素
                var tooltip = $('<div class="copy-tooltip">复制成功</div>').css({
                    'position': 'absolute',
                    'background': 'rgba(0,0,0,0.7)',
                    'color': 'white',
                    'padding': '5px 10px',
                    'border-radius': '4px',
                    'font-size': '12px',
                    'opacity': '0',
                    'transition': 'opacity 0.3s',
                    'pointer-events': 'none',
                    'z-index': '10001'
                }).appendTo('body');
                
                // 添加CSS过渡效果
                menu.css({
                    'transition': 'left 0.3s ease, top 0.3s ease'
                });
                
                // 检测是否在图片上
                function checkIfOnImage(target) {
                    var imgElement = target.closest('img');
                    if (imgElement) {
                        isOnImage = true;
                        imageUrl = imgElement.src;
                        // 修改"成为邻居"为"复制图片链接"
                        menu.find('a[href="https://www.daenyx.com/links"] i')
                            .removeClass('fa-meh-o')
                            .addClass('fa-link');
                        menu.find('a[href="https://www.daenyx.com/links"] span')
                            .text('复制此图片');
                    } else {
                        isOnImage = false;
                        imageUrl = '';
                        // 恢复"成为邻居"
                        menu.find('a[href="https://www.daenyx.com/links"] i')
                            .removeClass('fa-link')
                            .addClass('fa-meh-o');
                        menu.find('a[href="https://www.daenyx.com/links"] span')
                            .text('成为邻居');
                    }
                }
                
                // 复制图片链接函数
                function copyImageUrl() {
                    if (!isOnImage || !imageUrl) return false;
                    
                    try {
                        var tempInput = document.createElement('input');
                        tempInput.value = imageUrl;
                        document.body.appendChild(tempInput);
                        tempInput.select();
                        var success = document.execCommand('copy');
                        document.body.removeChild(tempInput);
                        
                        if (success) {
                            // 显示提示框
                            var menuPos = menu.offset();
                            tooltip.css({
                                'left': menuPos.left + menu.outerWidth() + 10,
                                'top': menuPos.top
                            }).stop().css('opacity', 1)
                              .delay(1500)
                              .animate({opacity: 0}, 500);
                            return true;
                        } else {
                            throw new Error('复制失败');
                        }
                    } catch (err) {
                        tooltip.text('复制失败').css({
                            'background': 'rgba(255,0,0,0.7)',
                            'left': menu.offset().left + menu.outerWidth() + 10,
                            'top': menu.offset().top
                        }).stop().css('opacity', 1)
                          .delay(1500)
                          .animate({opacity: 0}, 500);
                        return false;
                    }
                }
                
                a(window).mousemove(function(g) {
                    d = a(window).width();
                    c = a(window).height();
                    h = g.clientX;
                    k = g.clientY;
                    e = g.pageX;
                    f = g.pageY;
                    
                    // 调整位置防止超出窗口
                    h + menu.width() >= d && (e = e - menu.width() - 5);
                    k + menu.height() >= c && (f = f - menu.height() - 5);
                    
                    a("html").on({
                        contextmenu: function(c) {
                            if (3 == c.which) {
                                checkIfOnImage(c.target);
                                
                                if (isMenuShowing) {
                                    // 菜单已显示,平滑移动到新位置
                                    menu.css({
                                        left: e,
                                        top: f
                                    });
                                } else {
                                    // 菜单未显示,显示菜单
                                    menu.css({
                                        left: e,
                                        top: f
                                    }).show();
                                    isMenuShowing = true;
                                }
                                c.preventDefault(); // 阻止默认右键菜单
                            }
                        },
                        click: function() {
                            menu.hide();
                            isMenuShowing = false;
                        }
                    });
                });
                
                // 修改"成为邻居"的点击事件
                menu.on('click', 'a[href="https://www.daenyx.com/links"]', function(e) {
                    if (isOnImage && imageUrl) {
                        e.preventDefault();
                        copyImageUrl();
                        menu.hide();
                        isMenuShowing = false;
                    }
                });
                
                // 新增:滚动时隐藏菜单
                a(window).scroll(function() {
                    menu.hide();
                    isMenuShowing = false;
                });
            },
            disabledContextMenu: function() {
                window.oncontextmenu = function() {
                    return !1
                }
            }
        })
    })(jQuery);
 
    function getSelect() {
        "" == (window.getSelection ? window.getSelection() : document.selection.createRange().text) ? layer.msg("请先选择要复制的内容!") : document.execCommand("Copy")
    }
    
    function baiduSearch() {
        var a = window.getSelection ? window.getSelection() : document.selection.createRange().text;
        "" == a ? layer.msg("请先选择要搜索的内容!") : window.open("https://www.daenyx.com/?s=" + a)
    }
    
    $(function() {
        for (var a = navigator.userAgent, b = "Android;iPhone;SymbianOS;Windows Phone;iPad;iPod".split(";"), d = !0, c = 0; c < b.length; c++) if (0 < a.indexOf(b[c])) {
            d = !1;
            break
        }
        d && ($.mouseMoveShow(".usercm"), $.disabledContextMenu())
    });
    
    // 复制当前页面地址函数
    function copyPageUrl() {
    try {
        var tempInput = document.createElement('input');
        tempInput.value = window.location.href;
        document.body.appendChild(tempInput);
        tempInput.select();
        var success = document.execCommand('copy');
        document.body.removeChild(tempInput);
        
        if (success) {
            // 显示提示框
            var menu = $('.usercm');
            var tooltip = $('.copy-tooltip').text('已复制页面地址');
            var menuPos = menu.offset();
            tooltip.css({
                'left': menuPos.left + menu.outerWidth() + 10,
                'top': menuPos.top
            }).stop().css('opacity', 1)
              .delay(1500)
              .animate({opacity: 0}, 500);
            return true;
        } else {
            throw new Error('复制失败');
        }
    } catch (err) {
        $('.copy-tooltip').text('复制失败').css({
            'background': 'rgba(255,0,0,0.7)',
            'left': $('.usercm').offset().left + $('.usercm').outerWidth() + 10,
            'top': $('.usercm').offset().top
        }).stop().css('opacity', 1)
          .delay(1500)
          .animate({opacity: 0}, 500);
        return false;
    }
}
    
    
</script>
评论区
头像