标签归档:js

如何下载受限资源

1 通过Chrome的network查找到加载的资源,如 http://cache.gensee.com/gsgetrecord/record14.gensee.net/gsrecord/115291/sbr/2018_05_06/V4AFs46eBy_1525568216/3976114433_145.swf

1

2 尝试通过本地的html页面将单张集成起来,但swf有其特殊性集成失败

3 换个思路,切换到移动版本(现在的手机不支持flash),以同样的方法可以找到图片资源地址,如 http://cache.gensee.com/gsgetrecord/record19.gensee.net/gsrecord/115291/sbr/2018_05_05/V4AFs46eBy_1525499873/hls/3976114433_96.png

4 多找两张看看其规律 http://cache.gensee.com/gsgetrecord/record19.gensee.net/gsrecord/115291/sbr/2018_05_05/V4AFs46eBy_1525499873/hls/3976114433_97.png

5 按照规律写脚本,如下:

   var data = [];
    data.push({
        name:'冲刺1', 
        url:'http://cache.gensee.com/gsgetrecord/record20.gensee.net/gsrecord/115291/sbr/2018_05_05/V4AFs46eBy_1525481655/hls/3976114433_{0}.png',
        end: 95
    },{
        name:'冲刺2', 
        url:'http://cache.gensee.com/gsgetrecord/record19.gensee.net/gsrecord/115291/sbr/2018_05_05/V4AFs46eBy_1525499873/hls/3976114433_{0}.png',
        start: 96,
        end: 144
    },{
        name:'冲刺3', 
        url:'http://cache.gensee.com/gsgetrecord/record14.gensee.net/gsrecord/115291/sbr/2018_05_06/V4AFs46eBy_1525568216/hls/3976114433_{0}.png',
        start: 145,
        end: 202
    },{
        name:'冲刺4', 
        url:'http://cache.gensee.com/gsgetrecord/record20.gensee.net/gsrecord/115291/sbr/2018_05_06/V4AFs46eBy_1525586183/hls/3976114433_{0}.png',
        start: 203,
        end: 344
    });

6 将上述页面生成 html

   var b = 0;
    if(qs && qs['b']){
        b = qs['b'] * 1;
    } else {
        document.title = '系分考试';
        $('content').innerHTML = html;
        return;
    }
    
    
    
    var url = data[b].url;
    var start = data[b].start;
    if(!start){
        start = 0;
    }
    var end = data[b].end;
    var name = data[b].name;
    document.title = '系分考试-' + name;
    
    
    
    

    html += '\n\n';
    for(var i = start;i<=end;i++){
    
        html += '\n\n';
        
        html += '![{0}]({0}) '.format(url.format(i));
        
    }
    console.log(html);
    $('content').innerHTML = html;

7 通过浏览器打印生成pdf

8 完整代码

<!DOCTYPE html>
<html>
<title></title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<link rel="apple-touch-icon" href="images/task/task3.png">
<xmp theme="simplex" style="display:none;" id="content">

</xmp>
<script src="js/tohours.min.js"></script>
<script>
(function(){


    var data = [];
    data.push({
        name:'冲刺1', 
        url:'http://cache.gensee.com/gsgetrecord/record20.gensee.net/gsrecord/115291/sbr/2018_05_05/V4AFs46eBy_1525481655/hls/3976114433_{0}.png',
        end: 95
    },{
        name:'冲刺2', 
        url:'http://cache.gensee.com/gsgetrecord/record19.gensee.net/gsrecord/115291/sbr/2018_05_05/V4AFs46eBy_1525499873/hls/3976114433_{0}.png',
        start: 96,
        end: 144
    },{
        name:'冲刺3', 
        url:'http://cache.gensee.com/gsgetrecord/record14.gensee.net/gsrecord/115291/sbr/2018_05_06/V4AFs46eBy_1525568216/hls/3976114433_{0}.png',
        start: 145,
        end: 202
    },{
        name:'冲刺4', 
        url:'http://cache.gensee.com/gsgetrecord/record20.gensee.net/gsrecord/115291/sbr/2018_05_06/V4AFs46eBy_1525586183/hls/3976114433_{0}.png',
        start: 203,
        end: 344
    });
    
    var $ = function(id){
        return document.getElementById(id);
    }
    
    var html = '';
    for(var i=0;i<data.length;i++){
        if(i%3 == 0){
            html += '\n\n';
        }
        html += '[【{0}】](cc-xf?b={1}) '.format(data[i].name, i);
    }
    html += '\n\n';
    
    html += '<a href="javascript:;" onclick="hideLink()">【关闭】</a> [【首页】](cc-xf)';
    
    
    qs = tohours.queryString();
    var b = 0;
    if(qs && qs['b']){
        b = qs['b'] * 1;
    } else {
        document.title = '系分考试';
        $('content').innerHTML = html;
        return;
    }
    
    
    
    var url = data[b].url;
    var start = data[b].start;
    if(!start){
        start = 0;
    }
    var end = data[b].end;
    var name = data[b].name;
    document.title = '系分考试-' + name;
    
    
    
    

    html += '\n\n';
    for(var i = start;i<=end;i++){
    
        html += '\n\n';
        
        html += '![{0}]({0}) '.format(url.format(i));
        
    }
    console.log(html);
    $('content').innerHTML = html;
})();

function hideLink(){
    var a = document.getElementsByTagName('a');
    for(var i=0;i<a.length;i++){
        a[i].style = 'display:none';
    }
}
</script>
<script src="js/strapdown.js"></script>
</html>

 

上海公安出入境微信查询系统改进

最近再使用上海公安出入境的微信预约办理大陆证,网上预约与查询都很方便。唯一让我不爽的就是它每次都要让我重新输入身份证号和姓名,于是我做了简单的修改,自己用

出入境微信查询页面
查询页面:http://1251026295.cdn.myqcloud.com/1251026295/CRJ/page/yycheck.html

值得学习的几个地方

  1. 考虑到查询的量可能会特别的大,所以出入境使用了腾讯云(这也是我第一次听说腾讯也在做云)
  2. 考虑到页面展示与动态查询的分离,它使用了JSONP的方式做查询

