wordpress自定义右键菜单功能

  • A+
所属分类:建博笔记
摘 要

自定义wordpress右键菜单可以进一步扩展博客功能,丰富博客样式,提升用户体验。同时,在一定程度上也可以防止博客被扒。

一、效果预览

 

二、使用前提

使用该功能,需要确保你的主题已经存在/引入jQuery文件。若主题没有该文件,请将代码

<script type="text/javascript" src="//apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>

添加至主题根目录下【header.php】文件的<head></head>标签内。

 

三、操作步骤

直接复制下面的代码到主题根目录下【footer.php】文件的</body>标签前即可。

<style type="text/css">
	a {text-decoration: none;}
	div.usercm{background-repeat:no-repeat;background-position:center center;background-size:cover;background-color:#fff;font-size:13px!important;width:130px;-moz-box-shadow:1px 1px 3px rgba(0,0,0,.3);box-shadow:1px 1px 3px rgba(0,0,0,.3);position:absolute;display:none;z-index:10000;opacity:0.9;}
	div.usercm ul{list-style-type:none;list-style-position:outside;margin:0px;padding:0px;display:block;}
	div.usercm ul li{margin:0px;padding:0px;line-height:35px;border-bottom:1px solid #ccc;}
	div.usercm ul li a{color:#666;padding:0 15px;display:block;}
	div.usercm ul li a:hover{color:#fff;background:rgba(170,222,18,0.88);}
	div.usercm ul li a i{margin-right:10px;}
	a.disabled{color:#c8c8c8!important;cursor:not-allowed;}
	a.disabled:hover{background-color:rgba(255,11,11,0)!important;}
	div.usercm{background:#fff !important;}
</style>

<div class="usercm">
	<ul>
		<li>
			<a href="javascript:void(0);" onclick="getSelect();"><i class="fa fa-clipboard fa-fw"></i><span>复制文字</span></a>
		</li>
	    <li>
	    	<a href="javascript:window.location.reload();"><i class="fa fa-refresh fa-fw"></i><span>刷新页面</span></a>
	    </li>
	    <li>
	    	<a href="javascript:history.go(1);"><i class="fa fa-arrow-right fa-fw"></i><span>前进一页</span></a>
	    </li>
	    <li>
	    	<a href="javascript:history.go(-1);"><i class="fa fa-arrow-left fa-fw"></i><span>后退一页</span></a>
	    </li>
	    <li>
	    	<a target="_blank" href="javascript:void(0);"  onclick="baiduSearch();"><i class="fa fa-paw fa-fw"></i><span>百度搜索</span></a>
	    </li>
	   	<li>
	   		<a target="_blank" rel="external nofollow" target="_blank" href="https://isdola.com/wp-content/themes/begin/go.php?url=aHR0cHM6Ly93d3cuYmFpZHUuY29tL3M/aWU9dXRmLTgmYW1wO2Y9OCZhbXA7cnN2X2JwPTEmYW1wO3Jzdl9pZHg9MSZhbXA7dG49YmFpZHUmYW1wO3dkPSVFNCVCRCU5NSVFNSU4NSU4OCVFNyU5NCU5RiZhbXA7b3E9JTI1RTQlMjVCRCUyNTk1JTI1RTUlMjU4NSUyNTg4JTI1RTclMjU5NCUyNTlGJmFtcDtyc3ZfcHE9ODI4YmY5NmMwMDA0OGRlMiZhbXA7cnN2X3Q9Mzg0YU52dDQlMkZCZTRnVGtmbHZ6aElLUmlSNUdFRnlleTJYejlsc1o1OUxyYnIzZEFNckJIYU9HTmZYMCZhbXA7cnFsYW5nPWNuJmFtcDtyc3ZfZW50ZXI9MA==" ><i class="fa fa-search"></i><span>百度优化</span></a>
	   	</li>
	   	<li>
	   		<a target="_blank" rel="external nofollow" target="_blank" href="https://isdola.com/wp-content/themes/begin/go.php?url=aHR0cHM6Ly9hdXRob3IuYmFpZHUuY29tL2hvbWUvMTYxMzc0OTk1MzU2MTIyMg=="><i class="fa fa-paw" aria-hidden="true"></i><span>关注熊掌号</span></a>
	   </li>
	</ul>
</div>   
 
<script type="text/javascript">
(function(a) {
    a.extend({
        mouseMoveShow: function(b) {
            var d = 0,
                c = 0,
                h = 0,
                k = 0,
                e = 0,
                f = 0;
            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 + a(b).width() >= d && (e = e - a(b).width() - 5);
                k + a(b).height() >= c && (f = f - a(b).height() - 5);
                a("html").on({
                    contextmenu: function(c) {
                        3 == c.which && a(b).css({
                            left: e,
                            top: f
                        }).show()
                    },
                    click: function() {
                        a(b).hide()
                    }
                })
            })
        },
        disabledContextMenu: function() {
            window.oncontextmenu = function() {
                return !1
            }
        }
    })
})(jQuery);
 
function getSelect() {
    "" == (window.getSelection ? window.getSelection() : document.selection.createRange().text) ? alert("啊噢...你没还没选择文字呢!") : document.execCommand("Copy")
}

function baiduSearch() {
    var a = window.getSelection ? window.getSelection() : document.selection.createRange().text;
    "" == a ? alert("啊噢...你没还没选择文字呢!") : window.open("https://www.baidu.com/s?wd=" + a)
}

function googleSearch() {
    var a = window.getSelection ? window.getSelection() : document.selection.createRange().text;
    "" == a ? alert("啊噢...你没还没选择文字呢!") : window.open("https://www.google.com/search?q=" + a)
}

function localSearch() {
    var a = window.getSelection ? window.getSelection() : document.selection.createRange().text;
    "" == a ? alert("啊噢...你没还没选择文字呢!") : window.open("search.php?q=" + 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())
});
</script>

 

四、代码解释

  • 上面的代码主要分为三大部分,分别是:CSS样式、HTML代码和JS代码。这里,我是为了方便文章编辑,将这三个部分放在一起,童鞋们也可以将CSS样式和JS代码分别放至主题对应的CSS和JS文件中。
  • 代码中,至少需要修改的是JS代码部分的百度熊掌号ID号,其余部分可不做调整。当然,如果你想定制自己的右键菜单,也可以根据上面的结构做出相应的修改。
若文章图片、下载链接、网盘密码等信息出错,请留言反馈,博主将第一时间更新!如果喜欢,请打赏支持本站,谢谢大家!
isdola

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: