首页 > 其他分享 >XJTU_运动场

XJTU_运动场

时间:2022-11-14 10:25:32浏览次数:30  
标签:console log XJTU image 运动场 var document data

  1 // ==UserScript==
  2 // @name         xjtu-ydc-sr
  3 // @namespace    http://tampermonkey.net/
  4 // @version      0.4.1
  5 // @description         xitu-ydc-sr
  6 // @description:zh-CN   xjtu-ydc-sr
  7 // @author       AnZhili
  8 // @match        http://202.117.17.144/*
  9 // @icon         https://www.google.com/s2/favicons?sz=64&domain=17.144
 10 // @grant        none
 11 // @license      AnZhili
 12 // ==/UserScript==
 13 
 14 (function() {
 15     try{
 16     document.getElementById('showWin').style.display='none';
 17     document.getElementById('info').style.display='none';
 18     }catch(e){
 19 
 20     }
 21     var yzm = false;
 22     var currentTime = new Date(); //本地时间
 23     var currentTimeStr = currentTime.toString();
 24     var restString = " 08:40:01 GMT+08:00";
 25     var targetTimeStr = currentTimeStr.substring(0, 15) + restString;
 26     var targetTime = new Date(targetTimeStr); //目标时间(根据今天的时间自动更新);
 27     console.log("targetTime:" + targetTime);
 28     //确定预定时间
 29     try{
 30     document.getElementById("reserve")
 31         .style.display = "block";}
 32     catch(e){
 33     }
 34     var u = window.location.href;
 35 
 36     //在product页面下的操作;不进行时间预判;
 37     if (u.includes('product')) {
 38         $(document)
 39             .click(function(e) {
 40                 var id = e.target.id;
 41                 console.log(id);
 42                 if (id == "reserve") {
 43                     document.getElementById("reserve")
 44                         .attachEvent = ("onclick", applySeat());
 45                 }
 46             });
 47         //创建时间控件
 48         var t = document.createElement("text");
 49         t.style.margin = "10px";
 50         t.style.width = "100px";
 51         t.style.height = "30px";
 52         document.body.appendChild(t);
 53         var xhsj = setInterval(function() {
 54             //循环看时间
 55             var time = new Date()
 56                 .toLocaleTimeString();
 57             t.innerHTML = time;
 58         }, 1000);
 59     }
 60 
 61     //订购页面下,进行时间预判
 62     if (u.includes('order')) {
 63         //document.getElementById("reserve").attachEvent=("onclick",yzmWindow());
 64         yzmWindow();
 65         console.log("yzm");
 66         //创建时间控件
 67         t = document.createElement("text");
 68         t.style.margin = "10px";
 69         t.style.width = "100px";
 70         t.style.height = "30px";
 71         document.body.appendChild(t);
 72         var xhsj2 = setInterval(function() {
 73             //循环看时间
 74             var time = new Date()
 75                 .toLocaleTimeString();
 76             t.innerHTML = time;
 77             var restTime = getRestTime(targetTime);
 78             console.log(restTime)
 79             //这里判断
 80             if (restTime < -1000) {
 81                 //说明超过了40分1秒,人工处理提交了;
 82                 clearInterval(xhsj2);
 83             } else if (-1000<restTime && restTime<1000) {
 84                 //说明时间在00-01秒之间,这里进行提交
 85                 document.querySelector("#dlg > div.dialog-foot > button")
 86                     .click();
 87                 console.log('时间在0-1秒之内')
 88                 clearInterval(xhsj2);
 89             } else if (1000<restTime && restTime<10000) {
 90                 //时间还有5-10秒时,进行验证码处理;并判断是否验证码处理;
 91                 if (yzm == false) {
 92                     //说明没验证码;
 93                     var img = document.querySelector("#typecode > span > img"); //应该是图片不可以跨域访问导致的问题
 94                     var url = downloadIamge(img.src);
 95                     yzm = true;
 96                 }
 97             }else{
 98             console.log('等待中...')
 99             }
100             //继续等待
101         }, 1000);
102     }
103 
104 
105 
106 
107     //获取时间差值
108     function getRestTime(targetTime) {
109         currentTime = new Date();
110         var restTime = targetTime.getTime() - currentTime.getTime();
111         return restTime;
112     }
113 
114     function downloadIamge(imgsrc) { //下载图片地址和图片名
115         let image = new Image();
116         // 解决跨域 Canvas 污染问题
117         image.setAttribute("crossOrigin", "anonymous");
118         image.src = imgsrc;
119         image.onload = function() {
120             let canvas = document.createElement("canvas");
121             canvas.width = image.width;
122             canvas.height = image.height;
123             let context = canvas.getContext("2d");
124             context.drawImage(image, 0, 0, image.width, image.height);
125             let baseURL = canvas.toDataURL("image/png"); //得到图片的base64编码数
126             var webURL = baseURL.slice(22);
127             document.querySelector("#typecode > span > img")
128                 .src = 'data:image/png;base64,' + encodeURIComponent(webURL);
129             //console.log(encodeURIComponent(webURL))
130             imgcode(encodeURIComponent(webURL)) //获取验证码
131         };
132     }
133 
134 
135     function imgcode(uri) {
136         //token自行获取
137         //uri传进来
138         $.ajax({
139             type: "post",
140             url: "http://www.bhshare.cn/imgcode/",
141             data: {
142                 token: ' ',
143                 uri: 'data:image/png;base64,' + uri,
144                 type: "online"
145             },
146             dataType: "json",
147             success: function(data) {
148                 console.log(data);
149                 if (data.code > 0) {
150                     console.log(data.data);
151                     document.querySelector("#yzm")
152                         .value = data.data;
153                 } else {
154                     console.log(data.msg);
155                 }
156             },
157             error: function(result) {
158                 console.log(result);
159                 console.log(JSON.stringify(result));
160                 alert("系统繁忙,请稍后再试!");
161             }
162 
163         });
164     }
165 
166 
167 })();

 

标签:console,log,XJTU,image,运动场,var,document,data
From: https://www.cnblogs.com/anzhili/p/16888170.html