1 function withjQuery(callback, safe) { 2 if (typeof (jQuery) == "undefined") { 3 var script = document.createElement("script"); 4 script.type = "text/javascript"; 5 script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"; 6 7 if (safe) { 8 var cb = document.createElement("script"); 9 cb.type = "text/javascript"; 10 cb.textContent = "jQuery.noConflict();(" + callback.toString() + ")(jQuery);"; 11 script.addEventListener('load', function() { 12 document.head.appendChild(cb); 13 }); 14 } else { 15 var dollar = undefined; 16 if (typeof ($) != "undefined") 17 dollar = $; 18 script.addEventListener('load', function() { 19 jQuery.noConflict(); 20 $ = dollar; 21 callback(jQuery); 22 }); 23 } 24 document.head.appendChild(script); 25 } else { 26 callback(jQuery); 27 } 28 } 29 30 withjQuery(function($) { 31 var Notify = { 32 icon: "http://im.qq.com/favicon.ico", 33 title: "消息提醒", 34 target: null, 35 36 isSupport: function() { 37 return !!window.webkitNotifications; 38 }, 39 getPermission: function(callback) { 40 window.webkitNotifications.requestPermission(function() { 41 if (callback) { 42 callback(this.checkPermission()); 43 } 44 }); 45 }, 46 checkPermission: function() { 47 return !!(window.webkitNotifications.checkPermission() == 0); 48 }, 49 show: function(msg) { 50 Notify.target = window.webkitNotifications.createNotification(this.icon, this.title, msg); 51 Notify.target.show(); 52 setTimeout(this.close, 5000); 53 }, 54 close: function() { 55 if(!Notify.target) return; 56 57 Notify.target.cancel(); 58 Notify.target = null; 59 } 60 }; 61 62 function notice(msg) { 63 if(Notify.checkPermission()) { 64 Notify.show(msg); 65 }else{ 66 alert(msg); 67 } 68 if(jQuery("#audio:checked").size() > 0 ) new Audio("http://static.fishlee.net/resources/audio/music2.ogg").play(); 69 } 70 71 var interval = 10; 72 function init() { 73 $("div.toolbar").append(" <input type='checkbox' id='audio' checked='checked'>audio (最后刷新:<font color='red' id='refreshlabel'>"+new Date()+"</font> 下次刷新:<font color='red' id='countdown'>-</font>)"); 74 jQuery("a.del-record").remove(); 75 jQuery("ul.msg>li:last>h2").append("(" + jQuery("h2.date:last").text() + ")"); 76 77 setInterval(function(){countdown(interval);refreshMsg();}, interval * 1000); 78 countdown(interval); 79 } 80 81 function countdown(n) { 82 jQuery("#countdown").html(n); 83 if(n > 0) setTimeout(function(){countdown(n-1);}, 1000); 84 } 85 86 var lastest = ''; 87 function refreshMsg() { 88 89 jQuery("#chatMsgList").html(""); 90 jQuery("script[src='http://5.url.cn/verify/webkit/js/16/novip.min.js']").remove(); 91 jQuery(document.body).append("<script type=\"text/javascript\" src=\"http://5.url.cn/verify/webkit/js/16/novip.min.js\"></script>"); 92 93 setTimeout(function(){ 94 jQuery("#refreshlabel").html("" + new Date()); 95 96 var t = jQuery("ul.msg>li:last>h2").text(); 97 jQuery("a.del-record").remove(); 98 jQuery("ul.msg>li:last>h2").append("(" + jQuery("h2.date:last").text() + ")"); 99 if(lastest == "") lastest = t; 100 if(t != "" && t != lastest) { 101 notice(jQuery("ul.msg>li:last>p").text()); 102 lastest = t; 103 } 104 }, 1000); 105 } 106 107 window.onbeforeunload = function() { 108 return '提示:\n关闭该页将会停止消息提醒!'; 109 }; 110 111 112 jQuery(document).ready(function(){ 113 114 if(!Notify.checkPermission()) { 115 jQuery(document.body).prepend('<input type="button" value="getPremission" id="getPremissionBtn" style="100px;height:30px;">'); 116 } 117 118 jQuery('#getPremissionBtn').live('click', function(){ 119 Notify.getPermission(); 120 if(Notify.checkPermission()) { 121 jQuery(this).remove(); 122 } 123 }); 124 125 init(); 126 127 }); 128 129 }, true);