var token; if(isEmpty(token)){ var meta = $("meta[name=_uid]"); if(!isEmpty(meta)){ token = meta.attr("content"); console.log("token is uid:" + token); } } var swiperNewMessage = new Swiper(".newslist", { direction: "vertical", slidesPerView: 10, loop: true, autoplay: { delay: 2500, disableOnInteraction: false, }, }); var swiperRepo = new Swiper(".homepro-list", { slidesPerView: 3, slidesPerColumn: 2, slidesPerColumnFill:'row', spaceBetween: 30, pagination: { el: ".swiper-pagination", clickable: true, }, autoplay: { delay: 2500, disableOnInteraction: false, }, }); var output = document.getElementById("newmessage"); console.log("document.location.host="+document.location.host); console.log("document.URL="+document.URL); var url = "ws://" + document.location.host + "/action/notification"; if(document.location.host == "git.openi.org.cn" || document.URL.startsWith("https")){ url = "wss://" + document.location.host + "/action/notification" } var socket = new WebSocket(url); socket.onopen = function () { messageQueue = []; console.log("message has connected."); }; var maxSize = 20; var html =document.documentElement; var lang = html.attributes["lang"] var isZh = true; if(lang != null && lang.nodeValue =="en-US" ){ console.log("the language is " + lang.nodeValue); isZh=false; }else{ console.log("default lang=zh"); } socket.onmessage = function (e) { var data =JSON.parse(e.data) console.log("recevie data=" + e.data) var html = ""; if (data != null){ console.log("queue length=" + messageQueue.length); if(messageQueue.length > maxSize){ delete messageQueue[0]; }else{ messageQueue.push(data); } var currentTime = new Date().getTime(); for(var i = 0; i < messageQueue.length; i++){ var record = messageQueue[i]; var recordPrefix = getMsg(record); var actionName = getAction(record.OpType,isZh); if(record.OpType == "6" || record.OpType == "10" || record.OpType == "12" || record.OpType == "13"){ html += recordPrefix + actionName; html += " " + getIssueText(record) + "" } else if(record.OpType == "7" || record.OpType == "11" || record.OpType == "14" || record.OpType == "15" || record.OpType == "22" || record.OpType == "23"){ html += recordPrefix + actionName; html += " " + getPRText(record) + "" } else if(record.OpType == "1"){ html += recordPrefix + actionName; html += " " + getRepoLink(record) + "" } else if(record.OpType == "9" || record.OpType == "5"){ branch = "" + record.RefName + "" actionName = actionName.replace("{branch}",branch); html += recordPrefix + actionName; html += " " + getRepoLink(record) + "" }else if(record.OpType == "17"){ actionName = actionName.replace("{deleteBranchName}",record.RefName); var repoLink = "" + getRepoLink(record) + "" actionName = actionName.replace("{repoName}",repoLink); html += recordPrefix + actionName; } else if(record.OpType == "2"){ actionName = actionName.replace("{oldRepoName}",record.Content); html += recordPrefix + actionName; html += " " + getRepoLink(record) + "" } else{ continue; } if(record.Repo != null){ var time = getTime(record.CreatedUnix,currentTime); html += " " + time; } html += ""; html += ""; } /*
*/ } console.log("html=" + html) output.innerHTML = html; swiperNewMessage.updateSlides(); swiperNewMessage.updateProgress(); }; function getMsg(record){ var html =""; html += "