微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

注入脚本扩展错误 javascipt

如何解决注入脚本扩展错误 javascipt

你好,我正在尝试为一个赌博网站做一个扩展,它是一个轮盘赌 autobetter。 我已经完成了逻辑(js 代码)并且它工作正常。但是当我加载扩展时我遇到了一些问题我收到了一些我不明白的错误。并且最重要的一段代码由于某种原因没有运行 有时我不显示用户界面的某些部分。有时对齐会搞砸。它是如此不一致。这些是我收到的错误的一些屏幕截图

这个代码我在由于某种原因没有执行的部分上面写了一些文本(我在js注入器扩展中复制粘贴了相同的部分并且它工作正常所以逻辑是正确的)在这部分我使用一个自我声明函数与 setinterval

const Box = document.createElement("div");
const f =document.getElementsByClassName("roulette-header")[0]
f.appendChild(Box);
Box.id = "ExtensionBox";
document.getElementById("ExtensionBox").style.display = "flex"
document.getElementById("ExtensionBox").style.marginTop = "5%"
document.getElementById("ExtensionBox").style.background= "#1c1c22";
document.getElementById("ExtensionBox").style.height = "180px"
document.getElementById("ExtensionBox").style.width = "400%"
document.getElementById("ExtensionBox").style.borderRadius = "5px"

const BaseBet = document.createElement("h1")
BaseBet.innerHTML = "Base Bet"
BaseBet.style.color = "white"
BaseBet.style.position = "relative"
BaseBet.style.left =  "40%"
BaseBet.style.fontSize = "2rem"
BaseBet.style.marginTop = "10px"
Box.appendChild(BaseBet)


