-
-
Save arronzhang/1574007 to your computer and use it in GitHub Desktop.
12306 Auto Login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
12306 Auto Login => A javascript snippet to help you auto login 12306.com. | |
Copyright (C) 2011 Kevintop | |
Includes jQuery | |
Copyright 2011, John Resig | |
Dual licensed under the MIT or GPL Version 2 licenses. | |
http://jquery.org/license | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
// ==UserScript== | |
// @name 12306 Auto Login | |
// @author kevintop@gmail.com, zzdhidden@gmail.com | |
// @namespace https://plus.google.com/107416899831145722597 | |
// @description A javascript snippet to help you auto login 12306.com | |
// @include *://dynamic.12306.cn/otsweb/loginAction.do* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js | |
// ==/UserScript== | |
function withjQuery(callback, safe){ | |
if(typeof(jQuery) == "undefined") { | |
var script = document.createElement("script"); | |
script.type = "text/javascript"; | |
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"; | |
if(safe) { | |
var cb = document.createElement("script"); | |
cb.type = "text/javascript"; | |
cb.textContent = "jQuery.noConflict();(" + callback.toString() + ")(jQuery);"; | |
script.addEventListener('load', function() { | |
document.head.appendChild(cb); | |
}); | |
} | |
else { | |
var dollar = undefined; | |
if(typeof($) != "undefined") dollar = $; | |
script.addEventListener('load', function() { | |
jQuery.noConflict(); | |
$ = dollar; | |
callback(jQuery); | |
}); | |
} | |
document.head.appendChild(script); | |
} else { | |
callback(jQuery); | |
} | |
} | |
withjQuery(function($){ | |
$(document).click(function() { | |
//alert( "bb" + str ); | |
if( window.webkitNotifications && window.webkitNotifications.checkPermission() != 0) { | |
window.webkitNotifications.requestPermission(); | |
} | |
}); | |
var notify = function(str) { | |
//alert( "bb" + str ); | |
if( window.webkitNotifications && window.webkitNotifications.checkPermission() == 0) { | |
var notification = webkitNotifications.createNotification( | |
null, // icon url - can be relative | |
'订票', // notification title | |
str | |
); | |
notification.show(); | |
} else { | |
alert( str ); | |
} | |
} | |
var url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=login"; | |
var queryurl = "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init"; | |
function submitForm(){ | |
var submitUrl = url; | |
$.ajax({ | |
type: "POST", | |
url: submitUrl, | |
data: { | |
"loginUser.user_name": $("#UserName").val() | |
, "user.password": $("#password").val() | |
, "randCode": $("#randCode").val() | |
}, | |
timeout: 30000, | |
//cache: false, | |
//async: false, | |
success: function(msg){ | |
if (msg.indexOf('请输入正确的验证码') > -1) { | |
alert('请输入正确的验证码!'); | |
}; | |
if (msg.indexOf('当前访问用户过多') > -1) { | |
reLogin(); | |
} | |
else { | |
notify('登录成功,请刷新!'); | |
location.replace(queryurl); | |
}; | |
}, | |
error: function(msg){ | |
reLogin(); | |
}, | |
beforeSend: function(XHR){ | |
//alert("Data Saved: " + XHR); | |
} | |
}); | |
} | |
function reLogin(){ | |
var currNum = $('#reloginNum').html(); | |
$('#reloginNum').html(parseInt(currNum) + 1); | |
setTimeout(submitForm, 2000); | |
} | |
//初始化 | |
$("body").prepend("<div style='white-space:nowrap;'>重试次数:<div id='reloginNum' >0</div></div>"); | |
$("#subLink").after("<a href='#' id='autoSubmit' class='button_a' ><span><ins>自动登录</ins> </span> </a>"); | |
$("#autoSubmit").live("click", function(){ | |
notify('开始尝试登录,请耐心等待!'); | |
submitForm(); | |
}); | |
notify('如果使用自动登录功能,请输入用户名、密码及验证码后,点击自动登录,系统会尝试登录,直至成功!'); | |
}, true); |
自动刷新火车票...
https://gist.github.com/1554666
很不错的说,要是谁能搞个自动提交订单就好了。。。技术宅挡不住啊
@darkz1984 订单那一步还好吧, 本身就比较慢,这一步也比较激动,自个儿多点几次就成了。 点不进去后面也没票了。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
12306.com自动登录脚本:
来自:
https://gist.github.com/1570973
改为桌面通知提示.
chorme打开下面脚本安装:
https://gist.github.com/raw/1574007/1caa1a4f1a9fa057686b3e7066f68b4c2f3701a2/12306AutoLogin.user.js
然后打开 https://dynamic.12306.cn/otsweb/ 开始体验自动登录
源代码地址:
https://gist.github.com/1574007