// ==UserScript== // @name 获取12306cookie值 // @namespace https://kyfw.12306.cn/ // @version 0.2 // @description 我们的目的是在登录12306网站后,方便、快速的获取到抢票需要的cookie值。 // @author wonder // @match https://kyfw.12306.cn/* // @grant none // @downloadURL none // ==/UserScript== (function() { //'use strict'; //console.log($("body").html()); console.log("【总cookie】",document.cookie) function getCookie(cname) { var name = cname + "="; //var decodedCookie = decodeURIComponent(document.cookie); var cookieStr = document.cookie; var ca = cookieStr.split(';'); for(var i = 0; i " +"【tk】:
"+""+getCookie("tk")+"
" +"【RAIL_EXPIRATION】:
"+""+getCookie("RAIL_EXPIRATION")+"
" +"【RAIL_DEVICEID】:
"+""+getCookie("RAIL_DEVICEID")+"
" +"

" //ajax上传服务器 document.getElementById("send").onclick=sendData; //点击事件 // 不知道为什么不能引用jq,所以只能用原生js写了。 // $("#send").click(function(){ // alert("功能开发中~"); // console.log("发送数据到服务器~"); // $.ajax( // { // url:"https://api.github.com/", // type:"post", // data:{}, // success:function(res){ // console.log("服务器返回结果:",res); // } // } // ); // }) } var data = {tk:getCookie("tk"),rail_expiration:getCookie("RAIL_EXPIRATION"),rail_deviceid:getCookie("RAIL_DEVICEID")}; function sendData() { //alert("接收cookie程序开发中~"); var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { //alert(typeof xmlhttp.response); console.log(xmlhttp.response) var result = JSON.parse(xmlhttp.response); console.log(typeof result); if(result.code==200){ alert("发送成功!"); }else{ alert("发送失败!"); } } } //请把https://api.github.com改为自己的服务器地址。 请确保该地址为https 开头,而不是http xmlhttp.open("POST","https://wonder.test.utools.club/cookie",true); xmlhttp.setRequestHeader('Content-Type','application/json'); console.log("JSON==================",JSON.stringify(data)); //将用户输入值序列化成字符串 xmlhttp.send(JSON.stringify(data)); //向服务器发送tk值 //xmlhttp.send(); } // Your code here... })();