非常令人抓狂的地方

在你输入身份证查询预约信息以后,再返回页面想查询办件进度查询,必须要再输入身份证与姓名信息,非常的不人性化

解决方案

  1. 最好的解决方案当然是使用跟微信号绑定的方式,如果查询到这个微信用户已经登录过,去后台取用户信息直接返回用户查询结果就好了,这是一种最直接也是最安全的方式,但我们这次改造是接触不到后台的,所以这个方案在前端改造行不通
  2. 使用本地存储,将身份证和姓名记录到本地,当页面初始化的时候,调用方法读取本地的数据。但这样做有一个巨大的问题,就是用户的信息很容易被其他用户数据读取。

具体实施

  1. 复制上面的查询页面
  2. 粘贴到自己新建的html中
  3. 在head中增加base标签
  4. 在上方增加读取本地信息代码

base标签

<base href="http://1251026295.cdn.myqcloud.com/1251026295/CRJ/page/"/>

读取本地信息代码

$(function() {
    if (window.localStorage) {
        var ck_number = localStorage.getItem('ck_number');
        var ck_name = localStorage.getItem('ck_name');
        var ck_id = localStorage.getItem('ck_id');
        if (ck_number) {
            $('#ck_number').val(ck_number);
        }
        if (ck_name) {
            $('#ck_name').val(ck_name);
        }
        if (ck_id) {
            $('#' + ck_id).click();
        }

        $('#ck_sub').click(function() {
            ck_number = $('#ck_number').val();
            ck_name = $('#ck_name').val();
            ck_id = $(':radio[checked]').attr('id');
            if (ck_number) {
                localStorage.setItem('ck_number', ck_number);
            }
            if (ck_name) {
                localStorage.setItem('ck_name', ck_name);
            }
            if (ck_id) {
                localStorage.setItem('ck_id', ck_id);
            }
        });
    }

});

使用中出现的问题

在使用中会出现部分微信的Android手机不能读取到用户信息的问题,开始以为是localStorage的问题,查找结果显示,即使换成了Cookie也存在同样的问题。网上给出的建议还是使用微信绑定的方式来的更直观和安全以些,这个方式只能是个临时解决方案

最后,还是希望出入境开发人员做简单的调整,让我们以更安全更方便的方式来查询请求

JavaScript正则表达式定义常用方法

正则的定义:

var reg = /pattern/igm;
var reg = new RegExp(‘pattern’, ‘igm’);

1. 其中i的意思是忽略大小写,如:

不加i

reg = /test/;
str = ‘tEStab’;
reg.exec(str);//返回null

加上i

reg = /test/i;
str = “tEStab”;
reg.exec(str);//返回["tESt"]

2. g的意思是全局查找,

不加g

reg = /tes[ta]/;
str = ‘testatesab’;
reg.exec(str); //返回["test"]
reg.exec(str); //返回["test"]

加上g

reg = /tes[ta]/g;
str = ‘testatesab’;
reg.exec(str); //返回["test"]
reg.exec(str); //返回["tesa"]
reg.exec(str); //返回null

3. m的意思是指让^和$匹配行首和行尾

不加m

reg = /^b[ac]/g;
str=’ba.sinnbcsohu’;
reg.exec(str); //返回["ba"]
reg.exec(str); //返回null

加上m

reg = /^b[ac]/g;
str=’ba.sinnbcsohu’;
reg.exec(str); //返回["ba"]
reg.exec(str); //返回["bc"]
reg.exec(str); //返回null

正则的常用方法:

1. exec方法

result = reg.exec(str)
//返回的result是一个类数组的对象,如果在chrome的console里看到是数组,其实使用for in可以得到另外两个只读属性index, input
for(a in result) console.log(a + “:” + result[a]);

结果如下:

0:tESt
index:0
input:tEStab
result.input存放匹配的原始字符串,result.index是当前匹配的索引,其作用是当我们使用了g修饰符时,它是多次执行reg.exec(str)的依据;数据里依次存放匹配到的字符串,和正则中小括号匹配的分组数据,如:
reg = /tes(t)/;
str = ‘testab’;
reg.exec(str);//返回["test", "t"]
exec方法也同样影响RegExp(稍后介绍)

2. test方法

reg.test(str)
//测试是否匹配成功,若成功返回true,否则返回false。跟exec一样,其也返回结果,存放在RegExp.$*几个变量中,其中RegExp.$input, RegExp.$_表示输入字符串,而RegExp.$1 – RegExp.$9表示匹配的变量

3. RegExp对象

如果直接使用console.log(RegExp),function RegExp() { [native code] },这也是正则的构成方法,使用for in来看一下其中的变量:

reg = /tes(t)/;
str = ‘atestb’;
reg.exec(str);//结果为 ["test']
for(name in RegExp) console.log(name + “:” + RegExp[name]);

结果如下:

input:atestb
multiline:false
lastMatch:test
lastParen:t
leftContext:a
rightContext:b
$1:t
$2:
$3:
$4:
$5:
$6:
$7:
$8:
$9:

其中RegExp.input = RegExp.$input = RegExp.$_,RegExp.multiline表示m标签符是否被设置

总结

当然,能用正则的方法还有String对象的match, replace, split, search等方法,有时间再做一次介绍。这里只是介绍其使用方法,对于如果写正则表达式没有深入讲,内容还有很多
推荐阅读:JavaScript正则表达式

如何使用正则配对查找html中的标签

找了好久,以下的可以使用:

/<script[^>]*>.*?<\/script>/ig

基于javascript的正则,如果使用其他标签可以将其中的”script”进行替换。

有几点需要说明的

1、*?表示非贪心模式,如果是贪心模式下,则会将div中的内容也会替换进去。

<script type=”text/javascritp”>
//code1 at here…
</script>

<div>some other tag</div>

<script type=”text/javascritp”>
//code2 at here…
</script>

2、”<\/script>”中的”\“不可少,不然也会出现错误,当然在js中,/是正则的分界符,但在notepad++中,这个符号也不可少,不知道,虽然正则书上只对以下字符规定了转义要求:

