公司打算进入台湾市场,最近开发了繁体版本的网站,数据库里的信息全是简体,除了网页上固定的文字手动翻译了,文章内容标题都不是繁体。
于是在网上找了一段比较流行的繁简切换的JS实现了,不过后来却发现,有些页面会卡死,根本无法执行下去。弹出信息表明都是这个繁简切换的JS带来的问题。
仔细查看了下,发现原来是这个问题。分享下,也许有不少人遇到类似的问题。
先上代码:
//模仿语言包式的简繁转换功能插件!
var Default_isFT = 0 //默认是否繁体,0-简体,1-繁体
var StranIt_Delay = 50 //翻译延时毫秒(设这个的目的是让网页先流畅的显现出来)
//-------代码开始,以下别改-------
//转换文本
function StranText(txt,toFT,chgTxt)
{
if(txt==""||txt==null)return ""
toFT=toFT==null?BodyIsFt:toFT
if(chgTxt)txt=txt.replace((toFT?"简":"繁"),(toFT?"繁":"简"))
if(toFT){return Traditionalized(txt)}
else {return Simplized(txt)}
}
//转换对象,使用递归,逐层剥到文本
function StranBody(fobj)
{
if(typeof(fobj)=="object"){var obj=fobj.childNodes}
else
{
var tmptxt=StranLink_Obj.innerHTML.toString()
if(tmptxt.indexOf("简")<0)
{
BodyIsFt=1
StranLink_Obj.innerHTML=StranText(tmptxt,0,1)
//StranLink.title=StranText(StranLink.title,0,1)
}
else
{
BodyIsFt=0
StranLink_Obj.innerHTML=StranText(tmptxt,1,1)
//StranLink.title=StranText(StranLink.title,1,1)
}
setCookie(JF_cn,BodyIsFt,7)
var obj=document.body.childNodes
}
for(var i=0;i<obj.length;i++)
{
var OO=obj.item(i)
if("||BR|HR|TEXTAREA|".indexOf("|"+OO.tagName+"|")>0||OO==StranLink_Obj)continue;
if(OO.title!=""&&OO.title!=null)OO.title=StranText(OO.title);
if(OO.alt!=""&&OO.alt!=null)OO.alt=StranText(OO.alt);
if(OO.tagName=="INPUT"&&OO.value!=""&&OO.type!="text"&&OO.type!="hidden")OO.value=StranText(OO.value);
if(OO.nodeType==3){OO.data=StranText(OO.data)}
else StranBody(OO)
}
}
function JTPYStr()
{
return '皑蔼碍爱翱袄奥坝罢摆败颁办绊帮绑镑谤剥饱宝报鲍辈贝钡狈备惫绷笔毕毙闭边编贬变辩辫鳖瘪濒滨宾摈饼拨钵铂驳卜补参蚕残惭惨灿苍舱仓沧厕侧册测层诧搀掺蝉馋谗缠铲产阐颤场尝长偿肠厂畅钞车彻尘陈衬撑称惩诚骋痴迟驰耻齿炽冲虫宠畴踌筹绸丑橱厨锄雏础储触处传疮闯创锤纯绰辞词赐聪葱囱从丛凑窜错达带贷担单郸掸胆惮诞弹当挡党荡档捣岛祷导盗灯邓敌涤递缔点垫电淀钓调迭谍叠钉顶锭订东动栋冻斗犊独读赌镀锻断缎兑队对吨顿钝夺鹅额讹恶饿儿尔饵贰发罚阀珐矾钒烦范贩饭访纺飞废费纷坟奋愤粪丰枫锋风疯冯缝讽凤肤辐抚辅赋复负讣妇缚该钙盖干赶秆赣冈刚钢纲岗皋镐搁鸽阁铬个给龚宫巩贡钩沟构购够蛊顾剐关观馆惯贯广规硅归龟闺轨诡柜贵刽辊滚锅国过骇韩汉阂鹤贺横轰鸿红后壶护沪户哗华画划话怀坏欢环还缓换唤痪焕涣黄谎挥辉毁贿秽会烩汇讳诲绘荤浑伙获货祸击机积饥讥鸡绩缉极辑级挤几蓟剂济计记际继纪夹荚颊贾钾价驾歼监坚笺间艰缄茧检碱硷拣捡简俭减荐槛鉴践贱见键舰剑饯渐溅涧浆蒋桨奖讲酱胶浇骄娇搅铰矫侥脚饺缴绞轿较秸阶节茎惊经颈静镜径痉竞净纠厩旧驹举据锯惧剧鹃绢杰洁结诫届紧锦仅谨进晋烬尽劲荆觉决诀绝钧军骏开凯颗壳课垦恳抠库裤夸块侩宽矿旷况亏岿窥馈溃扩阔蜡腊莱来赖蓝栏拦篮阑兰澜谰揽览懒缆烂滥捞劳涝乐镭垒类泪篱离里鲤礼丽厉励砾历沥隶俩联莲连镰怜涟帘敛脸链恋炼练粮凉两辆谅疗辽镣猎临邻鳞凛赁龄铃凌灵岭领馏刘龙聋咙笼垄拢陇楼娄搂篓芦卢颅庐炉掳卤虏鲁赂禄录陆驴吕铝侣屡缕虑滤绿峦挛孪滦乱抡轮伦仑沦纶论萝罗逻锣箩骡骆络妈玛码蚂马骂吗买麦卖迈脉瞒馒蛮满谩猫锚铆贸么霉没镁门闷们锰梦谜弥觅绵缅庙灭悯闽鸣铭谬谋亩钠纳难挠脑恼闹馁腻撵捻酿鸟聂啮镊镍柠狞宁拧泞钮纽脓浓农疟诺欧鸥殴呕沤盘庞国爱赔喷鹏骗飘频贫苹凭评泼颇扑铺朴谱脐齐骑岂启气弃讫牵扦钎铅迁签谦钱钳潜浅谴堑枪呛墙蔷强抢锹桥乔侨翘窍窃钦亲轻氢倾顷请庆琼穷趋区躯驱龋颧权劝却鹊让饶扰绕热韧认纫荣绒软锐闰润洒萨鳃赛伞丧骚扫涩杀纱筛晒闪陕赡缮伤赏烧绍赊摄慑设绅审婶肾渗声绳胜圣师狮湿诗尸时蚀实识驶势释饰视试寿兽枢输书赎属术树竖数帅双谁税顺说硕烁丝饲耸怂颂讼诵擞苏诉肃虽绥岁孙损笋缩琐锁獭挞抬摊贪瘫滩坛谭谈叹汤烫涛绦腾誊锑题体屉条贴铁厅听烃铜统头图涂团颓蜕脱鸵驮驼椭洼袜弯湾顽万网韦违围为潍维苇伟伪纬谓卫温闻纹稳问瓮挝蜗涡窝呜钨乌诬无芜吴坞雾务误锡牺袭习铣戏细虾辖峡侠狭厦锨鲜纤咸贤衔闲显险现献县馅羡宪线厢镶乡详响项萧销晓啸蝎协挟携胁谐写泻谢锌衅兴汹锈绣虚嘘须许绪续轩悬选癣绚学勋询寻驯训讯逊压鸦鸭哑亚讶阉烟盐严颜阎艳厌砚彦谚验鸯杨扬疡阳痒养样瑶摇尧遥窑谣药爷页业叶医铱颐遗仪彝蚁艺亿忆义诣议谊译异绎荫阴银饮樱婴鹰应缨莹萤营荧蝇颖哟拥佣痈踊咏涌优忧邮铀犹游诱舆鱼渔娱与屿语吁御狱誉预驭鸳渊辕园员圆缘远愿约跃钥岳粤悦阅云郧匀陨运蕴酝晕韵杂灾载攒暂赞赃脏凿枣灶责择则泽贼赠扎札轧铡闸诈斋债毡盏斩辗崭栈战绽张涨帐账胀赵蛰辙锗这贞针侦诊镇阵挣睁狰帧郑证织职执纸挚掷帜质钟终种肿众诌轴皱昼骤猪诸诛烛瞩嘱贮铸筑驻专砖转赚桩庄装妆壮状锥赘坠缀谆浊兹资渍踪综总纵邹诅组钻致钟么为只凶准启板里雳余链泄台标';
}
function FTPYStr()
{
return '?}?@?K?勐O?\?W?瘟T?[?☆C?k?O?徒??^?r??????篚U???^?N??v??P???篱]???H??q?p???T?l?I?e?P??芾??K?g?N?a?⑿Q???M?K?N?n??}??????y?釉??v?较s???p?P?b?U???L?L???c?S?斥n???m??r?畏Q?驼\?G?V?t?Y?u?X??_?x?????P?I?I?h??N?z?r?A?τ|??鳢??J???N??b?o?~?n??[??????Z?e?_?зJ???梧??勰????Q?????觞h??n?v?u?\?ПI?羿???爝f??c?|??蔗??{叠??B???V??|????鲷Y?侏??x????嗑??蛾?????D?g?Z?Z?~??吼I????D?E?l?P?y?m?\?C?┕????L??w?U?M????^???S?S?麂h?L???T?p?S?P?w??彷o?x?}???D?`??}?w?众s??M??????V???V??R???w?t???o???m???h?????蛐M????P?^?^?T??V?矽?w???|?????F?]??L????^??n?h?u?Q?R?M?Z???t後?刈o????W?A????????g?h???Q?警???o?S?e?]?x?зV?x???Z?≈M?d?L???夥?@????C?e??I?u???O???D?姿E??????H?^?o?A?v?a?Z??r?{???O?怨{?g?D?}?O?z?A?|???旌????p?]???b?`?v??I????T?u?R??{?Y?????v?u?z?豺?????q?C?e?_??U?g?I?^?M?A??o?@??i?o?R?蒋d??Q?m???f?x?e?????※N?????Y?]?镁o?\?H??M?x?a?M?徘G?X?Q?E?^?x??E?_?P?w?ふn????煅??F?K?~???V??r??h?Q???U???D?R?碣??{??r?@?@?m??????[?欣|???E????疯D?绢??I?h?x?Y??Y?????畹[??r?`?z???B??z?i??磕???????Z??奢v????|??C?R??[?C?U?g??R?`?X?I?s????@?祷\??n?]???Шt?J?R?B?]?t?稃u???T????H?武X?H?铱|?]?V?G?n???\??y?噍?????S?]??}?_???j???j?????a??R?R?豳I???u?~?}?m?z?U?M???^?T?Q麽?q?]?V?T?????i?糁i????d??R????}?Q???\???c?{?y?夏X?吏[?H??f?俞??B??m??????甯?Q?翕o?~??廪r???Z?W?t???I?a?P?????圪r???i?_?h?l??O?{?u???H?滗??阕V??R?T?M????????L?T?U?w??t?X?Q???\?l?q??????N?????@???S?N?[?`?J?H?p??A???c???F??^?|??x?E???s?o???_?@?犴g?J?x?s?q??J?c???⑺_?w???黍}????⒓??Y?耖W??????p???B?d?z?卦O????鹉I?B??K?俾}???{?裨???r?g???R??葆?????郢F?休????H?傩g?湄Q????p?l???f?T?q?z???Z??A?b?\?K?V?C?m??q?O?p?S?s???i?H??E????c????T??U???C???l?v?`?R?}?w??l?N?F?d??N?~?y?^?D?T?F?j???r?W??E?D?m???愁B?f?W?f?`?????H?S???^??^?l?芈??y????Y?胛??u?C?桄u?跽_?o???]?F?照`?a?抟u???蚣??r??{?b?M?B?v?r?w?y?t??e?@?U?F?I?h?W?w???????l?????N??[??f??y?{?C???a?x?\??d?扮n?C??u??S?w?m??疫x?_?k?W?煸??ゑZ???d?壶f??????????}?李???W????┲V?????P????W?B?蝇??u?蜻b?G?{?????I?~?t??U?z?x?は???|???x??h?x?g???[?a??y???膪????t????I?上??f???虬b?x?????n?]??q?[?T??~?O?逝c?Z?Z?n?R?z?u?A?S?x?Y?@?@?T?A??h??s?S??[??????y?螂E?\?N?j????s?妮d???嘿??E?v????^???t?少\???????l?p?S???直K?剌????鹁`???q?べ~??w?U?H?N?@???稍\???瓯??b????C???碳???S?觅|?R?K?N?[?\?a?S????E?i?T?D?T??谫A?T?B?v?4u?D??肚f?b?y??铄F????Y??崞??Y?n??C??v?u?{?M??@??N?殡b???㈤??e?Z?N????_??';
}
function JTPYWord(){
var jtpyword = new Array('“','”','‘',''','三?O管','三极管' ,'中文?Y','串行','串列加速器','以太网','奶酪','二?O管','二极管','交互式','阿塞拜疆','人工智能','接口','任意球?T','任意球员',
'服务器','字?','字节','优先级','元??','元凶','光盘','光驱','克?_地??','克罗地亚','全角','冬天?Y','冬日?Y','凉菜','冷菜',
'凶器','?雌?','凶徒','?赐?','?词?','凶手','?窗?','凶案','凶??','???','凶残','???','凶杀','凶??','分布式','打印','列支敦士登','剪彩',
'加蓬','总线','局域网','特立尼?_和多巴哥','特立尼达和托巴哥','半角','卡塔??','卡塔尔','打印?C','打印机','厄立特里??','厄立特里亚','厄瓜多尔','厄瓜多??',
'斯威士兰','斯威士?m','吉布提','吉布堤','基里巴斯','?D瓦?R','图瓦卢','哈萨克斯坦','哥斯?_黎加','哥斯达黎加','格?吉??','格鲁吉亚','佐治亚','佐治??','嘴?Y',
'土库曼斯坦','薯仔','土豆?W','土豆网','坦桑尼亚','坦桑尼??','端口','塔吉克斯坦','塞舌尔','塞舌??','塞浦路斯','夏天?Y','夏日?Y',
'多明尼加共和??','多米尼加共和国','多米尼加共和??','多米尼加国','多明尼加??','穿梭?C','航天飞机','尼日利亚','尼日利??',
'字符','字号','字库','字符集','存盘','安提瓜和巴布?_','安提瓜和巴布达','宋元','洪都拉斯','寻址','寒假?Y','宽带','老??','老挝',
'打门','?比??','赞比亚','尼日??','尼日尔','山洞?Y','巴布??新畿???','巴布亚新几内亚','巴巴多斯','布基纳法索','布基?{法索','布什','布殊','帕劳','例程',
'平治之乱','平治之?y','几内亚比绍','????比?B','彩带','彩排','彩楼','彩牌楼','?吞K','复苏','心?Y','快闪存储器','闪存','传感','习用','戏彩娱亲',
'手电筒','手电','括号','拿破??','拿破仑','?e架','扫瞄仪','挂钩','?焘h','控件','台球','桌球','便携式','故事?Y','调制解调器','?{制解?{器','斯洛文尼??','斯洛文尼亚',
'新纪元','新?o元','日子?Y','春假?Y','春天?Y','春日?Y','?r?g?Y','芯片','暑假?Y','乍得','克林?D','克林顿','格林?{?_','格林纳达','凡高','森林?Y','榴?','榴莲','仿真',
'毛里裘斯','毛里求斯','?C械人','机器人','字段','元音','永历','文莱','沙特阿拉伯','沙地阿拉伯','波斯尼??黑塞哥?S那','波斯尼亚和黑塞哥维那','博茨瓦纳','博茨瓦?{','侯赛因','侯?因',
'深?Y?Y','光标','鼠标','算法','乌兹别克斯坦','词组','塞拉利昂','危地马拉','危地?R拉','冈比亚','??比??','疑??','疑凶','皮?Y?秋','?R旺?_','卢旺达','真凶','真??','硅片','硅谷',
'硬盘','硬件','盘片','磁盘','磁道','福士','秋假?Y','秋天?Y','秋日?Y','程控','突尼斯','尾注','蹦极跳','绑紧跳','等于','短?','短信','新西?m','新西兰','所罗门群岛','所?_?T群?u',
'索?R里','索马里','结彩','佛得角','?W?j','网络','互??W','因特网','彩球','彩绸','彩线','彩船','彩衣' ,'缉凶','???','?凶','意大利','老字号',
'圣基茨和尼维斯','?}吉斯?{域斯','?}文森特和格林?{丁斯','圣文森特和格林纳丁斯','圣卢西亚','?}?R西??','圣马力诺','?}?R力?Z','肚?Y','肯尼亚','肯雅','任意球',
'航天大学','苦?Y','毛里塔尼亚','毛里塔尼??','莫桑比克','万历','瓦努阿图','瓦努阿?D','也?T','也门','着','科摩?_','科摩罗','布隆迪','圭??那','圭亚那','火锅盖帽','苏里南',
'行凶','行??','行凶后','行?瘁?','行凶後','流?与??','移动电话','行程控制','卫生','?o生','埃塞俄比亚','埃塞俄比??','?Y勾外?B','?Y面','分辨率','译码','出租车','权限','瑙鲁','瑙?',
'变量','科特迪瓦','???','贝宁','伯利?','伯利兹','?I??','买凶','?I凶' ,'数据库','信息论','奔驰','平治','利比里亚','利比里??','?R索托','莱索托','软驱','?件','软件','加载',
'津巴布韦','津巴布?f','词汇','加纳','加?{','追凶','追??','?@?Y','信道','逞凶?Y狠','逞?呆Y狠','逞凶斗狠','即食?I','方便面','快速面','连字号','进制','入球','算子','?h程控制','远程控制',
'?丶{?D?f','?t院?Y','酰','巨商','钩','?h','钩心斗角','?h心?Y角','写保护','阿拉伯联合酋长国','阿拉伯?合酋?L??','噪声','脱机','雪?Y?t','雪?Y蕻','雪铁龙','异步','声卡','缺省','颁布','?C??',
'?I域?Y','头球','粒入球','马里共和国','?R里共和??','马耳他','马尔代夫','?R??代夫','?f事得','狄安娜','戴安娜','?c?Y','位图','商铺','商?','提交','店铺','店?','台湾','台湾','发布','?l布');
return jtpyword;
}
function FTPYWord(){
var ftpyword = new Array('「','」','『','』','三?O?w','三?O?w','中文?e','串列','串列加速器','乙太?W','乳酪','二?O?w','二?O?w','互?邮?','??塞拜然','人工智慧','介面','任意球?T','任意球?T',
'伺服器','位元?M','位元?M','??先?序','元凶','元凶','光碟','光碟?C','克?_埃西??','克?_埃西??','全形','冬天?e','冬日?e','冷?P','冷?P',
'凶器','凶器','凶徒','凶徒','凶手','凶手','凶案','凶案','凶??','凶??','凶??','凶??','凶??','凶??','分散式','列印','列支敦斯登','剪?Z',
'加彭','?R流排','?^域?W','千里?_托?哥','千里?_托?哥','半形','卡?_','卡?_','印表?C','印表?C','厄利垂??','厄利垂??','厄瓜多','厄瓜多',
'史瓦???m','史瓦???m','吉布地','吉布地','吉里巴斯','吐瓦?','吐瓦?','哈?_克','哥斯大黎加','哥斯大黎加','?讨??','?讨??','?讨??','?讨??','嘴?e',
'土?炻?','土豆','土豆?W','土豆?W','坦尚尼??','坦尚尼??','埠','塔吉克','塞席??','塞席??','塞普勒斯','夏天?e','夏日?e',
'多明尼加','多明尼加','多明尼加','多米尼克','多米尼克','太空梭','太空梭','奈及利??','奈及利??',
'字元','字型大小','字型?n','字符集','存?n','安地卡及巴布?_','安地卡及巴布?_', '宋元','宏都拉斯','定址','寒假?e','???l','寮??','寮??',
'射?T','尚比??','尚比??','尼日','尼日','山洞?e', '巴布???~????','巴布???~????','巴?多','布吉?{法索','布吉?{法索','布希','布希','帛琉','常式',
'平治之?y','平治之?y','????比索','????比索','彩??','彩排','彩??','彩牌??','?彤d','?彤d','心?e','快?W????w','快?W????w','感?y','?T用','?蚓Z?视H',
'手?筒','手?筒','括弧','拿破??','拿破??','捷豹','?呙槠?','?煦^','?煦^','控制?','撞球','撞球','?y??型','故事?e', '????C','????C','斯洛?S尼??','斯洛?S尼??',
'新?o元','新?o元','日子?e','春假?e','春天?e','春日?e','?r?g?e','晶元','暑假?e','查德','柯林?D','柯林?D','格瑞那?_','格瑞那?_','梵谷','森林?e','榴??','榴??','模?M',
'模里西斯','模里西斯','?C器人','?C器人','?谖?','母音','永??','汶?R','沙?醯匕⒗?伯','沙?醯匕⒗?伯','波士尼??赫塞哥?S?{','波士尼??赫塞哥?S?{','波札那','波札那','海珊','海珊',
'深?Y?e','游??','滑鼠','演算法','?跗??e克','片?Z','?{子山','瓜地?R拉','瓜地?R拉','甘比??','甘比??','疑凶','疑凶','皮?e?秋','?R安?_','?R安?_','真凶','真凶','矽片','矽谷',
'硬碟','硬?w','碟片','磁碟','磁?','福斯','秋假?e','秋天?e','秋日?e','程式控制','突尼西??','章?附?]','笨?i跳','笨?i跳','等於','??','??','?~西?m','?~西?m','索?_?T群?u','索?_?T群?u',
'索?R利??','索?R利??','?Y?Z','?S德角','?W路','?W路','?W?H?W路','?W?H?W路','?Z球','?Z?I','?Z?','?Z船','?Z衣','?凶','?凶','?凶','?x大利','老字?',
'?}克里斯多福及尼?S斯','?}克里斯多福及尼?S斯','?}文森及格瑞那丁','?}文森及格瑞那丁','?}露西??','?}露西??','?}?R利?Z','?}?R利?Z','肚?e','肯??','肯??','自由球',
'航天大?W','苦?e','茅利塔尼??','茅利塔尼??','莫三比克','?f??','?f那杜','?f那杜','?~?T','?~?T','著','葛摩','葛摩','蒲隆地','?w??那','?w??那','?w火?','?K利南',
'行凶','行凶','行凶後','行凶後','行凶後','行?与??','行?与??','行程控制','?l生','?l生','衣索比??','衣索比??','?e勾外?B','?e面','解析度','解?a','?程?','?S可??','?Z?','?Z?',
'???','象牙海岸','?南','?南','?里斯','?里斯','?I凶','?I凶','?I凶','?Y料??','?Y?理?','?e士','?e士','?比瑞??','?比瑞??','?索托','?索托','?碟?C','??w','??w','?d入',
'辛巴威','辛巴威','?o??','迦?{','迦?{','追凶','追凶','?@?e','通道','逞凶?Y狠','逞凶?Y狠','逞凶?Y狠','速食?I','速食?I','速食?I','?B字?','?M位','?M球','?\算元','?h程控制','?h程控制',
'那杜','?t院?e','醯','??Z','?^','?^','?^心?Y角','?^心?Y角','防??','阿拉伯?合大公??','阿拉伯?合大公??','?s?','?x?','雪?e?t','雪?e蕻','雪?F??','非同步','音效卡','?A?O','?C布','?C布',
'?I域?e','?^槌','?w?M球','?R利共和??','?R利共和??','?R??他','?R??地夫','?R??地夫','?R自?_','黛安娜','黛安娜','?c?e','?c??D','展?^','展?^','送出','展?^','展?^','?_??','?_??','?l??','?l??');
return ftpyword;
}
function Traditionalized(cc){
var str='',ss=JTPYStr(),tt=FTPYStr();
var ssa = JTPYWord(),tta = FTPYWord();
for(var i=0;i<cc.length;i++)
{
if(cc.charCodeAt(i)>10000&&ss.indexOf(cc.charAt(i))!=-1)str+=tt.charAt(ss.indexOf(cc.charAt(i)));
else str+=cc.charAt(i);
}
for(var j=0;j<ssa.length;j++){
if(str.indexOf(ssa[j]) >= 0){
str = str.replace(ssa[j],tta[j]);
}else{
str = str;
}
}
return str;
}
function Simplized(cc){
var str='',ss=JTPYStr(),tt=FTPYStr();
var ssa = JTPYWord(),tta = FTPYWord();
for(var i=0;i<cc.length;i++)
{
if(cc.charCodeAt(i)>10000&&tt.indexOf(cc.charAt(i))!=-1)str+=ss.charAt(tt.indexOf(cc.charAt(i)));
else str+=cc.charAt(i);
}
for(var j=0;j<ssa.length;j++){
if(str.indexOf(tta[j]) >= 0){
str = str.replace(tta[j],ssa[j]);
}else{
str = str;
}
}
return str;
}
function setCookie(name, value) //cookies设置
{
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
if(expires!=null)
{
var LargeExpDate = new Date ();
LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));
}
document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString()));
}
function getCookie(Name) //cookies读取
{
var search = Name + "="
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search)
if(offset != -1)
{
offset += search.length
end = document.cookie.indexOf(";", offset)
if(end == -1) end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
else return ""
}
}
var StranLink_Obj=document.getElementById("StranLink")
if (StranLink_Obj)
{
var JF_cn="ft"+self.location.hostname.toString().replace(/\./g,"")
var BodyIsFt=getCookie(JF_cn)
if(BodyIsFt!="1")BodyIsFt=Default_isFT
with(StranLink_Obj)
{
if(typeof(document.all)!="object") //非IE浏览器
{
href="javascript:StranBody()"
}
else
{
href="#";
onclick= new Function("StranBody();return false")
}
title=StranText("点击以繁体中文方式浏览",1,1);
innerHTML=StranText(innerHTML,1,1);
}
if(BodyIsFt=="1"){setTimeout("StranBody()",StranIt_Delay)}
}
起初我以为是那个递归的问题引起的,但是测试发现就算是很多字符,它仍然能快速的进行替换。
经过排查,原来是JS和OBJECT标签会带来卡死的问题。繁简切换实现必然会跳过某些标签,看到这段,它的作用就是来判断替换哪些标签里的文字。
for(var i=0;i<obj.length;i++)
{
var OO=obj.item(i)
if("||BR|HR|TEXTAREA|".indexOf("|"+OO.tagName+"|")>0||OO==StranLink_Obj)continue;
if(OO.title!=""&&OO.title!=null)OO.title=StranText(OO.title);
if(OO.alt!=""&&OO.alt!=null)OO.alt=StranText(OO.alt);
if(OO.tagName=="INPUT"&&OO.value!=""&&OO.type!="text"&&OO.type!="hidden")OO.value=StranText(OO.value);
if(OO.nodeType==3){OO.data=StranText(OO.data)}
else StranBody(OO)
}
加上这个就一切正常了:
if(OO.tagName=="OBJECT")continue;
if(OO.tagName=="SCRIPT")continue;