微学堂button7.1

// ==UserScript==
// @name button7.1 - wechess.cn
// @namespace Violentmonkey Scripts
// @match https://ke.wechess.cn/app/index.php
// @grant none
// @version 1.0
// @author -
// @description 2023/8/7 11:14:43 人机下棋、着200分(选中步骤分自动每步分析-通过局面切换),
// 5.0提示开局库,棋谱截断保存
// 6.0下载打印版棋谱(复盘界面) 6.5 黑白版
// 7.0 自动下棋
// ==/UserScript==

var stage = null;

function downloadFile(data, fileName) {
const blob = new Blob([data]);
const url = URL.createObjectURL(blob);

const link = document.createElement('a');
link.href = url;
link.download = fileName;

document.body.appendChild(link);
link.click();

document.body.removeChild(link);
URL.revokeObjectURL(url);
}

function formatter(score) {//ai局面评分分数转换

var temp = 0;
var temp2 = '';
var temp_val = score;
if (temp_val > 0) {
    temp = Math.round(10 * Math.pow(5, temp_val / 10000));
    if (temp > 0 && temp <= 100) {
        temp2 = '红略优';
    } else if (temp > 100 && temp <= 300) {
        temp2 = '红优';
    } else if (temp > 300 && temp <= 600) {
        temp2 = '红大优';
    } else if (temp > 600 && temp <= 29000) {
        temp2 = '红胜势';
    } else if (temp > 29000 && temp <= 29999) {
        temp2 = '红杀棋';
    } else {
        temp2 = '红胜';
    }
} else if (temp_val == 0) {
    temp = 0;
    temp2 = '均势';
} else {
    temp = Math.round(10 * Math.pow(5, (-temp_val) / 10000));
    if (temp > 0 && temp <= 100) {
        temp2 = '黑略优';
    } else if (temp > 100 && temp <= 300) {
        temp2 = '黑优';
    } else if (temp > 300 && temp <= 600) {
        temp2 = '黑大优';
    } else if (temp > 600 && temp <= 29000) {
        temp2 = '黑胜势';
    } else if (temp > 29000 && temp <= 29999) {
        temp2 = '黑杀棋';
    } else {
        temp2 = '黑胜';
    }
    temp = -temp;
}
//return  temp2 + '(' + temp + ')';

return temp;
}

function fetchAi(){//获取ai分析结果

  var a = window.game.scene.scenes[0];
  truemode = a.mode;
  a.mode=2;
  window.chessid = "";
  window.analyseMachine={
      "0": {
          "level": "17",
          "caltime": "0",
          "kaiju": "3|5,5|0"
      },
      "1": {
          "level": "-1",
          "caltime": "0.5",
          "kaiju": "1|5,5|3"
      }
  };
  window.onAnalyseListener();
  //console.log("dddddddd",vue.middleList);
  a.sendGetData(1);
  a.mode=truemode;

}
//获取关卡
function getStage(selectBooks,pStageName,isNextStage){
var a = window.game.scene.scenes[0];
if((a.mode == 0 ) && uid >0){

    var xhr = new XMLHttpRequest();
    var url = "https://login.gpt10086.com/langkongTool/xq/xqnextstage.php";
    var params = "uid="+uid+"&bid="+selectBooks.value+"&isnext="+isNextStage;
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            var responseText = xhr.responseText.trim();
            // 处理获取到的响应内容
            console.log(responseText);
            stage = responseText.split("zjszjs");
            if(stage.length<6){
              pStageName.textContent = stage[0];
              alert(stage[0]);
            }else{
              pStageName.textContent = stage[5]+": "+stage[1];
              a.setBoard(stage[2]);
            }

        }
    };
    xhr.send(params);

}

}

// 创建局面下拉框元素
function makeSelectControl( left,top,optArr,func){

var selectElement = document.createElement("select");

selectElement.style.position = "absolute";
selectElement.style.left = left+"px";
selectElement.style.top = top+"px";
selectElement.style.fontSize = "12px";
selectElement.style.height = "25px";
selectElement.addEventListener("change", func) //监听按钮点击事件
// 创建局面下拉框选项
for (var i = 0; i < optArr.length; i++) {
  var optioni =  document.createElement("option");
  optioni.text = optArr[i].text;
  optioni.value = optArr[i].value;
  selectElement.add(optioni);
}

return selectElement;

}

