// Traffic Stats of the entire Web site By baidu end document.write(""); document.write(""); var _gaq = []; var userAgent = navigator.userAgent.toLowerCase(); // Traffic Stats of the entire Web site By baidu var _hmt = _hmt || []; (function() { var getCookie =function (objName){//获取指定名称的cookie的值 var arrStr = document.cookie.split("; "); for(var i = 0;i < arrStr.length;i ++){ var temp = arrStr[i].split("="); if(temp[0] == objName && objName=="UD") return decodeURIComponent(temp[1]); if(temp[0] == objName) return decodeURI(temp[1]); } } var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?6bcd52f51e9b3dce32bec4a3997715ac"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); // Traffic Stats of the entire Web site By baidu end /** * 判断是否是博客网站 * @return {Boolean} [description] */ function is_blog(){ var loac_host = window.location.host; if(loac_host.indexOf("blog")=== 0)return true; else return false; } function siteId(){ var loac_host = window.location.host; // loac_host ='www.csdn.net' var siteId; if(loac_host.indexOf("blog")=== 0){ siteId = 'UA-127895514-2' }else if(loac_host.indexOf("download")=== 0){ siteId = 'UA-127895514-8' } else if(loac_host.indexOf("edu")=== 0){ siteId = 'UA-127895514-9' } else if(loac_host.indexOf("bbs")=== 0){ siteId = 'UA-127895514-4' }else if(loac_host.indexOf("ask")=== 0){ siteId = 'UA-127895514-5' }else if(loac_host.indexOf("gitbook")=== 0){ siteId = 'UA-127895514-10' }else if(loac_host.indexOf("iteye")=== 0){ siteId = 'UA-127895514-6' }else if(loac_host.indexOf("passport")=== 0){ siteId = 'UA-127895514-7' }else if(loac_host.indexOf("so")=== 0){ siteId = 'UA-127895514-3' }else if(loac_host.indexOf("www")=== 0){ if (loac_host.indexOf("iteye")>0){ siteId = 'UA-127895514-6' }else { siteId = 'UA-127895514-1' } }else { siteId = '' } return siteId } /** * 确定是否博客并有用户名 * @return {Boolean} [description] */ function is_bloger() { try { if(is_blog() && username){ return true; } } catch (e) { return false; } } !(function($){ var currUser={ userName:"", userNick:'设置昵称', desc : '编辑自我介绍,让更多人了解你', avatar:"//csdnimg.cn/public/common/toolbar/images/100x100.jpg" }; var prodLogo = "none"; var $oScriptTag =$("#toolbar-tpl-scriptId"); var skin =$oScriptTag.attr("skin")=="black"?" csdn-toolbar-skin-black ":""; var fixed = $oScriptTag.attr("fixed")=="top"?" navbar-fixed-top ":""; var prodIndex= $oScriptTag.attr("domain")?$oScriptTag.attr("domain"):window.location.protocol+"//"+window.location.host; prodIndex+='_logo'; var getCookie =function (objName){//获取指定名称的cookie的值 var arrStr = document.cookie.split("; "); for(var i = 0;i < arrStr.length;i ++){ var temp = arrStr[i].split("="); if(temp[0] == objName && objName=="UD") return decodeURIComponent(temp[1]); if(temp[0] == objName) return decodeURI(temp[1]); } } var setCookie = function (name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();// + ";domain=.csdn.net;path=/"; } var HTMLEncode =function(str) { var s = ""; if(str.length == 0) return ""; s = str.replace(/&/g, "&").replace(//g, ">").replace(/\'/g, "'").replace(/\"/g, """); return s; } var AUtoAvatar = function(AU){ if(!AU||!currUser.userName){ return false; } var _AUPath = AU.split("").join("/"); var userName = currUser.userName&&currUser.userName.toLowerCase(); return "//profile.csdnimg.cn/"+_AUPath+"/2_"+userName; } var hasLogin = false; var loginMark ="unlogin"; function checkLogin(callback) { currUser.userNick = getCookie("UserNick") ||currUser.userNick; currUser.userName = getCookie("UserName") || currUser.userName; currUser.avatar = AUtoAvatar(getCookie("AU")) || currUser.avatar; currUser.desc = getCookie("UD") || currUser.desc; if(getCookie("UD")){ currUser.desc = HTMLEncode(currUser.desc.replace(/\+/g," ")); } callback(currUser); } checkLogin(function(currUser){ if(currUser.userName){ hasLogin = true; _hmt.push(['_setUserTag', '5744', currUser.userName]); } loginMark = hasLogin?"":"unlogin"; }) /* * init pord logo */ var prodJSON = { "blog" : "blog-icon", "download" : "down-icon", "bbs" : "bbs-icon", "my" :"space-icon", "code" : "code-icon", "share" : "share-icon", "tag" : "tag-icon", "dashboard":"dashboard-icon", "news" : "news-icon", "tag" : "tag-icon", "ask" : "ask-icon", "notify" : "notify-icon" } if(prodJSON[$oScriptTag.attr("prod")]){ prodLogo=prodJSON[$oScriptTag.attr("prod")]||$oScriptTag.attr("prod"); } /** * 二级域名 getSecondaryDomain * @return {string} 二级域名 */ var getSecondaryDomain = (function () { var host = window.location.host; return host.split('.')[0] })() // festival customize var start_time = 1546012800, // toolbar 特殊样式起始时间戳new Date(2018,11,29).getTime()/1000 end_time = 1546358400, // toolbar 特殊样式结束时间戳 now_time = Math.floor(Date.now() / 1000), // 当前时间戳 logo_tpl = '', // 正常样式 logo_title = 'CSDN首页', // 正常提示 logo_href= 'https://www.csdn.net'; /** * 当前时间在起始与结束时间内时触发 */ // if(now_time > start_time && now_time start_time && now_time < end_time ){ // logo_tpl = ''; // logo_title = '中秋节'; // } if(now_time > start_time && now_time < end_time ){ logo_tpl = ''; logo_title = 'csdn-newyear'; } var input_placeholder = "搜CSDN"; if (is_bloger()) { input_placeholder = "搜博主文章" } // 因为 logo 是SVG 的,所以必须把 iconfont.js 加入到代码里面 var protocol = location.protocol.substr(0, 4) === 'http' ? '' : 'http:'; document.write(''); // 注册url,https://passport.csdn.net/account/register //
  • 首页
  • \ //
  • CSTO
  • \ //
  • GitChat
  • \ //
    反馈
    \ //

    扫码下载安卓版

    \ //
  • TinyMind
  • //
  • ITeye
  • \ var tpl ='\
    \
    \ \ \
    \
    '; $(document.body).prepend($(tpl)); $('#csdn-toolbar .logout').click(function(){ window.location.href = 'https://passport.csdn.net/account/logout?from='+encodeURIComponent(window.location.href); }) var timeOut = 1; if((window.location.host.indexOf('bbs.csdn.net')>-1 && window.location.pathname.indexOf('home')>-1)||(window.location.host.indexOf('bbs.csdn.net')>-1 && window.location.pathname.indexOf('forums')>-1)){ $('.csdn-toolbar').addClass('csdn-toolbarbbshome') } function istracking(){ if(timeOut>10){ return false; } try { if(typeof(csdn.trackingAd) === 'function'){ bindTracking(); }else{ timeOut++; setTimeout(istracking,1000); } } catch (e) { timeOut++; setTimeout(istracking,1000); } } istracking(); function bindTracking(){ csdn.trackingAd('.toolbar-tracking', { pid: 'toolbar', mod: 'popu_366', mtp: '1' }); // search_bar csdn.trackingAd('.search_bar', { pid: 'toolbar', mod: 'popu_369', mtp: '1' }); csdn.trackingAd('.write-bolg-btn', { pid: 'toolbar', mod: 'popu_370', mtp: '1' }); } // 消息新接口 (function() { if(!hasLogin) return ; var url = '//msg.csdn.net/v1/web/message/view/unread'; var maxNum = 10; var elems = $('#msgList a em'); var msgCircle = $('#msg-circle'); var docTitle = document.head.getElementsByTagName('title'); var docTitleText; docTitle = docTitle && docTitle[0]; docTitle && (docTitleText = docTitle.innerHTML); $.ajax({ url: url, type: 'post', xhrFields: { withCredentials: true }, dataType: 'json', success: function (json) { var len; if (json.status) { json = json.data; // || { // comment: 100, // follow: 5, // invitation: 8, // system: 0, // thumb_up: 2, // totalCount: 9 // }; if((len = json.totalCount) > 0){ if (len >= maxNum){ len = '9+'; } len && docTitle && (docTitle.innerHTML = '(' + len + '条消息)' + docTitleText) msgCircle.html(len).fadeIn(); elems.each(function (i, el) { var oClass = $(el).attr('class'); var strNum = Number(json[oClass], 10); if (strNum >= maxNum) { strNum = (maxNum-1) + '+' } strNum && $(el).html(strNum); }) } } }, error: function (err) { console.error('消息服务错误!', err, err.responseText) } }); })() /* 全站新添修改 @description toolbar调整 gitchat全站通栏广告添加 */ $(function(){ // control bbs toolbar function controlToolBarBBs(){ if($('#main-home').hasClass('open')){ $('#csdn-toolbar').addClass('tb_bbs'); } $('.left_side > span').on('click',function(){ if($(this).hasClass('btn_toggle_yc')){ $('#csdn-toolbar').removeClass('tb_bbs'); } if($(this).hasClass('btn_toggle_xs')){ $('#csdn-toolbar').addClass('tb_bbs'); } }); } // gitchat 广告全站添加 function advert(){ var t = 2000, cookieTime = 60*60*24, cookieKey = 'is_advert', domain = '.csdn.net', isStart = false, advertDate = { start: '2018/06/07 06:00:00', end: '2018/06/30 00:00:00' }; // contronl start isStart = adverControlDate(); // clear cookie if(!isStart){ // clear is_advert if(getCookie(cookieKey)){ setCookie(cookieKey, '', 0); } return false; } dynamicTpl({ posDom: $('#csdn-toolbar') },function(opts){ var optDom, adDom, closeDom, adDomLink; optDom = opts.optDom; adDom = opts.tplDom; closeDom = $('#js_advert_close'); adDomLink = adDom.find('.advert-a').get(0); // 点击关闭 closeDom.on('click', function(){ advertClose(adDom); return false; }) // 验证是否存在 if(getCookie(cookieKey)){ adDom.addClass('advert-cur'); return false; }else{ adDom.addClass('advert-ex'); } // start animation setMove(function(){ // 缩小 adDom.removeClass('advert-ex'); return true; },function(flg){ setMove(function(){ adDom.addClass('advert-cur'); return true; },200) // 写入cookie if(flg){ if(!getCookie(cookieKey)){ setCookie(cookieKey, '', cookieTime); } } }, t); }); // 控制动画流程 function setMove(beforeCallback, callback, t){ var flg; if(!beforeCallback){ return false; } if(callback && typeof callback === 'number' && Number(callback, 10) > 0){ t = callback; } if(!t){ return false; } setTimeout(function(){ flg = beforeCallback(); if(flg){ typeof callback === 'function' && callback(flg); } }, t); } // cookie设定 function setCookie(key, value, t){ var oDate = new Date(); var dayTime = oDate.getDate() + t; var v; oDate.setDate(dayTime); v = value || oDate.toGMTString(); document.cookie = key + '=' + encodeURIComponent(v) + '; max-age=' + t + '; domain=' + domain; return true; } // 获得cookie function getCookie(key){ var cookies = document.cookie; var a = cookies.split('; '), b, c; for(var i=0; i= advertStart && curTime < advertEnd){ flg = true; } return flg; } // control tpl function dynamicTpl(options, callback){ var opts, optDom, adDom, styl, tpl; opts = options ? options : null; if(!opts){ return false; } optDom = opts.posDom ? opts.posDom instanceof jQuery ? opts.posDom : $(opts.posDom) : null; if(!optDom){ return false; } styl = ''; tpl = ''; if(optDom.length<=0){ return false; } optDom = optDom[0]; adDom = $(tpl); document.head.insertBefore($(styl)[0], document.head.getElementsByTagName('title')[0]); document.body.insertBefore(adDom[0], optDom); callback && typeof callback === 'function' && callback({optDom: $(optDom), tplDom: adDom}); } } // run controlToolBarBBs(); advert(); }) // hover $(function(){ var moreHover={ showMore: function(){ var $dom = $('.show-more .more'); if($dom.is(":animated")){ $dom.stop(true,true).fadeIn(200); } $dom.stop(true,true).fadeIn(200); }, hideMore:function(){ var $dom = $('.show-more .more'); if($dom.is(":animated")){ $dom.stop(true,true).fadeIn(200); } $dom.stop(true,true).fadeOut(300); } } var userHover={ showMore: function(tagBox, tag){ var $dom = $(tagBox); if($dom.is(":animated")){ $dom.stop(true,true).fadeIn(200); } $dom.stop(true,true).fadeIn(200); tag && $(tag).hide() }, hideMore:function(tagBox){ var $dom = $(tagBox); if($dom.is(":animated")){ $dom.stop(true,true).fadeIn(200); } $dom.stop(true,true).fadeOut(300); } } var appHover={ showMore: function(){ var $dom = $('.appControl'); if($dom.is(":animated")){ $dom.stop(true,true).fadeIn(200); } $('.app-btn a').css('color','#C03A3A') $dom.stop(true,true).fadeIn(200); }, hideMore:function(){ var $dom = $('.appControl'); if($dom.is(":animated")){ $dom.stop(true,true).fadeIn(200); } $('.app-btn a').css('color','') $dom.stop(true,true).fadeOut(300); } } $('.show-more').hover(moreHover.showMore,moreHover.hideMore) $('.userLogin').hover(function () { userHover.showMore('.userControl', '.guo_tip_box') }, function () { userHover.hideMore('.userControl') }) $('.app-btn').hover(appHover.showMore,appHover.hideMore) $('.guo_tip_box').hover(function(){ $(this).css('display','none') $.get('https://statistic.csdn.net/toolbar/followTipsclose'); }) $('.blog_tip_box').hover(function(){ $(this).css('display','none') }) // 消息下拉 $('#msgBox').hover(function () { hasLogin && userHover.showMore('#msgList') }, function () { hasLogin && userHover.hideMore('#msgList') }) // 必须是在登录之后展示 并且存cookie if(hasLogin && !getCookie('blogTipShow')){ $('.write-bolg-btn .blog_tip_box').show() } else { $('.write-bolg-btn .blog_tip_box').hide() } $(document).on('click','#blogClick',function(){ setCookie('blogTipShow',true) }) if(!getCookie('c_adb')){ var importCheck = document.createElement('script'); importCheck.type="text/javascript"; importCheck.src = 'https://g.csdnimg.cn/check-adb/1.0.3/check-adb.js'; document.head.appendChild(importCheck); } }) // search $(function(){ //获取 网站位置 function getT(){ var title = window.location.host.split( ".",1)[0]; var t = '' switch (title) { case 'www': t = ' ' break; case 'blog': t = 'blog' break; case 'blog': t = 'codes_snippet' break; case 'bbs': t = 'discuss' break; case 'download': t = 'doc' break; case 'ask': t = 'ask' break; case 'gitchat': t = 'gitchat' break; case 'geek': t = 'news' break; case 'edu': t = 'course' break; default: t = ' ' } return t; } /** * 尝试获取用户名,拼接搜索链接 * @return {[type]} [description] */ function get_user_name(){ var addusername = "&u="; if(is_bloger()){ addusername += username; } return addusername; } function goFn(obj,txt){ var searchTxt = encodeURIComponent(txt), url = "//so.csdn.net/so/search/s.do?q="+searchTxt + "&t="+getT()+get_user_name(); if(searchTxt == ''){ return false; }else{ window.open(url) } } var searchBtn = $(".btn-search"), searchInpt = $(".input_search"), _this = this; //高亮当前导航 var myNav=document.getElementById("nav-left-menu").getElementsByTagName("a"); var currenturl = document.location.href; currenturl = currenturl.substr(currenturl.indexOf('/')); if(currenturl.indexOf('//edu.csdn.net')!=-1){ input_placeholder = "搜索学院课程" $('#toolber-keyword')[0].setAttribute('placeholder',input_placeholder) } //学院搜索 function eduSearch(obj,txt){ var searchTxt = encodeURIComponent(txt), url = "https://so.csdn.net/so/search/s.do?q="+searchTxt+"&t=course" if(searchTxt == ''){ return false; }else{ window.open(url) } } for(var i=0;i0){ $('.btn-search').detach(); $('.search_bar').append(''); }else{ $('.btn_clear').detach(); $('.search_bar').append(''); } } // toolbar_prompt_hover($('.write-bolg-btn a'),'写博客') // toolbar_prompt_hover($('.gitChat a'),'发布Chat') // toolbar_prompt_hover($('.search_bar'),'err') function toolbar_prompt_hover(e,text){ e = e instanceof jQuery ? e:$(e); e.css({'position':'relative'}) var con = { e:e, text:text, isbind:false }, isHave = false; this.events = this.events ? this.events : [con]; for (var i = 0; i < this.events.length; i++) { if(this.events[i].e[0] == e[0]){ this.events[i].text = text; this.events[i].e.children('.toolbar-prompt-box').text(this.events[i].text); isHave = true; } } if(!isHave){ this.events.push(con); isHave= false } if(!this.events[this.events.length-1].isbind){ toolbar_binding(this.events[this.events.length-1]) this.events[this.events.length-1].isbind = true; } } function toolbar_binding(evens){ var even = evens.e; t = evens.text; even.append(toolbar_tpls(t)) var even_children = even.children('.toolbar-prompt-box'), even_children_w = even_children.width(), even_width = even.width(); even_children.css({'left':-((even_children_w+16-even_width)/2)}).children().css({'left':(even_children_w+16)/2-5}) even.hover(toolbar_prompt_show,toolbar_prompt_hide) } function toolbar_tpls(t) { var tpl = '
    \
    \ '+t+'\
    '; return tpl; } function children_show(t){ $(t).children('.toolbar-prompt-box').fadeIn(500) } var clearTime;//计时器id function toolbar_prompt_show() { if($(this).children('.toolbar-prompt-box').is(":animated")){ $(this).children('.toolbar-prompt-box').stop(true,true).css({'display':'block'}) }else{ clearTime = setTimeout(children_show,1000,this); } } function toolbar_prompt_hide() { clearTimeout(clearTime) $(this).children('.toolbar-prompt-box').fadeOut(500) } // 阻止 $(document).on('click','.prevent_a',function(e){ e.preventDefault(); }); function loadScript(url, callback){ var script = document.createElement ("script") script.type = "text/javascript"; if (script.readyState){ //IE script.onreadystatechange = function(){ if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; callback(); } }; } else { //Others script.onload = function(){ callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); } loadScript("//csdnimg.cn/search/baidu_opensug-1.0.0.js",function(){ BaiduSuggestion.bind("toolber-keyword",{ "XOffset":"0", "YOffset":"-5", "fontSize":"14px", //文字大小 "width" : 200, "line-height" : "35px", "padding" : "0 10px", "borderColor":"#e2e2e2", //提示框的边框颜色 "bgcolorHI":"#f44444", //提示框高亮选择的颜色 "sugSubmit":false //在选择提示词条是是否提交表单 }); }); }) })(jQuery);