SCBOY乌龟雪插件

为论坛添加很棒的乌龟雪。

目前為 2021-12-10 提交的版本,檢視 最新版本

// ==UserScript==
// @license      MIT
// @name         SCBOY乌龟雪插件
// @namespace    https://gitee.com/rustyhare
// @version      1.3
// @description  为论坛添加很棒的乌龟雪。
// @author       RustyHare
// @match        *://www.scboy.cc/*
// @grant        none
// ==/UserScript==


window.SnowRand=function(count){
    for(var i=0;i<count;i++){
        var obj=new Object();
        obj.domElement=document.createElement("div");
        obj.domElement.id="snow";
        obj.domElement.innerHTML="🐢";
        obj.domElement.style.position="fixed";
        obj.domElement.style.opacity=0.3;
        obj.domElement.style.color="snow";
        obj.domElement.style.fontSize=(Math.random()*200).toString()+"%";
        obj.domElement.style.top=Math.random()*document.body.scrollHeight.toString()+"px";
        obj.domElement.style.left=Math.random()*document.body.scrollWidth.toString()+"px";
        document.body.appendChild(obj.domElement);
        delete(obj);
    }
}
window.SnowBorder=function(count){
    for(var i=0;i<count;i++){
        var obj=new Object();
        obj.domElement=document.createElement("div");
        obj.domElement.id="snow";
        obj.domElement.innerHTML="🐢";
        obj.domElement.style.position="fixed";
        obj.domElement.style.opacity=0.3;
        obj.domElement.style.color="snow";
        obj.domElement.style.fontSize=(Math.random()*200).toString()+"%";
        var place=Math.random();
        if(place<0.4){//顶端
            obj.domElement.style.top=(Math.random()/8*window.screen.availHeight-5).toString()+"px";
            obj.domElement.style.left=(Math.random()*(window.screen.availWidth+10)-5).toString()+"px";
        }else if(place>0.4 && place<0.7){
            obj.domElement.style.top=(Math.random()*(window.screen.availHeight+10)-5).toString()+"px";
            obj.domElement.style.left=(Math.random()/8*window.screen.availWidth-5).toString()+"px";
        }else{
            obj.domElement.style.top=(Math.random()*(window.screen.availHeight+10)-5).toString()+"px";
            obj.domElement.style.left=(window.screen.availWidth-Math.random()/8*window.screen.availWidth+5).toString()+"px";
        }
        document.body.appendChild(obj.domElement);
        delete(obj);
    }
}

window.snow=function(num){//入口点,main函数
    window.SnowRand(num);
    window.wind=window.Wind()//把变量绑在window上可以防止其被函数卸载
    var int0=window.setInterval("Refresh(window.wind.velX/60,window.wind.velY/60)",1000/144);
    var int1=window.setInterval("window.TurtleBurstRefresh()",1000/144);
    document.getElementById("body").addEventListener("click",function(e){window.TurtleBurst(e.y,e.x,10);console.log(e.x);console.log(e.y)})

}


window.Wind=function(){//风向和风速的变化似乎是个马尔科夫链?
    var wind=new Object();
    wind.velX=0;
    wind.velY=9.8;
    //两个速度
    wind.windVelX=0;
    wind.windVelY=9.8;
    wind.accuCF=0;//该因子的增长速度是每次刷新+1(每秒15次刷新),上限为10000,风向每次变化的几率为accuCF/10000,
    wind.windChange=function(){
        if(wind.accuCF>Math.random()*10000){//抽中,使其在一个范围内回归
            wind.windVelX=(Math.random()*40)-20;
            wind.windVelY=5+(Math.random()*6);
            wind.accuCF=0;
            console.log("RustyHare::T_WindChangeTriggered");
        }else{//未抽中
            wind.accuCF+=1;
        }
        wind.velX+=(wind.windVelX-wind.velX)/150;
        wind.velY+=(wind.windVelY-wind.velY)/150;
    }
    wind.interval=setInterval("wind.windChange()",1000/15);
    return wind;
}

