黄衣哥

文章 分类 评论
40 4 19

站点介绍

分享各种thing~

网站常用JS代码

黄衣哥 2021-11-29 41 0条评论 知识 代码JS前端

首页 / 正文
本站换新域名啦 目前老域名:huangyige.cf 新域名:blog.huangyige.xyz 都可以访问啦!

发布于2022-01-01

前言

我为大家准备了几个网站常用的JS代码,大部分是禁止something~

禁止F12

`

<script>
document.onkeydown = function () {
    if (window.event && window.event.keyCode == 123) {
        alert("F12被禁用");
        event.keyCode = 0;
        event.returnValue = false;
    }
    if (window.event && window.event.keyCode == 13) {
        window.event.keyCode = 505;
    }
    if (window.event && window.event.keyCode == 8) {
        alert(str + "\n请使用Del键进行字符的删除操作!");
        window.event.returnValue = false;
    }
}
</script>

`

禁止复制


<script>
document.oncopy = function (event) {
    if (window.event) {
        event = window.event;
    }
    try {
        var the = event.srcElement;
        if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
            return false;
        }
        return true;
    } catch (e) {
        return false;
    }
}
</script>

禁止剪切

<script>
document.oncut = function (event) {
    if (window.event) {
        event = window.event;
    }
    try {
        var the = event.srcElement;
        if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
            return false;
        }
        return true;
    } catch (e) {
        return false;
    }
}
</scrtpt>

禁止选中


<script>
document.onselectstart = function (event) {
    if (window.event) {
        event = window.event;
    }
    try {
        var the = event.srcElement;
        if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
            return false;
        }
        return true;
    } catch (e) {
        return false;
    }
}
</script>

禁止右键

<script>
document.oncontextmenu = function (event) {
    if (window.event) {
        event = window.event;
    }
    try {
        var the = event.srcElement;
        if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
            return false;
        }
        return true;
    } catch (e) {
        return false;
    }
}
</script>

禁止粘贴

<script>
document.onpaste = function (event) {
    if (window.event) {
        event = window.event;
    }
    try {
        var the = event.srcElement;
        if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
            return false;
        }
        return true;
    } catch (e) {
        return false;
    }
}
</script>

鼠标点击冒出爱心

!function(e, t, a) {
    //对当前页面由用户点击产生的心进行操作,若产生的心的透明度小于零了,则移除该元素,若不小于零,则该心继续向上移动,并慢慢放大
   function r() {
       for(var e = 0; e < n.length; e++) 
           n[e].alpha <= 0 ? (t.body.removeChild(n[e].el), n.splice(e, 1)) : (n[e].y--, n[e].scale += .004, 
           n[e].alpha -= .013, 
           n[e].el.style.cssText = "left:" + n[e].x + "px;top:" + n[e].y + "px;opacity:" + n[e].alpha + ";transform:scale(" + n[e].scale + "," + n[e].scale + ") rotate(45deg);background:" + n[e].color + ";z-index:99999");
       requestAnimationFrame(r)
   }
   //存放页面心的数组
   var n = [];
   //对于不同浏览器做兼容处理
   e.requestAnimationFrame =
       e.requestAnimationFrame || 
       e.webkitRequestAnimationFrame || 
       e.mozRequestAnimationFrame || 
       e.oRequestAnimationFrame || 
       e.msRequestAnimationFrame || 
       function(e) {
           setTimeout(e, 1e3 / 60)
   },
   //创建style标签并写入css样式
   function(e) {
       var a = t.createElement("style");
       a.type = "text/css";
       try {
           a.appendChild(t.createTextNode(e))
       } catch(t) {
           a.styleSheet.cssText = e
       }
       t.getElementsByTagName("head")[0].appendChild(a)
   }(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),
   //将用户点击操作产生的心push进n数组之内
   function() {
       var a = "function" == typeof e.onclick && e.onclick;
       e.onclick = function(e) {
           a && a(),
           function(e) {
               var a = t.createElement("div");
               a.className = "heart", 
               n.push({
                   el: a,
                   x: e.clientX - 5,
                   y: e.clientY - 5,
                   scale: 1,
                   alpha: 1,
                   color: "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
                   }), 
                   t.body.appendChild(a)
               }(e)
           }
       }(), 
   r()
}(window, document);

鼠标点击弹出关键词

var a_idx = 0;
jQuery(document).ready(function($) {
    $("body").click(function(e) {
        var a = new Array("萌萌哒","帅气","阳光","八块腹肌","治愈系","无敌暖男","运动狂魔","软件开发","酷爱外语");
        var $i = $("<span/>").text(a[a_idx]);
//                    a_idx = (a_idx + 1) % a.length;
                    a_idx = Math.round(Math.random()*a.length);
        var x = e.pageX,
                y = e.pageY;
        $i.css({
            "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
            "top": y - 20,
            "left": x,
            "position": "absolute",
            "color":`rgba(${Math.random()*255},${Math.random()*255},${Math.random()*255},1)`
        });
        $("body").append($i);
        $i.animate({
            "top": y - 180,
            "opacity": 0
         },1500,function() {
             $i.remove();
         });
        });
});

网站统计人数代码(很简单,每刷新一次就会+1)

<!--
var caution = false
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
}
var now = new Date()
fixDate(now)
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
var visits = getCookie("counter")
if (!visits)
visits = 1
else
visits = parseInt(visits) + 1
setCookie("counter", visits, now)
document.write("您是第" + visits + "访客")

评论(0)

热门文章

最新评论

  • 黄衣哥

    @常瑞 谢谢,常来玩哦

  • 常瑞

    不错!

  • 黄衣哥

    @一直默默关注你 谢谢[[微笑]] 常来玩哦!

  • 黄衣哥

    @土拨许 可能是我写得太拉了[[猪头]][汗]

  • 黄衣哥

    @默默关注你的人 谢谢~[[微笑]] 常来玩哦

  • 默默关注你的人

    很有帮助哦

  • 土拨许

    学渣表示看不懂...

  • 一直默默关注你

    挺实用

  • 黄衣哥

    @芬达 收到,已更换![[呲牙]]

  • 芬达

    您好,芬达博客域名更换为 https://yu8.top 已为贵站添加博客,望更新一下链接

日历

2022年01月

      1
2345678
9101112131415
16171819202122
23242526272829
3031     

文章目录

推荐关键字: 洛谷 题解 c++ 代码 前端 JS CSS scratch 极域 HTML

站点公告
本站换新域名啦 目前老域名:huangyige.cf 新域名:blog.huangyige.xyz 都可以访问啦!
点击小铃铛关闭
配色方案