桌面小工具,网络时间表

前因:

      我的电脑本地时间不准了,应该是换块电池就成,去客服,但客服人员的处理方案是"换主板",擦...我一听,算了吧,上次我换个主板,就浪费我一个多月的时间,我真心等不起.

下个工具吧,但许多现成的时间表工具都是读取本地时间的,于是,只好自己做了个专门获取网络时间的桌面小工具.

正题:

谢谢网络上开源代码的好人们啊

先贴主要代码:这个就是桌面工具的主文件

DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="css/gadget.css" type="text/css" rel="stylesheet" />
head>
 <body >
    <div class="main" id="timestyle">
      <div class="shouye">
            <div id="bjt" style="margin-top:8px">
                <div id="bjt_1">
                    <div id="swf_clock">div>
                    <div id="bjt_info">
                        <div id="time">Loading...div>
                        <div id="date">Loading...div>
                    div>
                div>
            div>
        div>
        <script type="text/javascript">
            if (typeof console == "undefined"){
                var console = {
                    log:function(){}
                };
            }
            var swfLoaded = false;
            var initTime = undefined;
            
            
            function setFDF(){
                swfLoaded = true;
                //console.log(initTime);
                if(initTime) setClockTime(initTime);
                return true;
            }
            
            function setClockTime(time){
                if (swfLoaded && swfCtrl) {
                    //console.log("COLK:"+time);
                    //try{
                        swfCtrl.setTime(time);
                    //}catch(e){}
                }
            }
            script>
            <script src="core/clock.js">script>
            <script type="text/javascript">
                (function(){
                var week = '日一二三四五六';
                var innerHtml = '{0}:{1}:{2}';
                var dateHtml = "{0}月{1}日 周{2}";
                var timer = 0;
                var beijingTimeZone = 8;
                
                function format(str, json){
                    return str.replace(/{(\d)}/g, function(a, key) {
                        return json[key];
                    });
                }
                
                function p(s) {
                    return s < 10 ? '0' + s : s;
                }
                
                window.baidu_time =     function(time){    
                    initTime = time;
                    show(time);
                    timer = setInterval(function(){
                        time += 1000;
                        show(time);
                    }, 1000);
                    
                }
                function getcurrenttime()
                {
                    var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");  
                    xmlhttp.open("GET", "http://bjtime.cn", false);  
                    xmlhttp.setRequestHeader("If-Modified-Since", "bjtime");  
                    xmlhttp.send();  
                    var dateStr = xmlhttp.getResponseHeader("Date");  
                    var date = new Date(dateStr);  
                    var year = date.getFullYear();  
                    var month = date.getMonth() + 1;  
                    var date1 = date.getDate();  
                    var hour = date.getHours();  
                    var minutes = date.getMinutes();  
                    var second = date.getSeconds();  
                    var s=year+"-"+month+"-"+date1+" "+hour+":"+minutes+":"+second;
                    var a=s.split(/[^0-9]/);
                    var d=new Date(a[0],a[1]-1,a[2],a[3],a[4],a[5]);
                    return d.getTime();
                }
                function show(time){
                    var timeOffset = ((-1 * (new Date()).getTimezoneOffset()) - (beijingTimeZone * 60)) * 60000;
                    var now = new Date(time - timeOffset);
                    document.getElementById('time').innerHTML = format(innerHtml, [p(now.getHours()), p(now.getMinutes()), p(now.getSeconds())]);
                    setClockTime(time);
                    document.getElementById('date').innerHTML = format(dateHtml, [ p((now.getMonth()+1)), p(now.getDate()), week.charAt(now.getDay())]);
                }
                function init(){
                    var elm = document.createElement('SCRIPT');
                    elm.src = 'http://open.baidu.com/app?module=beijingtime&t=' + new Date().getTime();
                    alert(new Date().getTime());
                    document.getElementsByTagName('HEAD')[0].appendChild(elm);
                }
                
                window.baidu_time(getcurrenttime());
                
                })();
            script>
 body>
html>

剩下3个文件1个xml,1个css,1个js;

下面按顺序

xml:
xml version="1.0" encoding="utf-8" ?> <gadget> <name>TimeBarname> <version>1.0.0.0version> <hosts> <host name="TimeSidebar"> <base type="HTML" apiVersion="1.0.0" src="Time.html" /> <permissions>Fullpermissions> <platform minPlatformVersion="1.0" /> host> hosts> gadget>
css:
body
{ margin: 0; width: 103px; height: 108px; font-family: verdana; font-weight: bold; font-size: small; } /* 大小设置,见注* */ #timestyle { vertical-align: middle; text-align: center; overflow: hidden; }
js:
var
swfCanvas = document.getElementById("swf_clock"); var swfCtrl = undefined; function getSWFVersion(){ var n = navigator; if (n.plugins && n.mimeTypes.length) { var a = n.plugins["Shockwave Flash"]; if (a && a.description) { return a.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s)+r/, ".") + ".0"; } } else if (window.ActiveXObject && !window.opera) { for (var i = 10; i >= 2; i--) { try { var c = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i); if (c) { return i + ".0.0"; break; } } catch (e) { } } } } function creatFlashfunction(id,url, width, height, fq){ var str = ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; swfCanvas.innerHTML = str; } function getSWF(movieName) { var isIE = navigator.userAgent.indexOf('MSIE') != -1 && !window.opera; if(isIE){ return document[movieName] || window[movieName]; }else { return document[movieName+"_ff"] || window[movieName+"_ff"]; } }; (function(){ var swfVer=getSWFVersion(); if(swfVer==undefined||swfVer.split(".")[0]<8){} else { swfCanvas.className = "swfBox"; creatFlashfunction("bd_swf_clock","http://www.baidu.com/swf/aladdin/clock/clock.swf","64px","64px",""); swfCtrl = getSWF("bd_swf_clock"); setTimeout(function(){ if (!swfLoaded) swfCanvas.style.display = "none"; },5000); } })();

以下是结构的图片

 桌面小工具,网络时间表_第1张图片

这是桌面小工具的文件位置:

C:\Users\用户名\AppData\Local\Microsoft\Windows Sidebar\Gadgets

先建个XXX.Gadget文件夹,把代码文件放里面,就成小工具了.挺简单的

效果图:

桌面小工具,网络时间表_第2张图片

***************************************************

功能上肯定有缺陷,日后完善

70%的已经完成,后面的还有样式的优化,和自定义偏好的设置.每个人有个各自的喜好,就不贴了

转载于:https://www.cnblogs.com/Feng-Scorpio/p/3227451.html

你可能感兴趣的:(桌面小工具,网络时间表)