$()*+.?[\^{|

js 实现首行缩进

在html的样式控制里面,一直没有什么好的方法实现段落的首行缩进,下面是我使用正则实现段落首行缩进的代码:

html = " " + html;
html = html.replace(/<br[^>]*>/ig, "<br /> ");

很简单,只要将文中的br或都p前面增加两个中文全角空白字符就行了。

css的text-indent可以实现p中同样的效果,但在br中却不能实现缩进,而且在IE6下显示也有些问题,如果对于浏览器兼容性不高的话,可以选择这种方式,否则的话,上面增加两个全角空白是比较好的一种方式

浏览器本地存储——从新浪微博得到的启示

偶然间发现如果输入一句话到微博文本框中,即使不提交,也会被持久化——你关掉浏览器再打开,还看到你写的东西,即使你退回再登录也是能够看到你写的东西;

image

但是在cookie里面并不能找到这句话,这就推翻了我对浏览器本地化只能存储到cookie中的认识;那么我想会不会ajax已经同步到了后台,由于存储的速度是立即的,使用ajax就会跟后台代码频繁交互,会拖累整个系统,所以我认为没有,而监控的结果也证明了我的想法;如在chrome里面输入一句话,打开IE登录同样的账号后就不会看到那句话;说明这句话还是持久化到本地了;

image

后来分析新浪的代码,得知,除了cookie,新的html5本地存储支持的更多,如localStorage。而新浪代码中用了三种方式:localStroage, IE的userData和cookie;而在chrome下显示locaStorage,证实了我的想法;

image

代码如下:

//storage
App.storage = (function() {
var a = window.localStorage;
if (window.ActiveXObject) {
store = document.documentElement;
STORE_NAME = “localstorage”;
try {
store.addBehavior(“#default#userdata”);
store.save(STORE_NAME)
} catch(b) {}
return {
set: function(g, h) {
try {
store.setAttribute(g, h);
store.save(STORE_NAME)
} catch(j) {}
},
get: function(g) {
try {
store.load(STORE_NAME);
return store.getAttribute(g)
} catch(h) {
return “”
}
},
del: function(g) {
try {
store.removeAttribute(g);
store.save(STORE_NAME)
} catch(h) {}
}
}
} else {
if (a) {
return {
get: function(g) {
return a.getItem(g) == null ? null: unescape(a.getItem(g))
},
set: function(g, h, j) {
a.setItem(g, escape(h))
},
del: function(g) {
a.removeItem(g)
},
clear: function() {
a.clear()
},
getAll: function() {
var g = a.length,
j = null,
m = [];
for (var h = 0; h < g; h++) {
j = a.key(h),
m.push(j + “=” + this.getKey(j))
}
return m.join(“; “)
}
}
} else {
return {
get: function(n) {
var j = document.cookie.split(“; “),
h = j.length,
g = [];
for (var m = 0; m < h; m++) {
g = j[m].split(“=”);
if (n === g[0]) {
return unescape(g[1])
}
}
return null
},
set: function(g, h, j) {
if (! (j && typeof j === date)) {
j = new Date(),
j.setDate(j.getDate() + 1)
}
document.cookie = g + “=” + escape(h) + “; expires=” + j.toGMTString()
},
del: function(g) {
document.cookie = g + “=”; expires=Fri, 31 Dec 1999 23:59:59 GMT;”
},
clear: function() {
var j = document.cookie.split(“; “),
h = j.length,
g = [];
for (var m = 0; m < h; m++) {
g = j[m].split(“=”);
this.deleteKey(g[0])
}
},
getAll: function() {
return unescape(document.cookie.toString())
}
}
}
}
}

分享工具栏分析

有时候自己想说能够写任何能够实现的效果,但自己写代码最终的结果是费时费力;好处也是易见的,能够自己控制代码,清楚代码格式;

今天一是由于时间太急,二是别人已经找到了一个效果,需要在此基础上做一些调整,然后再加个新的工具栏,于是就想在其基础上修改,颇费了一番功夫,最终的结果也是差强人意……

js代码的压缩我有一定的了解,但像这种压缩方式目前为止只是见过,具体怎么样实现的还真不是太知道;不知道怎么实现压缩的不要紧,关键是能不能恢复成一个可以理解的方式,这个时候chrome的控制台就发挥了其作用;

image

注意看下面这句,eval要的是一个字符器,那么其function返回的p也就是相应的字符器,如果把第一个function返回的字符串提取出来则就是我们想要的东西,将eval后面的所有代码拷贝到chrome的控制台执行,得到我们认可的压缩代码;

image

然后去http://www.css88.com/tool/js_beautify/ 把压缩的代码格式化一下就可以得到如下代码,下面的代码就可以看的懂了,虽然变量还是abcd这些字母来代替,并且可以手动修改了。

他的代码可以学习的地方有如下几个:

  • 代码压缩
    他们的代码压缩方式是我经常见到但又不知道怎么去弄的方式,把关键字都提取到数组中去了,这样的解码难度确实高了不少
  • 良好的代码风格
    里面的所有私有成员都以“_”开头,一目了然
  • 代码配置化
    有自己的数据配置方式,在不改动代码的方式下实现灵活改变

但也有很大的问题在里面,这也是造成我后面扩展困难,不得不重新复制出另一套代码:

  • 全局执行方式
    现在成熟的写法很少进行全局执行,而它的所有js文件都是全局执行
  • 没有对多侧边栏进行考虑
    也许他们本就不需要考虑多个边栏,所以就没有做这方面的考虑
  • 多js加载,虽然实现了一个js里面加载多个其他js,但也造成了速度慢的等问题;
  • 可定制化差;无论从排序还是图标,都没有让人可定制化的地方

if (!window._jiathis_r) {
    var JIATHIS_CONFIGS = {
        webhost: "http://www.jiathis.com",
        lhost: "http://l.jiathis.com",
        codehost: "",
        sc: true,
        uid: 0,
        type: "right",
        move: 1,
        btn: "",
        ckprefix: "jt_",
        jtcbk: "jtss",
        jtck: "",
        custom: [],
        servicelist: {
            ‘jt_ishare’: ‘一键分享,yjfx’,
            ‘jt_copy’: ‘复制网址,fzwz’,
            ‘jt_fav’: ‘收藏夹,scj’,
            ‘jt_print’: ‘打印,dy’,
            ‘jt_email’: ‘邮件,yj’,
            ‘jt_qzone’: ‘QQ空间,qqkj,sns.qzone.qq.com’,
            ‘jt_tsina’: ‘新浪微博,xlwb,weibo.com’,
            ‘jt_tqq’: ‘腾讯微博,txwb,t.qq.com’,
            ‘jt_tsohu’: ‘搜狐微博,shwb,t.sohu.com’,
            ‘jt_t163’: ‘网易微博,wywb,t.163.com’,
            ‘jt_renren’: ‘人人网,rrw,www.renren.com’,
            ‘jt_kaixin001’: ‘开心网,kxw,www.kaixin001.com’,
            ‘jt_sohu’: ‘搜狐白社会,shbsh,bai.sohu.com’,
            ‘jt_taobao’: ‘淘江湖,tjh,i.taobao.com’,
            ‘jt_douban’: ‘豆瓣,db,www.douban.com’,
            ‘jt_xiaoyou’: ‘朋友网,pyw,share.pengyou.com’,
            ‘jt_mop’: ‘猫扑推客,mptk,tk.mop.com’,
            ‘jt_baidu’: ‘百度搜藏,bdsc,cang.baidu.com’,
            ‘jt_tieba’: ‘百度贴吧,bdtb,tieba.baidu.com’,
            ‘jt_tianya’: ‘天涯社区,tysq,my.tianya.cn’,
            ‘jt_feixin’: ‘飞信,fx,space.feixin.10086.cn’,
            ‘jt_qu1’: ‘趣一网,qyw,www.qu1.com’,
            ‘jt_tifeng’: ‘凤凰微博,fhwb,t.ifeng.com’,
            ‘jt_youshi’: ‘优士网,ysw,www.ushi.cn’,
            ‘jt_fanfou’: ‘饭否,ff,fanfou.com’,
            ‘jt_51′: ’51社区,51sq,home.51.com’,
            ‘jt_google’: ‘谷歌,gg’,
            ‘jt_buzz’: ‘谷歌Buzz,ggbuzz’,
            ‘jt_youdao’: ‘有道书签,ydsq,shuqian.youdao.com’,
            ‘jt_qq’: ‘QQ书签,qqsq,shuqian.qq.com’,
            ‘jt_msn’: ‘MSN,msn’,
            ‘jt_sina’: ‘新浪vivi,xlvivi,vivi.sina.com.cn’,
            ‘jt_huaban’: ‘花瓣网,hbw,huaban.com’,
            ‘jt_ifensi’: ‘粉丝网,fsw,cyworld.ifensi.com’,
            ‘jt_115’: ‘115收藏,115sc’,
            ‘jt_hi’: ‘百度空间,bdkj,apps.hi.baidu.com’,
            ‘jt_gmail’: ‘Gmail邮箱,gmailyx,mail.google.com’,
            ‘jt_hotmail’: ‘Hotmail邮箱,hotmailyx’,
            ‘jt_ymail’: ‘Yahoo! mail,yahoo! mail’,
            ‘jt_hexun’: ‘和讯,hx,bookmark.hexun.com’,
            ‘jt_139mail’: ‘139邮箱,139yx’,
            ‘jt_189mail’: ‘189邮箱,189yx’,
            ‘jt_i139’: ‘手机,sj’,
            ‘jt_189cn’: ‘天翼社区,tysq,club.189.cn’,
            ‘jt_139’: ‘139说客,139sk,shequ.10086.cn’,
            ‘jt_tpeople’: ‘人民微博,rmwb,t.people.com.cn’,
            ‘jt_cnfol’: ‘中金微博,zjwb’,
            ‘jt_googlereader’: ‘谷歌阅读,ggyd’,
            ‘jt_translate’: ‘谷歌翻译,ggfy’,
            ‘jt_tuita’: ‘推他,tt,www.tuita.com’,
            ‘jt_sdonote’: ‘麦库记事,mkjs’,
            ‘jt_digu’: ‘嘀咕网,dgw,digu.com’,
            ‘jt_zhuaxia’: ‘抓虾,zx’,
            ‘jt_xianguo’: ‘鲜果,xg’,
            ‘jt_zuosa’: ‘做啥,zs,zuosa.com’,
            ‘jt_ganniu’: ‘赶牛网,gnw,www.ganniu.com’,
            ‘jt_42qu’: ’42区,42q’,
            ‘jt_miliao’: ‘米聊,ml’,
            ‘jt_woshao’: ‘我烧网,wsw,woshao.com’,
            ‘jt_qingsina’: ‘新浪轻博,xlqb,qing.weibo.com’,
            ‘jt_chinanews’: ‘中新网,zxw’,
            ‘jt_gmw’: ‘光明网,gmw’,
            ‘jt_renjian’: ‘人间网,rjw,renjian.com’,
            ‘jt_leihou’: ‘雷猴网,lhw,leihou.com’,
            ‘jt_thexun’: ‘和讯微博,hxwb,t.hexun.com’,
            ‘jt_dream163’: ‘梦幻人生,mhrs,dream.163.com’,
            ‘jt_masar’: ‘玛撒网,msw’,
            ‘jt_renmaiku’: ‘人脉库,rmk,www.renmaiku.com’,
            ‘jt_fb’: ‘Facebook,facebook,www.facebook.com’,
            ‘jt_twitter’: ‘Twitter,twitter,t.co’,
            ‘jt_tumblr’: ‘Tumblr,tumblr,www.tumblr.com’,
            ‘jt_reddit’: ‘Reddit,reddit’,
            ‘jt_instapaper’: ‘Instapaper,instapaper,www.instapaper.com’,
            ‘jt_readitlater’: ‘Read It Later,readitlater,readitlaterlist.com’,
            ‘jt_diglog’: ‘奇客发现,qkfx,www.diglog.com’,
            ‘jt_wealink’: ‘若邻网,rlw’,
            ‘jt_bietiao’: ‘别挑,bt,i.bietiao.com’,
            ‘jt_leshou’: ‘乐收,ls,site.leshou.com’,
            ‘jt_myspacecn’: ‘聚友网,jyw,blog.myspace.cn’,
            ‘jt_tongxue’: ‘同学网,txw’,
            ‘jt_waakee’: ‘挖客网,wkw’,
            ‘jt_cyzone’: ‘创业邦,cyb,u.cyzone.cn’,
            ‘jt_99earth’: ‘救救地球,jjdq’,
            ‘jt_chouti’: ‘抽屉网,ctw’,
            ‘jt_dig24’: ‘递客网,dkw,www.dig24.cn’,
            ‘jt_douban9dian’: ‘豆瓣9点,db9d,9.douban.com’,
            ‘jt_hemidemi’: ‘黑米书签,hmsq,www.hemidemi.com’,
            ‘jt_meilishuo’: ‘美丽说,mls’,
            ‘jt_mogujie’: ‘蘑菇街,mgj,mogujie.cn’,
            ‘jt_tianji’: ‘天际网,tjw,app.tianji.com’,
            ‘jt_poco’: ‘Poco网,pocow,my.poco.cn’,
            ‘jt_baohe’: ‘宝盒网,bhw,www.baohe.com’,
            ‘jt_yijee’: ‘易集网,yjw,www.yijee.com’,
            ‘jt_pdfonline’: ‘Pdf在线转换,pdfzxzh’,
            ‘jt_printfriendly’: ‘友好打印,yhdy’,
            ‘jt_w3c’: ‘W3c验证,w3cyz’,
            ‘jt_bitly’: ‘Bit.ly,bitly,bit.ly’,
            ‘jt_digg’: ‘Digg,digg,digg.com’,
            ‘jt_mailru’: ‘Mail.ru,mail.ru’,
            ‘jt_diigo’: ‘Diigo,diigo’,
            ‘jt_evernote’: ‘EverNote,evernote’,
            ‘jt_friendfeed’: ‘FriendFeed,friendfeed’,
            ‘jt_myspace’: ‘Myspace,myspace’,
            ‘jt_linkedin’: ‘LinkedIn,linkedin’,
            ‘jt_mixx’: ‘Mixx,mixx’,
            ‘jt_netlog’: ‘NetLog,netlog’,
            ‘jt_netvibes’: ‘Netvibes,netvibes’,
            ‘jt_phonefavs’: ‘Phonefavs,phonefavs’,
            ‘jt_pingfm’: ‘Ping.fm,ping.fm’,
            ‘jt_plaxo’: ‘Plaxo,plaxo’,
            ‘jt_delicious’: ‘Delicious,delicious,www.delicious.com’,
            ‘jt_wong’: ‘Mister Wong,misterwong’,
            ‘jt_stumbleupon’: ‘Stumbleupon,stumbleupon’,
            ‘jt_plurk’: ‘Plurk,plurk’,
            ‘jt_funp’: ‘Funp,funp’,
            ‘jt_myshare’: ‘Myshare,myshare’,
            ‘jt_fwisp’: ‘Fwisp,fwisp’
        }
    };
    (function() {
        try {
            var g = jiathis_config || {}
        } catch(e) {
            var g = {}
        };
        var j = document.getElementsByTagName(‘script’);
        for (var i = 0, ci; ci = j[i++];) {
            if (/jiathis/.test(ci.src)) {
                JIATHIS_CONFIGS.codehost = ci.src.substring(0, ci.src.lastIndexOf("/"));
                ci.src.replace(/(type|btn|move|uid)=([^&]+)/g,
                function(a, p, v) {
                    JIATHIS_CONFIGS[p] = v
                })
            }
        }
        var d = document,
        isStrict = d.compatMode == "CSS1Compat",
        dd = d.documentElement,
        db = d.body,
        m = Math.max,
        na = navigator.userAgent.toLowerCase(),
        ie = !!d.all,
        head = d.getElementsByTagName(‘head’)[0] || dd,
        wlh = window.location.host,
        _imgw = typeof(g.imageWidth) == "number" ? g.imageWidth: 26,
        _ckpre = JIATHIS_CONFIGS.ckprefix,
        _lists = JIATHIS_CONFIGS.servicelist,
        _ref = d.referrer,
        _reced = false,
        _mt = typeof(g.marginTop) == "number" ? g.marginTop: 150,
        getWH = function() {
            return {
                h: (isStrict ? dd: db).clientHeight,
                w: (isStrict ? dd: db).clientWidth
            }
        },
        getS = function() {
            return {
                t: m(dd.scrollTop, db.scrollTop),
                l: m(dd.scrollLeft, db.scrollLeft)
            }
        },
        creElm = function(o, t, a) {
            var b = d.createElement(t || ‘div’);
            for (var p in o) {
                p == ‘style’ ? b[p].cssText = o[p] : b[p] = o[p]
            }
            return (a || db).insertBefore(b, (a || db).firstChild)
        },
        _sc = function(a, b, c) {
            var d = new Date();
            d.setTime(d.getTime() + c * 1000);
            document.cookie = a + "=" + escape(b) + (c ? ";expires=" + d.toGMTString() : "") + ";path=/"
        },
        _gc = function(a) {
            var b = document.cookie;
            var c = b.indexOf(a + "=");
            if (c != -1) {
                c += a.length + 1;
                var d = b.indexOf(";", c);
                if (d == -1) {
                    d = b.length
                }
                return unescape(b.substring(c, d))
            }
            return ""
        },
        _rec = function(e) {
            if (!_reced) {
                if ( !! e.origin && e.origin.slice( – 12) == ".jiathis.com") {
                    if (e.data && e.data != "FALSE") {
                        JIATHIS_CONFIGS.jtck = e.data
                    }
                }
                _req();
                _reced = true
            }
        },
        _custom = function() {
            try {
                var a = jiathis_config || {}
            } catch(e) {
                var a = {}
            };
            var u = a.services_custom;
            if (u) {
                if (! (u instanceof Array)) {
                    u = [u]
                }
                for (var b = 0; b < u.length; b++) {
                    var c = u[b];
                    if (c.name && c.icon && c.url) {
                        c.code = c.url = c.url.replace(/ /g, "");
                        c.code = c.code.split("//").pop().split("?").shift().split("/").shift().toLowerCase();
                        JIATHIS_CONFIGS.custom[c.code] = c;
                        JIATHIS_CONFIGS.servicelist[_ckpre + c.code] = c.name + ‘,’ + c.code + ‘,’ + c.code
                    }
                }
            }
        },
        _req = function() {
            try {
                var a = jiathis_config || {}
            } catch(e) {
                var a = {}
            };
            var b = a.shareImg || {};
            b.showType && creElm({
                src: JIATHIS_CONFIGS.codehost + "/plugin.shareimg.js",
                charset: "utf-8"
            },
            "script", head);
            var c, s, E = encodeURIComponent,
            o = _grf(_ref),
            T = document.title || "",
            Y = window.location.href || "",
            an = Y ? Y.indexOf(JIATHIS_CONFIGS.jtcbk) : -1,
            d1 = _gd(o.host),
            d2 = _gd(Y),
            q = null,
            f = (d1 && d2 && d1 == d2) ? false: true;
            if (an > -1) {
                c = Y.substr(an);
                q = c.split("#").pop().split("-").pop().split("=").pop();
                q = _lists[_ckpre + q] ? q: ”
            }
            q = (!q && o.webid) ? o.webid: q;
            if (q && f) {
                s = ‘rsc=’ + q + ‘&rnm=’ + parseInt(JIATHIS_CONFIGS.uid) + ‘&rfh=’ + E(o.host) + ‘&rfp=’ + E(o.path) + ‘&pre=’ + E(Y) + ‘&tit=’ + escape(T);
                (new Image).src = JIATHIS_CONFIGS.lhost + "/l.gif?" + s
            }
        },
        _gd = function(o) {
            var d = null;
            if (o) {
                d = o.split(".").slice( – 2).join(".");
                d = (d == "com.cn") ? o.split(".").slice( – 3).join(".") : d;
                d = d.split("/").shift()
            }
            return d
        },
        _grf = function(r) {
            var h = "",
            p = "",
            q = "",
            m;
            if (r.match(/(?:[a-z]\:\/\/)([^\/\?]+)(.*)/gi)) {
                h = RegExp.$1;
                p = RegExp.$2;
                h = h ? h: "";
                p = p ? p: "";
                if (h) {
                    for (var k in _lists) {
                        m = _lists[k].split(‘,’);
                        if (m[2] && m[2] == h) {
                            q = k.slice(3);
                            break
                        }
                    }
                }
            }
            return {
                host: h,
                path: p,
                webid: q
            }
        },
        jiathis_utility_ifr = !!window.postMessage ? creElm({
            style: "display:none;",
            frameBorder: 0,
            src: JIATHIS_CONFIGS.codehost + "/jiathis_utility.html"
        },
        "iframe") : null,
        div,
        div1 = creElm({
            id: ‘ckepop’,
            style: "height:auto;position:absolute;z-index:100000000;display:none;top:50%;left:50%;overflow:auto;"
        }),
        inputTimer,
        list,
        clist,
        as,
        texts = {},
        script,
        timerover,
        timerout,
        timerloop,
        loop = function() {
            var t = 1000,
            st = getS().t,
            c,
            c = st – div.offsetTop + _mt;
            c != 0 && (div.style.top = div.offsetTop + c / 10 + ‘px’, t = 10);
            timerloop = setTimeout(loop, t)
        },
        iframe = creElm({
            style: ‘position:’ + (/firefox/.test(na) ? ‘fixed’: ‘absolute’) + ‘;display:none;’,
            frameBorder: 0
        },
        ‘iframe’),
        dsp = (_gc("jiathis_off") == ‘yes’) ? ‘display:none;’: ”,
        rpic = g.imageUrl || (JIATHIS_CONFIGS.codehost + "/images/" + (JIATHIS_CONFIGS.btn || ‘r.gif’)),
        lpic = g.imageUrl || (JIATHIS_CONFIGS.codehost + "/images/" + (JIATHIS_CONFIGS.btn || ‘l.gif’)),
        hidemore = g.hideMore || false,
        ckjs = hidemore ? "": " onclick=’$CKE.center(this)’",
        flag = ((!isStrict && /msie /i.test(na)) || (JIATHIS_CONFIGS.move == 1 || /msie 6/i.test(na)));
        div = creElm({
            id: ‘ckepop’,
            style: dsp + "height:auto;position:" + (flag ? ‘absolute’: ‘fixed’) + ";z-index:100000000;top:" + (flag ? ‘0’: _mt + ‘px’) + ";" + (JIATHIS_CONFIGS.type == ‘right’ ? "right:0;overflow:hidden;width:" + _imgw + "px;": "left:-242px;overflow:auto;"),
            innerHTML: JIATHIS_CONFIGS.type == ‘right’ ? "<table cellPadding=0 cellSpacing=0><tbody style=’background:transparent’><tr><td style=’background:transparent’><img src=’" + rpic + "’ style=’cursor:pointer;’ onmouseover=’$CKE.over()’" + ckjs + " /></td><td><div></div></td></tr></tbody></table>": "<table cellPadding=0 cellSpacing=0><tbody style=’background:transparent’><tr><td><div></div></td><td><img src=’" + lpic + "’ style=’cursor:pointer;’ onmouseover=’$CKE.over()’" + ckjs + " /></td></tr></tbody></table>"
        });
        window._jiathis_r = div;
        _custom();
        creElm({
            href: JIATHIS_CONFIGS.codehost + ‘/css/jiathis_share.css’,
            rel: ‘stylesheet’,
            type: ‘text/css’
        },
        ‘link’);
        d.write(‘<script src="’ + JIATHIS_CONFIGS.codehost + ‘/ckepop.js" charset="utf-8"></script><script src="’ + JIATHIS_CONFIGS.codehost + ‘/ckecenterpop.js" charset="utf-8"></script>’);
        $CKE = {
            sers: "",
            pop: div.getElementsByTagName(‘div’)[0],
            centerpop: div1,
            disappear: function(a) {
                var b = window.event || a,
                t = b.srcElement || b.target,
                contain = div1.contains ? div1.contains(t) : !!(div1.compareDocumentPosition(t) & 16),
                contain1 = div.contains ? div.contains(t) : !!(div.compareDocumentPosition(t) & 16);
                if (!contain && !contain1) {
                    iframe.style.display = div1.style.display = ‘none’
                }
            },
            over: JIATHIS_CONFIGS.type == ‘right’ ?
            function() {
                if (div.offsetWidth > _imgw) {
                    return
                }
                clearTimeout(timerloop);
                clearInterval(timerout);
                div.style.cssText += ";width:" + _imgw + "px;left:" + (getWH() – _imgw) + "px";
                var t = 10,
                tmp = 0,
                step = this.pop.offsetWidth / 55;
                timerover = setInterval(function() {
                    if (t == 0) {
                        clearInterval(timerover);
                        flag && loop()
                    } else {
                        var n = Math.round(step * t–);
                        div.style.left = div.offsetLeft – n + ‘px’;
                        div.style.width = div.offsetWidth + n + ‘px’
                    }
                    div.style.zIndex = 100000000
                },
                10)
            }: function() {
                clearTimeout(timerloop);
                clearInterval(timerout);
                clearInterval(timerover);
                var t = 10,
                tmp = 0,
                step = Math.abs(div.offsetLeft / 55);
                timerover = setInterval(function() {
                    if (t == 0) {
                        clearInterval(timerover);
                        flag && loop()
                    } else {
                        var n = Math.round(step * t–);
                        div.style.left = div.offsetLeft + n + ‘px’
                    }
                    div.style.zIndex = 100000000
                },
                10)
            },
            out: JIATHIS_CONFIGS.type == ‘right’ ?
            function() {
                $CKE.cancelClose();
                if (div.offsetWidth > $CKE.pop.offsetWidth) {
                    clearInterval(timerover);
                    clearTimeout(timerloop);
                    div.style.cssText += ";width:" + ($CKE.pop.offsetWidth + _imgw) + "px;left:" + (getWH() – _imgw – $CKE.pop.offsetWidth) + "px";
                    var t = 10,
                    tmp = 0,
                    step = (div.offsetWidth – _imgw) / 55;
                    timerout = setInterval(function() {
                        if (t == 0) {
                            clearInterval(timerout);
                            div.style.left = ”;
                            flag && loop()
                        } else {
                            var n = Math.round(step * t–);
                            div.style.width = div.offsetWidth – n < _imgw ? _imgw: div.offsetWidth – n + ‘px’;
                            div.style.left = div.offsetLeft + n + ‘px’
                        }
                        div.style.zIndex = 100000000
                    },
                    10)
                }
            }: function() {
                $CKE.cancelClose();
                clearInterval(timerover);
                clearInterval(timerout);
                clearTimeout(timerloop);
                var t = 10,
                tmp = 0,
                step = Math.abs((div.offsetLeft + 242) / 55);
                timerout = setInterval(function() {
                    if (t == 0) {
                        clearInterval(timerout);
                        div.style.left = ‘-242px’;
                        flag && loop()
                    } else {
                        var n = Math.round(step * t–);
                        div.style.left = div.offsetLeft – n + ‘px’
                    }
                    div.style.zIndex = 100000000
                },
                10)
            },
            center: function(a) {
                if (a) {
                    db.style.position = ‘static’;
                    var b = getS();
                    div1.style.display = "block";
                    div1.style.margin = ( – div1.offsetHeight / 2 + b.t) + "px " + ( – div1.offsetWidth / 2 + b.l) + "px";
                    list = d.getElementById(‘ckelist’);
                    clist = list.cloneNode(true);
                    as = clist.getElementsByTagName(‘input’);
                    for (var i = 0, ci; ci = as[i++];) {
                        texts[ci.value] = ci.parentNode
                    }
                    with(iframe.style) {
                        left = top = ‘50%’;
                        width = div1.offsetWidth + ‘px’;
                        height = div1.offsetHeight + ‘px’;
                        margin = div1.style.margin;
                        display = ‘block’
                    }
                }
            },
            choose: function(o) {
                clearTimeout(inputTimer);
                inputTimer = setTimeout(function() {
                    var s = o.value.replace(/^\s+|\s+$/, ”),
                    frag = d.createDocumentFragment();
                    for (var p in texts) {
                        eval("var f = /" + (s || ‘.’) + "/ig.test(p)"); !! texts[p].cloneNode && (f && frag.appendChild(texts[p].cloneNode(true)))
                    }
                    list.innerHTML = ”;
                    list.appendChild(frag)
                },
                100)
            },
            centerClose: function() {
                iframe.style.display = div1.style.display = ‘none’
            },
            shareClose: function() {
                var a = d.getElementById("jiathis_sers");
                if (a) {
                    if (!$CKE.sers) {
                        $CKE.sers = a.innerHTML
                    }
                    var b = ‘<div style="margin:10px 5px 10px 10px;font-size:14px;">’;
                    b += ‘<p style="font-weight:normal;margin-bottom:10px;">关闭分享按钮?</p>’;
                    b += ‘<p style="color:#666;font-size:12px;font-weight:normal;margin-bottom:10px;">关闭后,该分享按钮将不再出现,您也无法使用分享到功能,确定吗?</p>’;
                    b += ‘<p style="background:none repeat scroll 0 0 #FEFFDB;border:1px solid #FFDDB3;padding:10px 15px;width:185px;"><a href="javascript:;" onclick="$CKE.doClose();return false;"><u style="font-weight:normal;">确定</u></a>&nbsp;&nbsp;<a href="javascript:;" onclick="$CKE.cancelClose();return false;"><u style="font-weight:normal;">取消</u></a></p>’;
                    b += ‘</div>’;
                    a.innerHTML = b
                }
            },
            doClose: function() {
                iframe.style.display = div1.style.display = div.style.display = ‘none’;
                _sc("jiathis_off", "yes", 86400)
            },
            cancelClose: function() {
                var a = d.getElementById("jiathis_sers");
                if ($CKE.sers && a) {
                    a.innerHTML = $CKE.sers;
                    $CKE.sers = ”
                }
            },
            open: function(A) {
                creElm({
                    src: A,
                    charset: "utf-8"
                },
                "script", head)
            },
            fireEvent: function(F, O) {
                if (F) {
                    F = typeof(F) == "function" ? F: eval(F);
                    F(O)
                }
            }
        };
        if ( !! window.addEventListener) { !! window.addEventListener && window.addEventListener("message", _rec, false)
        } else {
            if ( !! window.postMessage) { ( !! window.attachEvent && window.attachEvent("onmessage", _rec))
            } else {
                _req()
            }
        }
        if (ie) {
            div.onmouseleave = $CKE.out;
            d.attachEvent("onclick", $CKE.disappear)
        } else {
            div.onmouseout = function(e) {
                try {
                    var p = (this.compareDocumentPosition(e.relatedTarget) == 20)
                } catch(e) {
                    var p = false
                }; ! (this === e.relatedTarget || (this.contains ? this.contains(e.relatedTarget) : p)) && $CKE.out.call(this)
            };
            d.addEventListener("click", $CKE.disappear, false)
        };
        flag && loop()
    })();
    function jiathis_sendto(a) {
        try {
            var b = jiathis_config || {}
        } catch(e) {
            var b = {}
        };
        var c = encodeURIComponent,
        cu = JIATHIS_CONFIGS.custom[a] || {},
        U = String(b.url || document.location),
        W = "?webid=" + a,
        G = "&url=" + c(U),
        T = "&title=" + c(b.title || document.title),
        S = b.summary ? "&summary=" + c(b.summary) : "",
        F = JIATHIS_CONFIGS.uid ? "&uid=" + parseInt(JIATHIS_CONFIGS.uid) : "",
        E = b.data_track_clickback ? "&jtss=1": "",
        K = (b.appkey && b.appkey[a]) ? "&appkey=" + b.appkey[a] : "",
        P = b.pic ? "&pic=" + c(b.pic) : "",
        R = (b.ralateuid && b.ralateuid[a]) ? "&ralateuid=" + b.ralateuid[a] : "",
        Q = (b.evt && b.evt[‘share’]) ? b.evt[‘share’] : null,
        A = ‘http://s.jiathis.com/’,
        X = (cu.name && cu.url) ? "&acn=" + c(cu.name) + "&acu=" + c(cu.url) : "",
        B = A + W + G + T + F + E + K + P + R + S + X;
        if (a == ‘copy’ || a == ‘fav’ || a == ‘print’) {
            $CKE.open(B);
            if (a == ‘copy’) {
                jiathis_copyUrl()
            } else if (a == ‘fav’) {
                jiathis_addBookmark()
            } else {
                window.print()
            }
        } else {
            window.open(B, ”)
        }
        $CKE.fireEvent(Q, {
            type: ‘share’,
            data: {
                service: a,
                url: U
            }
        });
        return false
    }
    function jiathis_addBookmark() {
        try {
            var d = jiathis_config || {}
        } catch(e) {
            var d = {}
        };
        var a = d.title || document.title;
        var b = d.url || parent.location.href;
        var c = window.sidebar;
        if (c && !!c.addPanel) {
            c.addPanel(a, b, "")
        } else if (document.all) {
            window.external.AddFavorite(b, a)
        } else {
            alert(‘请按 Ctrl + D 为你的浏览器添加书签!’)
        }
    }
    function jiathis_copyUrl() {
        try {
            var d = jiathis_config || {}
        } catch(e) {
            var d = {}
        };
        var a = d.url || this.location.href;
        var b = d.title || document.title;
        var c = b + " " + a;
        var f = navigator.userAgent.toLowerCase();
        var g = f.indexOf(‘opera’) != -1 && opera.version();
        var h = (f.indexOf(‘msie’) != -1 && !g) && f.substr(f.indexOf(‘msie’) + 5, 3);
        if (h) {
            clipboardData.setData(‘Text’, c);
            alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友!")
        } else if (prompt(‘你使用的是非IE核心浏览器,请按下 Ctrl+C 复制代码到剪贴板’, c)) {
            alert(‘复制成功,请粘贴到你的QQ/MSN上推荐给你的好友!’)
        } else {
            alert(‘目前只支持IE,请复制地址栏URL,推荐给你的QQ/MSN好友!’)
        }
    }
}

抢购火车票

现在说什么都爆弱了,拿到手3到4个程序,最好用的一个绝对是刷票的利器,配合chrome非常的好用;只可惜现在已经不是买票高峰期了,要测试还要再过几天才行。

在开始的时候,我一直想自己写点代码出来抢购火车票;现在的代码分为两种形式:一种是客户端软件;一种是各种浏览器插件(基于js完成的);就我个人而言,比较倾向于后者。加上我发现订票的系统是使用iframe来完成的,这样的情况下,我们很容易将自己的js注入到订票的页面,由于他不会刷新页面,所以整个订票流程只需要注入一次就可以了。

我的想法比较简单,开始的时候,我只想不要让自己的会话丢失。这个后来被证明还是很有用的,因为到开始抢票的时候,你不可能很轻松的登录进去;而我也只是靠这个买到了几张票。但后来抢深圳票的时候出现了问题——订单一直不能提交;开始的时候我没有什么好的办法,只能手动一遍一遍提交,但结果都是失败;后来我就想找一下现在网络上的一些解决方案,看了一些后,才知道,原来现在的订票网站登录验证码有一个bug,我们可以很轻松的绕过这个验证码。当然如果铁道部现在把这个bug给修补上,我们只能再从其他方面着手了;绕过验证码的好处不言而喻,我们不再需要手动一遍遍的查询车票的剩余信息,不需要手动一遍遍的提交订单,还出现各种报错的页面,而我们只需要做的是自动登录后,选后你的车次,剩下的订单提交就交给自动程序来帮你完成;当然最后的订单支付还是要你来的。

抢购火车票的软件肯定会越来越多,也会越来越好用,并且最终都将是免费的;我们要的仅仅是一张火车票……