window.Refresh=function(x,y){
    $("div#snow").each(function(index,element){
        var top=parseFloat(this.style.top.slice(0,-2))+y*(1+parseFloat(this.style.fontSize.slice(0,-1))*0.003);
        var left=parseFloat(this.style.left.slice(0,-2))+x*(1+parseFloat(this.style.fontSize.slice(0,-1))*0.006);
        if((top<window.screen.availHeight+10)&&(left<window.screen.availWidth+10)&&(top>-10)&&(left>-10)){
            $(this).css("top",top.toString()+"px");
            $(this).css("left",left.toString()+"px");
        }else{
            $(this).remove();
            window.SnowBorder(1);
        }
    })
    return "window.Refresh("+x.toString()+","+y.toString()+")";
}

//开始编写乌龟爆发的效果,使用同样的乌龟图标🐢
//2021.12.10
//罗斯贝尔野兔
window.TurtleBurst=function(x,y,quantity){
    console.log("RustyHare::T_NavBarClickTriggered")
    for(var i=0;i<quantity;i++){
        var obj=new Object();
        obj.domElement=document.createElement("div");
        obj.domElement.id="snowRotate";
        var whatIsThis=Math.random();
        if(whatIsThis<0.4){
        obj.domElement.innerHTML="🐢";
        }else if(whatIsThis>=0.4 && whatIsThis<0.6){
            obj.domElement.innerHTML="🐔";
        }else if(whatIsThis>=0.6 && whatIsThis<0.8){
            obj.domElement.innerHTML="🎉";
        }else{
            obj.domElement.innerHTML="🦌";
        }
        //🐔🎉🐢🦌
        obj.domElement.style.position="fixed";
        obj.domElement.style.opacity=0.6;
        obj.domElement.style.fontSize=(Math.random()*200).toString()+"%";
        //位置:顶端居中
        obj.domElement.style.top=x.toString()+"px";
        obj.domElement.style.left=+y.toString()+"px";
        //(document.body.scrollWidth/2).toString()
        //旋转角度随机化
        obj.domElement.style.transform="rotate("+(Math.random()*180-90).toString()+"deg)";
        //记录其弧线属性
        var randSpdX=Math.random()*10-5;
        var randSpdY=Math.random()*14.7-9.8;
        //(Math.random()*5-10).toString().slice(0,5)
        obj.domElement.classList.add("V" + (randSpdX>0?"+":"") + randSpdX.toString().slice(0,5));
        obj.domElement.classList.add("V" + (randSpdY>0?"+":"") + randSpdY.toString().slice(0,5));
        //此处可能有些费解:我使用class属性来存储这个乌龟的x分速度和y分速度,其中x分速度一成不变,y分速度用于模拟抛物线。
        //总共需要两个class,第一个Va.bbb存储X速度,第二个Va.bbb存储Y速度
        //例:V1.332 V8.581
        document.body.appendChild(obj.domElement);
    }
}
window.TurtleBurstRefresh=function(){
    $("div#snowRotate").each(function(index,element){
        var top=parseFloat(this.style.top.slice(0,-2));
        var left=parseFloat(this.style.left.slice(0,-2));
        if((top<window.screen.availHeight+10)&&(left<window.screen.availWidth+10)&&(left>-10)){
            try{
                $(this).css("top",(top+parseFloat($(this)[0].classList.item(1).toString().slice(1))*0.03).toString()+"px");
            }catch(e){
                $(this)[0].classList.add("V+0.000");
            }
            $(this).css("left",(left+parseFloat($(this)[0].classList.item(0).toString().slice(1))*0.2).toString()+"px");
            //上面更改当前位置
            var currentClass=$(this)[0].classList.item(1).toString();
            $(this)[0].classList.remove(currentClass);
            $(this)[0].classList.add("V"+((parseFloat(currentClass.slice(1))>0?"+":"")+((parseFloat(currentClass.slice(1))+0.14).toString())));
            //上面这两行更改Y速度。不支持连锁调用啊。
            $(this).css("transform","rotate("+(parseFloat(this.style.transform.slice(7,-3))+2.0).toFixed(3).toString()+"deg)");
        }else{
            $(this).remove();
        }
    })
    return "window.TurtleBurstRefresh()";
}


//乌龟爆发效果结束


$(".actGotop").attr("onclick", "console.log('RustyHare::T_201')")
$("#nav-checkin").attr("onclick","window.TurtleBurst(80,document.body.scrollWidth/2,40)")
$("#xs_checkin_btn").attr("onclick","window.TurtleBurst(80,document.body.scrollWidth/2,40)")
$(".p-t-sm").attr("onclick","window.TurtleBurst(80,document.body.scrollWidth/2,40)")
//301和302都可以被触发
window.snow(100)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址