龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

天气预报插件更改官方代码实现完全自定义的方法

时间:2012-01-20 15:18来源:未知 作者:admin 点击:
分享到:
天气预报官方提供的接口,只能让背景透明,却不能更改文字的颜色。下面给出具体解决方案 折叠 展开 XML/HTML Code 复制内容到剪贴板 !DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//ENhttp://www.
天气预报官方提供的接口,只能让背景透明,却不能更改文字的颜色。下面给出具体解决方案
折叠XML/HTML Code复制内容到剪贴板
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <style type="text/css">  
  6. *   {margin: 0;padding: 0;list-style:none;font-weight:normal;line-height:180%;    }img    {border:0;}body     {font-family: Verdana, Arial, Helvetica, sans-serif;background-color:transparent;color:#000;font-size:12px;text-align:center;}a     {color:#000;text-decoration:none;}a:hover    {color:#FF6600;text-decoration:underline;}em    {font-style:normal;}strong    {}a strong    {}select    {height:20px;line-height:20px;}ul.row    {clear:both;}ul.row li    {float:left;margin:0 4px;}ul.row li a    {display:inline;height:22px;line-height:22px;}.more a    {}ul.col li    {margin:4px auto;text-align:center;font-size:14px;font-weight:bold;}ul.col li #city    {font-weight:bold;margin-left:10px;}ul.col li a    {font-size:14px;font-weight:bold;}ul.col .small    {padding-top:6px;}ul.col .small a    {font-size:12px;}ul.col .line    {padding:10px;border-bottom:1px dashed #ddd;}dl    {clear:both;margin:0 auto;}dl dt    {float:left;height:65px;margin-right:10px;}dl dt strong    {display:block;margin-top:5px;*margin-top:10px;_margin-top:15px;}dl dt a    {}dl dd    {margin-left:5px;text-align:left;height:18px;line-height:18px;padding:0;margin:0;}dl .title     {margin-bottom:4px;_margin-bottom:-4px;}dl .title #city    {font-size:14px;font-weight:bold;}#cj    {clear:both;}#left    {float:left;text-align:center;}#left h3   {   margin-bottom:4px;   }#left h3 #city    {font-size:14px;font-weight:bold;}#cj h4    {font-size:12px;margin-bottom:5px;}#right    {margin-left:10px;text-align:left;float:left;}#cjbg    {background:url(/img/bg.gif) left bottom repeat-x;height:90px;padding:10px;}#cjbg .line    {border-left:1px solid #ddd;padding-left:8px;}#cjbg h4    {font-size:12px;}#right h3 #city    {font-size:14px;margin-right:10px;font-weight:bold;margin-bottom:4px;}ul.new    {   background-color:transparent;   height:28px;   line-height:28px;   }ul.new li a img   {   margin-top:4px;      } ul.new li a em    {font-weight:bold;color:#fff;line-height:28px;}ul.new li a:hover    {text-decoration:none;color:#000;}ul.new li a:hover em    {color:#000;}#eNew    {text-align:left;margin:0 auto;width:150px;height:180px;}#eNew h1    {font-size:20px;margin-bottom:0;}#eNew h2 a em    {    font-size:14px;    font-weight:normal;    }#eNew h4    {background:url(/img/w.gif) left top no-repeat;height:43px;line-height:43px;text-indent:1em;width:150px;}#eNew h4 a em    {line-height:43px;font-size:18px;font-weight:blod;}#eNew p    {font-size:12px;}.blue      {  text-align:right;  }.blue li a      {  color:#0070C0;      }ul.blue li{  float:right;  }img, div { behavior: url(iepngfix.htc) }  
  7. </style>   
  8. </head>  
  9. <body>  
  10. <ul class="row">  
  11.   <li><a id="url1" href="" target="_blank"><em id="city"></em></a></li>  
  12.   <li><a id="url2" href="" target="_blank"><img id="small1" src="" alt="" width="20" height="20" /></a></li>  
  13.    <li><a id="url3" href="" target="_blank"><em id="temp1"></em></a></li>  
  14.   <li><a id="url4" href="" target="_blank"><em id="wind1"></em></a></li>  
  15. </ul>  
  16. <script type="text/javascript">  
  17. var xmlhttp=null;   
  18. var jsonobj;  
  19. var rs="http://61.4.185.48:81/g/";  
  20. var cookie_infogetCookie('newcity1');  
  21. var id1;  
  22. var ids="url1,url2,url3,url4";  
  23. var url=window.location.href;  
  24. var start=url.indexOf("id");  
  25. var end=url.indexOf("T");  
  26. var setURL=function(ids, url)  
  27. {var nodes=ids;if(typeof nodes=="string"){nodesnodes=nodes.split(",");}  
  28. for( var i=0; i<nodes.length; i++){if(document.getElementById(nodes[i])){document.getElementById(nodes[i]).href=url;}}}  
  29. function setCookie(name, value)   
  30. { var argv = setCookie.arguments;   
  31. var argc = setCookie.arguments.length;   
  32. var expires = (argc > 2) ? argv[2] : null;   
  33. if(expires!=null)   
  34. { var LargeExpDate = new Date (); LargeExpDate.setTime(LargeExpDate.getTime() + (expires*365*24*60*60*1000*10));}   
  35. document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString())); }  
  36. function getCookie(Name)   
  37. {var search = Name + "=" ;  
  38. if(document.cookie.length > 0)   
  39. {offset = document.cookie.indexOf(search)   
  40. if(offset != -1)   
  41. {offset += search.length;  
  42. end = document.cookie.indexOf(";", offset);  
  43. if(end == -1) end = document.cookie.length;  
  44. return unescape(document.cookie.substring(offset, end));}   
  45. else return "";} }  
  46. function createXMLHTTPRequext()  
  47. {   
  48. if (window.XMLHttpRequest)  
  49. {xmlhttp = new XMLHttpRequest(); }  
  50. else if (window.ActiveXObject)  
  51. {xmlhttp =new ActiveXObject("Msxml2.XMLHTTP") ;  
  52. if (! xmlhttp )  
  53. {xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }}}  
  54. function HandleStateChange()   
  55. {if (xmlhttp.readyState == 4)  
  56. {var jsontext =xmlhttp.responseText;  
  57. var func = new Function("return " + jsontext);  
  58. jsonobj = func();} }  
  59. function PostOrder(xmldoc)   
  60. {createXMLHTTPRequext();  
  61. // try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); } catch (e) { alert("Permission UniversalBrowserRead denied."); }   
  62. xmlhttp.open("GET", xmldoc,false);  
  63. xmlhttp.onreadystatechangeHandleStateChange;  
  64. xmlhttp.send(null); }  
  65. function returndata(id){var datastr1;  
  66. if(id==""){str="101010100";  
  67. datastr1='/tq/tq_code.php?cd='+str;}else{datastr1='/tq/tq_code.php?cd='+id;}  
  68. PostOrder(datastr1);  
  69. HandleStateChange();  
  70. var parseData=new Object();  
  71. with(jsonobj.weatherinfo){parseData={city: {innerHTML: city},  
  72. temp1: {innerHTML: temp1},  
  73. wind1: {innerHTML: wind1},  
  74. index_d: {innerHTML: index_d},  
  75. index_uv: {innerHTML: index_uv},  
  76. small1: {src:"http://m.weather.com.cn/img/c"+(img2==99?img1:img2)+".gif",  
  77. title: "中国天气网今日天气指数 紫外线指数:"+index_uv+"。"+"穿衣指数:"+index_d},  
  78. small2: {src:"http://m.weather.com.cn/img/c"+img2+".gif",  
  79. title: "中国天气网今日天气指数 紫外线指数:"+index_uv+"。"+"穿衣指数:"+index_d}}}  
  80. for( var m in parseData){var node=document.getElementById(m);  
  81. var sets=parseData[m];  
  82. if(node){for( var prop in sets ){node[prop]=sets[prop];}}}}  
  83. if(start!=-1){var first=start+parseInt(3);  
  84. call=url.substring(first,end);  
  85. returndata(call);  
  86. setURL(ids,"http://www.weather.com.cn/weather/"+call+".shtml");}  
  87. else{if(!cookie_info)  
  88. {var js = document.createElement("script");   
  89. js.setAttribute("type", "text/javascript");  
  90. js.setAttribute("src",rs);  
  91. document.body.insertBefore(js, null);  
  92. function id_callback()  
  93. {   
  94. std = id;  
  95. if(typeof(id)=="undefined")  
  96. {id1="101010100";  
  97. setURL(ids,"http://www.weather.com.cn/weather/"+id1+".shtml");  
  98. returndata(id1);}  
  99. else  
  100. {id1=std;  
  101. time=new Date();  
  102. time.setTime(time.getTime()+365*24*60*60*1000*10);  
  103. date=time.toGMTString();  
  104. document.cookie = "newcity1=" + escape(std)+ ";expires="+date;  
  105. setURL(ids,"http://www.weather.com.cn/weather/"+id1+".shtml");  
  106. returndata(std);}}}else{id1=cookie_info;  
  107. setURL(ids,"http://www.weather.com.cn/weather/"+id1+".shtml");  
  108. returndata(id1);}}var vjAcc="";var wrUrl="http://c.wrating.com/";var wrSv=0;function vjTrack(C){var B=vjValidateTrack();if(B===false){return }var A=wrUrl+"a.gif"+vjGetTrackImgUrl(C);document.write('<div style="display:none"><img src="'+A+'" id="wrTagImage" width="1" height="1"/></div>');vjSurveyCheck()}function vjEventTrack(D){var C=vjValidateTrack();if(C===false){return }var B=wrUrl+"a.gif"+vjGetTrackImgUrl(D);var A=new Image();A.src=B;A.onload=function(){}}function vjValidateTrack(){if(document.location.protocol=="file:"){return false}if(vjAcc==""){return false}else{if(wrUrl.substr(wrUrl.length-1,1)!="/"){wrUrl+="/"}}return true}function vjGetTrackImgUrl(S){var M=0;var N="expires=Fri, 1 Jan 2038 00:00:00 GMT;";var T=document.location;var P=document.referrer.toString();var D;var H=vjGetDomainFromUrl(T);var K;var V;var Y="";var L=vjFlash();var G="";var Z="";var J="";var O=navigator.appName+" "+navigator.appVersion;var F=new Date();var X=F.getTimezoneOffset()/-60;var A=0;var U="";var R="";if(typeof (H[1])!="undefined"){V=H[1]}else{if(typeof (H[0])!="undefined"){V=H[0]}}if(P!=""){Y=vjGetKeyword(P)}else{if((O.indexOf("MSIE")>=0)&&(parseInt(O.substr(O.indexOf("MSIE")+5),4)>=5)&&(O.indexOf("Mac")==-1)&&(navigator.userAgent.indexOf("Opera")==-1)){try{document.documentElement.addBehavior("#default#homePage");if(document.documentElement.isHomePage(location.href)){P="ishomepage"}}catch(W){}}}if(navigator.cookieEnabled){M=1}if(self.screen){G=screen.width+"x"+screen.height+"x"+screen.colorDepth}else{if(self.java){var Q=java.awt.Toolkit.getDefaultToolkit().getScreenSize();G=Q.width+"x"+Q.height+"x0"}}if(navigator.language){Z=navigator.language.toLowerCase()}else{if(navigator.browserLanguage){Z=navigator.browserLanguage.toLowerCase()}else{Z="-"}}if(navigator.javaEnabled()){A=1}if(M==1){D=document.cookie;if(D.indexOf("vjuidsvjuids=")<0){K=vjVisitorID();document.cookie="vjuids="+escape(K)+";"+N+";domain="+V+";path=/;"}else{K=vjGetCookie("vjuids")}if(D.indexOf("vjlast=")<0){U="30";var E=vjGetTimestamp(F.getTime()).toString();R=E+"."+E+".30"}else{var a=vjGetCookie("vjlast");var C=a.split(".");var B="";if(typeof (C[0])!="undefined"){R=C[0].toString()}else{R=vjGetTimestamp(F.getTime()).toString()}if(typeof (C[1])!="undefined"){var I=new Date(parseInt(C[1])*1000);if(I.toDateString()!=F.toDateString()){R+="."+vjGetTimestamp(F.getTime()).toString();if(parseInt(vjGetTimestamp(F.getTime())-parseInt(C[1]))/86400>30){U="2"}else{U="1"}if(typeof (C[2])!="undefined"){U+=C[2].substr(0,1)}else{U+="0"}}else{R+="."+C[1].toString();if(typeof (C[2])!="undefined"){U+=C[2]}else{U="10"}}}else{R+="."+vjGetTimestamp(F.getTime()).toString();if(typeof (C[2])!="undefined"){U+=C[2]}else{U="10"}}R+="."+U}document.cookie="vjlast="+R+";"+N+";domain="+V+";path=/;"}J="?a="+F.getTime().toString(16)+"&t=&i="+escape(K);J+="&b="+escape(T)+"&c="+vjAcc;J+="&s="+G+"&l="+Z;J+="&z="+X+"&j="+A+"&f="+escape(L);if(P!=""){J+="&r="+escape(P)+"&kw="+Y}J+="&ut="+U+"&n=";if(typeof (S)=="undefined"){J+="&js="}else{J+="&js="+escape(S)}J+="&ck="+M;return J}function vjGetTimestamp(A){return Math.round(A/1000)}function vjGetKeyword(C){var A=[["baidu","wd"],["baidu","q1"],["google","q"],["google","as_q"],["yahoo","p"],["msn","q"],["live","q"],["sogou","query"],["youdao","q"],["soso","w"],["zhongsou","w"],["zhongsou","w1"]];var B=vjGetDomainFromUrl(C.toString().toLowerCase());var D=-1;var E="";if(typeof (B[0])=="undefined"){return""}for(i=0;i<A.length;i++){if(B[0].indexOf("."+A[i][0]+".")>=0){D=-1;D=C.indexOf("&"+A[i][1]+"=");if(D<0){D=C.indexOf("?"+A[i][1]+"=")}if(D>=0){E=C.substr(D+A[i][1].length+2,C.length-(D+A[i][1].length+2));D=E.indexOf("&");if(D>=0){EE=E.substr(0,D)}if(E==""){return""}else{return A[i][0]+"|"+E}}}}return""}function vjGetDomainFromUrl(E){if(E==""){return false}EE=E.toString().toLowerCase();var F=[];var C=E.indexOf("//")+2;var B=E.substr(C,E.length-C);var A=B.indexOf("/");if(A>=0){F[0]=B.substr(0,A)}else{F[0]=B}var D=F[0].match(/[^.]+\.(com.cn|net.cn|gov.cn|cn|com|net|org|gov|cc|biz|info)+$/);if(D){if(typeof (D[0])!="undefined"){F[1]=D[0]}}return F}function vjVisitorID(){var A=vjHash(document.location+document.cookie+document.referrer).toString(16);var B=new Date();return A+"."+B.getTime().toString(16)+"."+Math.random().toString(16)}function vjHash(C){if(!C||C==""){return 0}var B=0;for(var A=C.length-1;A>=0;A--){var D=parseInt(C.charCodeAt(A));B=(B<<5)+B+D}return B}function vjGetCookie(D){var B=D+"=";var F=B.length;var A=document.cookie.length;var E=0;while(E<A){var C=E+F;if(document.cookie.substring(E,C)==B){return vjGetCookieVal(C)}E=document.cookie.indexOf(" ",E)+1;if(E==1){break}}return null}function vjGetCookieVal(B){var A=document.cookie.indexOf(";",B);if(A==-1){A=document.cookie.length}return unescape(document.cookie.substring(B,A))}function vjFlash(){var _flashVer="-";var _navigator=navigator;if(_navigator.plugins&&_navigator.plugins.length){for(var ii=0;ii<_navigator.plugins.length;ii++){if(_navigator.plugins[ii].name.indexOf("Shockwave Flash")!=-1){_flashVer=_navigator.plugins[ii].description.split("Shockwave Flash ")[1];break}}}else{if(window.ActiveXObject){for(var ii=10;ii>=2;ii--){try{var fl=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+ii+"');");if(fl){_flashVer=ii+".0";break}}catch(e){}}}}return _flashVer}function vjSurveyCheck(){if(wrSv<=0){return }var C=new Date();var A=C.getTime();var D=Math.random(A);if(D<=parseFloat(1/wrSv)){var B=document.createElement("script");B.type="text/javascript";B.id="wratingSuevey";B.src="http://tongji.wrating.com/survey/check.php?c="+vjAcc;document.getElementsByTagName("head")[0].appendChild(B)}};  
  109. var vjAcc="860010-2151010100";  
  110. var wrUrl="http://c.wrating.com/";  
  111. var wrRandom = 70;  
  112. var now = new Date();  
  113. var seed = now.getTime();  
  114. var randomNumber = Math.random(seed);  
  115. if (randomNumber <= parseFloat(1/wrRandom))  
  116. {        vjTrack("");}  
  117. </script>  
  118. <noscript><img src="http://c.wrating.com/a.gif?a=&c=860010-2151010100" width="1" height="1"/></noscript>  
  119. </body>  
  120. </html>  
把上面的代码放到服务器,
注意这段代码,主要是抓取天气预报官网数据,解决跨域的问题
XML/HTML Code复制内容到剪贴板
  1. datastr1='/tq/tq_code.php?cd='+str;}else{datastr1='/tq/tq_code.php?cd='+id;}  
tq_code.php具体代码如下:
XML/HTML Code复制内容到剪贴板
  1. <?php  
  2. $code=intval($_GET['cd']);  
  3. $url="http://m.weather.com.cn/data/".$code.".html";  
  4. $content=file_get_contents($url);  
  5. echo $content;  
  6. ?>  
这就可以完全修改页面样式实现自定义了,具体引用代码:
XML/HTML Code复制内容到剪贴板
  1. <iframe width="165" scrolling="no" height="20" frameborder="0" allowtransparency="" vspace="0" hspace="0" marginheight="0" marginwidth="0" src="http://www.1sohu.com/tq/qixiang.html"></iframe>  

转载请注明出处:http://www.1sohu.com/newsHtm/95/n_16895.shtml

精彩图集

赞助商链接