//创建按钮
function makeButton(left,top,width,text,color,func){

var button = document.createElement("button"); //创建一个按钮
button.textContent = text; //按钮内容
button.style.width = width+"px"; //按钮宽度
button.style.height = "25px"; //按钮高度
button.style.align = "center"; //文本居中
button.style.color = "white"; //按钮文字颜色
button.style.fontSize = "14px";
button.style.background = color; //按钮底色
button.style.border = "1px solid "+color; //边框属性
button.style.borderRadius = "4px"; //按钮四个角弧度
button.addEventListener("click", func) //监听按钮点击事件
button.style.position = "absolute";
button.style.left = left+"px";
button.style.top = top+"px";
return button

}

function chessdb2wechessStep(dStep){
var wStep="";
var dArr = dStep.split("");
wStep += dArr[0].charCodeAt(0)-97;
wStep += 9-(dArr[1].charCodeAt(0)-48);
wStep += dArr[2].charCodeAt(0)-97;
wStep += 9-(dArr[3].charCodeAt(0)-48);
return wStep;

}

(function() {

'use strict';

var button1BigMouth = makeButton(0,0,60,"大嘴","#e33e33",clickBotton1_BigMouth);
var button2AiTips = makeButton(140,0,60,"提示","#008000",clickBotton2_AiTips);
var buttonCutSave = makeButton(210,60,90,"截断保存","#8B0000",clickBotton_CutSave);

// 创建复选框元素
var checkboxBuzhoufen = document.createElement("input");
checkboxBuzhoufen.type = "checkbox";
checkboxBuzhoufen.id = "checkbok1";
checkboxBuzhoufen.checked = false;
checkboxBuzhoufen.style.position = "absolute";
checkboxBuzhoufen.style.left = "60px";
checkboxBuzhoufen.style.top = "0px";
// 创建标签元素
var checkboxBuzhoufenLabel = document.createElement("label");
checkboxBuzhoufenLabel.htmlFor = "checkbok1";
checkboxBuzhoufenLabel.appendChild(document.createTextNode("步骤分"));
checkboxBuzhoufenLabel.style.color = "white"; //按钮文字颜色
checkboxBuzhoufenLabel.style.fontSize = "14px";
checkboxBuzhoufenLabel.style.position = "absolute";
checkboxBuzhoufenLabel.style.left = "80px";
checkboxBuzhoufenLabel.style.top = "0px";

var button5MakePu = makeButton(200,0,60,"存谱","#e33e33",clickBotton1_MakePu);
// 创建局面下拉框元素
var optArr = [{text:"今局",value:0},{text:"昨局",value:1},{text:"前局",value:2}];
var selectTipSteps = makeSelectControl(200,0,optArr,changeSelTipsteps);

var buttonSimhum = makeButton(200,25,60,"拟人","#333333",clickBotton_Simhum);
//     // 创建复选框元素
// var checkboxXiaqi = document.createElement("input");
// checkboxXiaqi.type = "checkbox";
// checkboxXiaqi.id = "checkbok2";
// checkboxXiaqi.checked = true;
// checkboxXiaqi.style.position = "absolute";
// checkboxXiaqi.style.left = "263px";
// checkboxXiaqi.style.top = "28px";
// // 创建标签元素
// var checkboxXiaqiLabel = document.createElement("label");
// checkboxXiaqiLabel.htmlFor = "checkbok2";
// checkboxXiaqiLabel.appendChild(document.createTextNode("自动下"));
// checkboxXiaqiLabel.style.color = "white"; //按钮文字颜色
// checkboxXiaqiLabel.style.fontSize = "14px";
// checkboxXiaqiLabel.style.position = "absolute";
// checkboxXiaqiLabel.style.left = "285px";
// checkboxXiaqiLabel.style.top = "28px";

// 创建自动下棋下拉框元素

var optArr = [{text:"不下",value:0},{text:"最佳",value:1},{text:"2选1",value:2},{text:"3选1",value:3},{text:"4选1",value:4},{text:"5选1",value:5}];
var selectXiaqi = makeSelectControl(263,28,optArr,changeSelXiaqi);
var button3Next = makeButton(0,85,60,"下关","#008080",clickBotton3_Next);
var buttonClearBook = makeButton(0,50,60,"清书","#8B0000",clickBotton_clearBook);
var buttonReplay = makeButton(65,85,60,"重玩","#008080",clickBotton_replay);
//创建book下拉框元素
var optArr = [{text:"象棋基本杀法",value:203000480},{text:"精巧实用残局100局",value:203000826},{text:"象棋杀着大全",value:203000537},{text:"象棋残局杀势",value:203000657},{text:"象棋路边摊",value:203000936},
              {text:"中局妙手300",value:202000002},{text:"实战杀局欣赏",value:202000367}, {text:"吕钦实战中局",value:202000333}];
var selectBooks = makeSelectControl(70,50,optArr,changeSelBooks);
var button4_collectFen = makeButton(270,0,70,"收藏","#8B0000",clickBotton4_collectFen);
//创建标签
var pStageName = document.createElement("p");
pStageName.textContent = "对局名称";
pStageName.style.fontSize = "14px";
pStageName.style.color = "white";
pStageName.addEventListener("click", showAnswer) //监听点击事件
pStageName.style.position = "absolute";
pStageName.style.left = "130px";
pStageName.style.top = "65px";

var timer = null;
var timerAi = null;
var uid = 0;
setTimeout(function(){
      uid = vue.memberinfo.originuid;
      getStage(selectBooks,pStageName,false);
    },3000);// setTimeout  数秒后关闭评判

function changeSelTipsteps(){
       // 获取选中的值
      var idx = this.value;

      var a = window.game.scene.scenes[0];
      a.hideBranch('tips');//清除箭头
      var tips = a.nodes[a.movesIndex-idx].tipsStep;  //a.movesIndex
        vue.displayLine =true
        a.showTipsStep(tips[0],"先");
        a.showTipsStep(tips[1],"后");
        setTimeout(function(){
            vue.displayLine = false;
            button2AiTips.style.background = "#008000";
            button2AiTips.style.border = "1px solid #008000"; //变可用
          },300);// setTimeout  数秒后关闭评判
}

function changeSelXiaqi(){

}

function changeSelBooks(){
    var idx = this.value;
    getStage(selectBooks,pStageName,false);
}

function showAnswer(){
  var a = window.game.scene.scenes[0];
  if(stage){
    alert(stage[4]);
  }
}

var isAuplaying = false;
var isAuplayOn = false;
var timerRun = null;
function autoPlay(intv,choice){

  computer = "";
  b_autoset = 0;
  r_autoset = 0;
  vue.redautoplayTog = false;
  vue.blackautoplayTog = false;
  computerHold = 0;

  isAuplaying = true;
  var a = window.game.scene.scenes[0];

  var miniSec = 8;
  if(intv<miniSec){

          clickBotton2_AiTips();
          setTimeout(function() {
                if (choice+1>a.nodes[a.currentId].tipsStep.length || choice<0){
                  choice=choice%a.nodes[a.currentId].tipsStep.length;
                }
                a.aiMoveChess(a.nodes[a.currentId].tipsStep[choice]);

                isAuplaying = false;

         }, 1000*intv);//intv秒后落子
  }else{

    setTimeout(function() {
        clickBotton2_AiTips();
          setTimeout(function() {
                if (choice+1>a.nodes[a.currentId].tipsStep.length || choice<0){
                  choice=choice%a.nodes[a.currentId].tipsStep.length;
                }
                a.aiMoveChess(a.nodes[a.currentId].tipsStep[choice]);

                isAuplaying = false;

         }, 1000*miniSec);//miniSec秒后落子
    }, 1000*(intv-miniSec));//intv-miniSec秒后显示提示
  }

}

function clickBotton_Simhum(){

 isAuplaying = false;
 if (!isAuplayOn){
   isAuplayOn = true;
   buttonSimhum.style.background = "#008080";
   buttonSimhum.style.border = "1px solid #008080"; //激活色
   var a = window.game.scene.scenes[0];

   clearInterval(timerRun);
   timerRun = null;
   timerRun = setInterval(function() {
      if(((a.getHold()==-1 && a.isReverse==0)||(a.getHold()==1 && a.isReverse==1))&&!isAuplaying)//对方下
      {
          var timeintv = 4;
          if(a.movesIndex>20){
              timeintv = 20;
          }
          if(selectXiaqi.value>0)
          {
              autoPlay(timeintv,Math.floor(Math.random()*selectXiaqi.value));
          }

      }
     },1000);
 }else{
   // buttonSimhum.style.background = "#333333";
   // buttonSimhum.style.border = "1px solid #333333"; //变灰色

// clearInterval(timerRun);
// timerRun = null;

 }

}

async function getFenImg(fen){

   if (typeof game2 === 'undefined') {
    var script = document.createElement('script');
    script.src = 'https://ke.wechess.cn/addons/xiangqi_lesson/template/mobile/script/chess/game2.js';
    document.head.appendChild(script);
    setTimeout(() => {
      initialization2();
      setTimeout(() => {
        return "not ready for getFenImg";
        //   })
      }, 1000);
    }, 1000);

  } else {
        window.game2.scene.scenes[0].setChessByMap(board2map(fen, 1), 0)
        return vue.snapshot();
        // imgPromise.then(function(imgBase64) {
        //     console.log('<img src="'+imgBase64+'">');
        //   })
      alert("dd");
  }
}

 function getFenImg2(fen,isblack){
   var xhr = new XMLHttpRequest();
   var url = "https://login.gpt10086.com/langkongTool/xq/xqfen2base64.php";
   var params = "imgtype=base64&fen="+fen+"&isBlack="+isblack;

    xhr.open("POST", url, false);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhr.send(params);

  if (xhr.readyState === 4 && xhr.status === 200) {
    return xhr.responseText;
  }
}

function clickBotton1_MakePu(){

  var a = window.game.scene.scenes[0];
  var s = '<html><head><meta charset="UTF-8"><title>Documenttitle</title>    <style>.container {      column-count: 2;      column-gap: 20px;      width: 100%;        }    .content {      break-inside: avoid;    }        </style></head><body>';
  s += '<div class="container">  <div class="content"><h2>象棋</h2>';
  var w = 300;
  var countNoImg = 0;
  if(a.nodes[0].currentFen !== "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w")
  {
    var imgBase64 = getFenImg2(a.nodes[0].currentFen,a.isReverse);
    s += '<img width = "'+w+'px" src="'+imgBase64+'">'+"<BR>";
  }
 var oldScore = a.nodes[0].score;
  for (var i = 1; i < a.nodes.length; i++) {
      var node = a.nodes[i];
      var gradeStr = "";
      countNoImg += 1;
      if (node.grade == "漏"){gradeStr = '<span style="color: #ff4444; font-weight: bold;">'+i+"、"+node.stepcn+"("+node.score+")"+'漏</span><BR>'+a.nodes[i-1].tipsStep[0]+"、"+a.nodes[i-1].tipsStep[1];}//
      else if (node.grade == "错"){gradeStr = '<span style="color: #ff4444; font-weight: bold;">'+i+"、"+node.stepcn+"("+node.score+")"+'错</span><BR>'+a.nodes[i-1].tipsStep[0]+"、"+a.nodes[i-1].tipsStep[1];}//
      else if (node.grade == "差"){gradeStr = '<span style="color: #fe8905; font-weight: bold;">'+i+"、"+node.stepcn+"("+node.score+")"+'差</span>';}
      else if (node.grade == "中"){gradeStr = '<span style="color: #999999; font-weight: bold;">'+i+"、"+node.stepcn+"("+node.score+")"+'中</span>';}
      else if (node.grade == "良"){gradeStr = '<span style="color: #3388ff; font-weight: bold;">'+i+"、"+node.stepcn+"("+node.score+")"+'良</span>';}
      else if (node.grade == "官"){gradeStr = '<span style="color: #644227; font-weight: bold;">'+i+"、"+node.stepcn+"("+node.score+")"+'官</span>';}
      else if (node.grade == "优"){gradeStr = '<span style="color: ##2ba38e; font-weight: bold;">'+i+"、"+node.stepcn+"("+node.score+")"+'优</span>';
         if(countNoImg>4){
              countNoImg = 0;
               var imgBase64 = getFenImg2(node.currentFen,a.isReverse);

               gradeStr += '<BR><img width = "'+w+'px"  src="'+imgBase64+'">';
         }
      }
      else{
        gradeStr = '<span style="color: #000; ">'+i+"、"+node.stepcn+"("+node.score+")"+'</span>';
      }
      s+= gradeStr;
      if(i%2 == 0 || countNoImg == 0){
        s+="<BR>";
      }else{
        s+="&nbsp;&nbsp;&nbsp;&nbsp;";
      }
      if((Math.abs(node.score-oldScore)>200  || i==10)&&  countNoImg >0){
          countNoImg = 0;
         var imgBase64 = getFenImg2(node.currentFen,a.isReverse);
         if(i%2 == 1){s += "<BR>";}
         s += '<img width = "'+w+'px"  src="'+imgBase64+'">'+"<BR>";
      }

      oldScore = node.score;
  }
   s += "</div>   </div> </body></html>";
   console.log(s);
    const fileContent = s;
    const fileName = 'qipu.html';

    downloadFile(fileContent, fileName);
}

function clickBotton1_BigMouth(){//开启功能
  button1BigMouth.style.background = "#85532e";
  button1BigMouth.style.border = "1px solid #85532e"; //变灰色
  //console.log(checkboxBuzhoufen.checked);

  var a = window.game.scene.scenes[0];
  var curStep = 0;
  var curScore = 0;
  //a.playAudio("hejie","message")
  if(a.mode>0){  //复盘,华山,对战
      vue.toastValue = "开启好棋臭棋提示,可选是否显示步骤分";
  }else{ //a.mode == 0 人机对战
      vue.toastValue = "选中步骤分,才能步步ai";
  }

  vue.toastShow = true;
  setTimeout(function(){
      vue.toastShow = false;
      //clearInterval(timer);
  },3000);// setTimeout  数秒后关闭评判

  if(timer){
    clearInterval(timer);
  };

  var isClickedBtn2 = false;
  timer = setInterval(function() {
        //var date = new Date();
        //console.log(date.toLocaleTimeString());
        if(a.mode == 5){  //online game
          var countdown = document.getElementsByClassName('countdown')[1];
          countdown =parseInt(countdown.textContent.trim());
          if(countdown<30 && curStep>8 &&  !isClickedBtn2){
              clickBotton2_AiTips();
              isClickedBtn2 = true;
          }
        }
        if (a.movesIndex > curStep ){
            curStep = a.movesIndex;

            if(a.mode==0 && checkboxBuzhoufen.checked){ //a.mode==0  人机对战
                fetchAi();  //不注释此处,步步ai分析。 这时候 人机对战模式下 “大嘴”供能才可以用,其它下棋界面不影响
            }

            isClickedBtn2 = false;
            if (a.mode >=0){
                setTimeout(function(){
                       if(a.mode == 5){ //online game 棋力测评,华山论剑
                            var score = formatter(vue.dataY[curStep]);
                       }else if(a.mode==2 ||a.mode==7){ //复盘
                             var score = formatter(vue.dataY[0][curStep][1]);
                       }else if(a.mode==0 ||a.mode==3){ //a.mode==0  人机对战   3棋谱观看

                             var score = a.nodes[curStep].score;
                       }

                        if ((score - curScore)>0){
                          var tagupdown = "↑";
                        }else{
                          var tagupdown = "↓";
                        }
                  console.log(score);
                        if(Math.abs(score - curScore )>200){
                           vue.toastValue = tagupdown+score+"着!!!!!";
                           fetchAi();
                           vue.toastShow = true;
                        }else{
                           vue.toastValue = tagupdown+score;
                           if(checkboxBuzhoufen.checked){
                              vue.toastShow = true;
                           }

                        }
                  console.log(vue.toastValue );
                        if(vue.toastShow){
                          setTimeout(function(){
                              vue.toastShow = false;
                              //clearInterval(timer);
                            },3000);// setTimeout  数秒后关闭评判
                        }
                        curScore = score;
                    },3000);// setTimeout  数秒后开始评判

            }
        }

      }, 500);

}

function clickBotton2_AiTips(){//AI提示

  button2AiTips.style.background = "#85532e";
  button2AiTips.style.border = "1px solid #85532e"; //变灰色
  selectTipSteps.value = 0;
  var a = window.game.scene.scenes[0];
  var curId  = a.currentId;  //a.movesIndex  a.currentId

  var xhr = new XMLHttpRequest();
  var url = "https://www.chessdb.cn/chessdb.php?action=queryall&learn=1&showall=0&board="+a.nodes[curId].currentFen;
  xhr.open("GET", url, true);
  xhr.onreadystatechange = function() {
      if (xhr.readyState === 4 && xhr.status === 200) {
          var resArr = xhr.responseText.split("|");
          //console.log(xhr.responseText);
          if(xhr.responseText.startsWith("move")){
            vue.displayLine =true
            vue.toastShow = true;
            vue.toastValue = "分数:";
            var tag=["先","后","3","4","5","6","7","8","9","10"];
            var tipBUshu = 0;
            //if((a.currentId)%2 != a.isReverse) //a.isReverse 0执红1执黑    (a.currentId)%2   0轮到红下1轮到黑下                getHold()
            if((a.getHold()==-1 && a.isReverse)||(a.getHold()==1 && !a.isReverse))
            {
                tipBUshu = 5;  //对方下,提示五种
            }else{
                tipBUshu = 5; //自己下,提示3种
            }
            a.nodes[curId].tipsStep = [];
            for(var i=0;i<Math.min(resArr.length,tipBUshu);i++){
               var dirArr = resArr[i].split(",");
               var step = dirArr[0].replace("move:","");
               //if (i==0){
                   //a.nodes[curId].tipsStep = chessdb2wechessStep(step); //记录 步骤
                   // //a.nodes[a.movesIndex].score = parseInt(dirArr[1].replace("score:",""));  //不记录分数,怕分数格式不一样
               //}
              a.nodes[curId].tipsStep.push(chessdb2wechessStep(step));
              a.showTipsStep(chessdb2wechessStep(step),tag[i]);
              vue.toastValue += "("+tag[i]+"):"+dirArr[1].replace("score:","")+"、";

            }
            vue.displayLine = false;
            button2AiTips.style.background = "#008000";
            button2AiTips.style.border = "1px solid #008000"; //变可用
            setTimeout(function(){
              vue.toastShow = false;
            },3000);// setTimeout  数秒后关闭评判
          }else{

              fetchAi();

              vue.toastValue = "正在生成ai提示...";
              vue.toastShow = true;
              a.nodes[curId].tipsStep = [];
              timerAi = setInterval(function() {

                   if(a.nodes[curId].tipsStep.length>1 ){
                        a.nodes[curId].tipsStep.pop();//删除对手招法tips[1]

                        vue.toastShow = false;
                        console.log(a.nodes[curId].openbookDetail);//开局信息
                        console.log(a.nodes[curId].computerDetail[0]);//多步骤提示信息
                        console.log(a.nodes[curId].tipsStep);//一个回合提示

                        a.hideBranch('tips');//清除箭头
                        var tips = a.nodes[curId].tipsStep;  //a.movesIndex
                        vue.displayLine =true
                        a.showTipsStep(tips[0],"先");
                        a.showTipsStep(a.nodes[curId].computerDetail[0].list[1],"先");
                        a.showTipsStep(a.nodes[curId].computerDetail[0].list[2],"后");
                        a.showTipsStep(a.nodes[curId].computerDetail[0].list[3],"后");
                        a.showTipsStep(a.nodes[curId].computerDetail[0].list[4],"3");
                        a.showTipsStep(a.nodes[curId].computerDetail[0].list[5],"3");
                        //vue.toastValue = "红优正分:"+a.nodes[a.movesIndex].score;
                        //if((a.currentId)%2 ){//黑下a.getHold()
                        if(a.getHold()==-1 ){//黑下
                            vue.toastValue = "分数:"+ (-a.nodes[curId].score)+" 下法:"+tips[0];
                        }else{
                             vue.toastValue = "分数:"+a.nodes[curId].score+" 下法:"+tips[0];
                        }
                        vue.toastShow = true;
                            vue.displayLine = false;
                            button2AiTips.style.background = "#008000";
                            button2AiTips.style.border = "1px solid #008000"; //变可用
                            setTimeout(function(){
                              vue.toastShow = false;
                            },3000);// setTimeout  数秒后关闭评判
                        clearInterval(timerAi);
                   }
                },300);// setTimeout  数秒后关闭评判

          }
      }
  };
  xhr.send();

}

function clickBotton3_Next(){

var a = window.game.scene.scenes[0];
//获取下一关记录
getStage(selectBooks,pStageName,true);

}

function clickBotton_replay(){

var a = window.game.scene.scenes[0];
//重玩当前关
if(stage){
  a.setBoard(stage[2]);
}else{
  getStage(selectBooks,pStageName,false);
}

}

function clickBotton_clearBook(){

var a = window.game.scene.scenes[0];
//重玩当前关
if (confirm("确定要清除本书的学习记录吗?点确定会导致重新学本书:"+selectBooks.options[selectBooks.selectedIndex].text)) {
      var xhr = new XMLHttpRequest();
      var url = "https://login.gpt10086.com/langkongTool/xq/xqclearuserbook.php";
      var params = "uid="+uid+"&bid="+selectBooks.value;
      xhr.open("POST", url, true);
      xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xhr.onreadystatechange = function() {
          if (xhr.readyState === 4 && xhr.status === 200) {
              var responseText = xhr.responseText.trim();
              getStage(selectBooks,pStageName,false);
              // 处理获取到的响应内容
              alert(responseText);
          }
      };
      xhr.send(params);
} else {
}

}

function clickBotton_CutSave(){

var a = window.game.scene.scenes[0]
var omitStep = a.currentId //当前步后局面
a.nodes = a.nodes.slice(omitStep)
for(var i=0;i<a.nodes.length;i++){
  a.nodes[i].child[0] -= omitStep
  a.nodes[i].id-=omitStep
  a.nodes[i].index-=omitStep
  a.nodes[i].pater-=omitStep
}
a.nodes[0].step=""
a.nodes[0].stepcn=""
vue.hasChange = true
saveChess("",chessdata.id,null)
clearHistoryStorage(chessdata.id)
vue.hasChange = false

}

function clickBotton4_collectFen(){

var a = window.game.scene.scenes[0];
if(a.mode == 0){//人机对战 收藏的是关卡棋盘,不是当前棋盘
  if(confirm("点“确认”收藏当前关卡(回到第一步),点“取消”收藏当前棋局(当前步)")){
      a.setBoard(stage[2]);
      window.collectFen();
  }else{
     window.collectFen();
  }

}else{
  window.collectFen();
}

}

var main_bg = document.getElementsByClassName('main_bg')[0]; //getElementsByClassName 返回的是数组,所以要用[] 下标  qipan   van-nav-bar__content
main_bg.appendChild(button1BigMouth); //把按钮加入到 x 的子节点中
main_bg.appendChild(button2AiTips);
main_bg.appendChild(buttonCutSave);
main_bg.appendChild(checkboxBuzhoufen);
main_bg.appendChild(checkboxBuzhoufenLabel);
main_bg.appendChild(selectTipSteps);
main_bg.appendChild(button5MakePu);

main_bg.appendChild(button3Next);
main_bg.appendChild(buttonReplay);
main_bg.appendChild(buttonClearBook);
main_bg.appendChild(selectBooks);
main_bg.appendChild(button4_collectFen);
main_bg.appendChild(pStageName);

main_bg.appendChild(buttonSimhum);
main_bg.appendChild(selectXiaqi);

setInterval(function() {
  var a = window.game.scene.scenes[0];
  if(a.mode==0){
    button3Next.style.display = "block";buttonReplay.style.display = "block";buttonClearBook.style.display = "block";
    selectBooks.style.display = "block";
    pStageName.style.display = "block";
    buttonSimhum.style.display = "block";
    selectXiaqi.style.display = "block";

  }else{
    button3Next.style.display = "none";buttonReplay.style.display = "none";buttonClearBook.style.display = "none";
    selectBooks.style.display = "none";
    pStageName.style.display = "none";
    buttonSimhum.style.display = "none";
    selectXiaqi.style.display = "none";
  }

  if(a.mode==3){//被上面条挡住了
    button2AiTips.style.top = "60px";
    buttonCutSave.style.display = "block";
  }else{
    button2AiTips.style.top = "0px";
    buttonCutSave.style.display = "none";
  }

  if(a.mode==2 || a.mode==7){
    selectTipSteps.style.display = "none";
    button5MakePu.style.display = "block";
  }else{
    selectTipSteps.style.display = "block";
    button5MakePu.style.display = "none";
  }
}, 500);

   if (typeof game2 === 'undefined') {
    var script = document.createElement('script');
    script.src = 'https://ke.wechess.cn/addons/xiangqi_lesson/template/mobile/script/chess/game2.js';
    document.head.appendChild(script);
    setTimeout(() => {
      initialization2();
      setTimeout(() => {
        console.log("initialization2 done  ");

      }, 1000);
       console.log("game2 done  ");
    }, 1000);
   }

})(); //(function() { --- })(); 表示立即执行

发表新评论