const BasBetInput = document.createElement("input")
BasBetInput.type = "number"
BasBetInput.id = "BasBetInput"
BasBetInput.style.position = "relative"
BasBetInput.style.left =  "32%"
BasBetInput.style.fontSize = "1.5rem"
BasBetInput.style.width = "25%"
BasBetInput.style.background = "#2d2d35"
BasBetInput.style.marginTop = "42px"
BasBetInput.placeholder = " 10 recomended "
BasBetInput.style.borderRadius = "5px"
Box.appendChild(BasBetInput)
const BaseBet2 = document.createElement("h1")
BaseBet2.innerHTML = "Target Balance"
BaseBet2.style.color = "white"
BaseBet2.style.position = "relative"
BaseBet2.style.left =  "7%"
BaseBet2.style.top = "40%" 
BaseBet2.style.fontSize = "2rem"
Box.appendChild(BaseBet2)
const BasBetInput2 = document.createElement("input")
BasBetInput2.type = "number"
BasBetInput2.id = "BasBetInput2"
BasBetInput2.style.position = "relative"
BasBetInput2.style.left =  "-6%"
BasBetInput2.style.fontSize = "1.5rem"
BasBetInput2.style.width = "25%"
BasBetInput2.style.background = "#2d2d35"
BasBetInput2.style.marginTop = "130px"
BasBetInput2.placeholder = " once reached bot will stop "
BasBetInput2.style.borderRadius = "5px"
Box.appendChild(BasBetInput2)
const RedBox = document.createElement("div");
f.appendChild(RedBox)
RedBox.id = "redBox"
document.getElementById("redBox").style.display = "flex"
document.getElementById("redBox").style.marginTop = "4%"
document.getElementById("redBox").style.background= "#c8354e";
document.getElementById("redBox").style.height = "180px"
document.getElementById("redBox").style.width = "110%"
document.getElementById("redBox").style.borderRadius = "5px"
RedBox.style.position = "relative"
RedBox.style.right = "71%"
RedBox.style.whiteSpace = "Nowrap"
const balanc = document.createElement("h1")
balanc.innerHTML = "Your Starting balance :"+document.getElementById('balance').innerHTML
RedBox.appendChild(balanc)
balanc.id = "balanc"
document.getElementById("balanc").style.color = "white"
document.getElementById("balanc").style.fontSize = "2.5rem"
document.getElementById("balanc").style.marginLeft = "10px"
const message = document.createElement("h2")  
message.style.color = "white"
message.innerHTML = " Your can Survive :"
message.style.fontSize = "2.5rem"
message.style.position = "relative"
message.style.top = "75px"
message.style.right = "300px"
message.style.textAlign = "center"
message.id = "message"
RedBox.appendChild(message)
document.getElementById("message").style.fontWeight = "300"
clearbutton = document.createElement("button")
clearbutton.type = "reset"
clearbutton.innerHTML = "reset" 
clearbutton.style.height = "50px"
clearbutton.style.width = "10%"
clearbutton.style.color = "white"
clearbutton.style.borderRadius = "5px"
clearbutton.style.fontSize = "1.5rem"
clearbutton.style.background = "#2d2d35"
clearbutton.style.borderColor = "#2d2d35"
clearbutton.style.margin="10px"
clearbutton.style.position = "relative"
clearbutton.style.top="55px"
clearbutton.style.left="16.6%"
Box.appendChild(clearbutton)
clearbutton1 = document.createElement("button")
clearbutton1.style.BoxShadow = "none"
clearbutton1 = document.createElement("button")
clearbutton1.innerHTML = "indurance" 
clearbutton1.style.height = "50px"
clearbutton1.style.width = "10%"
clearbutton1.style.color = "white"
clearbutton1.style.borderRadius = "5px"
clearbutton1.style.fontSize = "1.5rem"
clearbutton1.style.background = "#2d2d35"
clearbutton1.style.borderColor = "#2d2d35"
clearbutton1.style.margin="-30px"
clearbutton1.style.position = "relative"
clearbutton1.style.top="37px"
clearbutton1.style.left="102px"
Box.appendChild(clearbutton1)
StartButton = document.createElement("button")
StartButton.id="sb"
Box.appendChild(StartButton)
document.getElementById("sb").innerHTML = "Start Bot"
document.getElementById("sb").style.background = "#c8354e"
document.getElementById("sb").style.width = "10%"
document.getElementById("sb").style.height = "50px"
document.getElementById("sb").style.color = "white"
StartButton.style.margin="10px"
StartButton.style.marginTop="122px"
document.getElementById("sb").style.borderColor = "#c8354e"
document.getElementById("sb").style.borderRadius = "5px"
document.getElementById("sb").style.fontSize = "1.5rem"
clearbutton.addEventListener("click",function(){
    document.getElementById("BasBetInput2").value = "";
    document.getElementById("BasBetInput").value = "";
    
})
losses = 1;
clearbutton1.addEventListener("click",function(){
    balance= document.getElementById('balance').innerHTML;
    balance = parseInt(balance.replace(",",""));
    if (balance > 120){
        
        bt=document.getElementById("BasBetInput").value;
        losses = 1;
        do{
        bt = bt*2
        balance = balance-bt
        losses = losses+1

        }while (!(bt > balance))
        document.getElementById("message").innerHTML = " Your can Survive :"+" "+losses +" "+ "Losses"
        
    } 
    
})
document.getElementById("sb").addEventListener("click",function(){
        
    balance= document.getElementById('balance').innerHTML;
    balance = parseInt(balance.replace(",""));
    bt=document.getElementById("BasBetInput").value;
    TargetBalance=document.getElementById("BasBetInput2").value;
    document.getElementById('bet-input-r').value = bt ;
    bc="black"; 
    if (bc == "red" ){
        document.getElementById('roulette-btn-red').click();
    }else{
        document.getElementById('roulette-btn-black').click();
    }
    setInterval(function(){
        // code here does not excute for some reason
        balance= document.getElementById('balance').innerHTML;
        balance = parseInt(balance.replace(","")); 
        if (TargetBalance>balance){
            l=((document.getElementsByClassName("roulette-past-queue--prevIoUs-rolls-container horizontal-scroll")[0].innerText).length);
            f = document.getElementsByClassName("roulette-past-queue--prevIoUs-rolls-container horizontal-scroll")[0].innerText;
            number = f.substring(f.lastIndexOf("\n"),l);
            number = parseInt(number.replace(" ",""));
    
            
            if (number >= 1 && number <= 7){
                LastResult = "red";
            };
            if (number >= 8 && number <= 14){
                LastResult = "black";
            };
            if (number == 0){
                LastResult = "green";
            };
            
            if(LastResult == bc){
                if (bc == "red"){
                    document.getElementById('bet-input-r').value = bt ;
                    document.getElementById('roulette-btn-red').click();
                }else{
                    document.getElementById('bet-input-r').value = bt ;
                    document.getElementById('roulette-btn-black').click();
                };
            
            
            
                
            };
            
            
            if(LastResult !==  bc){
                if (bc == "red"){
                    document.getElementById('bet-btn-double-r').click();
                    document.getElementById('roulette-btn-black').click();
                    bc = "black"
                    
                }else{
                    document.getElementById('bet-btn-double-r').click();
                    document.getElementById('roulette-btn-red').click();
                    bc = "red"
                    
                };
                
        }
        }
        
    },32000 );

})

清单文件

{
    "name": "CSGO500 Roullete Autobetter","description": "This is a csgo500 roullete strategy autobetter","version": "1.0","manifest_version": 2,"content_scripts": [
        {
            "js": ["foreground.js"],"matches": ["https://csgo500.com/roulette"]
        }
    ]
    

    

}
    

解决方法

通过将 const 变量更改为 let 解决了每个问题。现在它工作正常

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。