Watch 3 Star 2 Fork 0

huhu呼呼 / Make DUOSHUO Show UAJavaScript

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
使多说评论显示UA,代码才20行而已是不是很坑爹(不算css) spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

#Make DUOSHUO Show UA

版本:0.1
反馈:http://jibushengdan.tk/make_duoshuo_show_ua.jbsd

##简介

字面意思:使多说评论显示ua
代码仅20行
该代码依赖ua-parser解析ua,地址:https://github.com/faisalman/ua-parser-js

##使用

见test.html
如自定义显示颜色css请加.this_ua.platform.相关名称(注意大小写)

##建议

如果不知道将以下代码放在何处你可以考虑放在文章节点末尾

	<script type="text/javascript">
	if (typeof DUOSHUO !== 'undefined')hookDUOSHUO_tp();
	else $('[src="http://static.duoshuo.com/embed.js"]')[0].onload=hookDUOSHUO_tp;
	function hookDUOSHUO_tp(){
		var _D_post=DUOSHUO.templates.post
		DUOSHUO.templates.post=function (e,t){
			var rs=_D_post(e,t);
			if(e.agent&&/^Mozilla/.test(e.agent))rs=rs.replace(/<\/div><p>/,show_ua(e.agent)+'</div><p>');
			return rs;
		}
	}
	function show_ua(string){
		console.log(string)
		$.ua.set(string);
		var sua=$.ua;
		if(sua.os.version=='x86_64')sua.os.version='x64';
		return '<span class="this_ua platform '+sua.os.name+'">'+sua.os.name+' '+sua.os.version+'</span><span class="this_ua browser '+sua.browser.name+'">'+sua.browser.name+'|'+sua.browser.version+'</span>';
	}
	</script>

###无刷新加载的请使用下面代码 <script type="text/javascript"> if (typeof DUOSHUO !== 'undefined')hookDUOSHUO_tp(); else $('[src="http://static.duoshuo.com/embed.js"]')[0].onload=hookDUOSHUO_tp; var hookDUOSHUO_bl=false; function hookDUOSHUO_tp(){ if(hookDUOSHUO_bl)return; else hookDUOSHUO_bl=true; var _D_post=DUOSHUO.templates.post; DUOSHUO.templates.post=function (e,t){ var rs=_D_post(e,t); if(e.agent&&/^Mozilla/.test(e.agent))rs=rs.replace(/</div>

/,show_ua(e.agent)+'

'); return rs; } } function show_ua(string){ console.log(string) $.ua.set(string); var sua=$.ua; if(sua.os.version=='x86_64')sua.os.version='x64'; return ''+sua.os.name+' '+sua.os.version+''+sua.browser.name+'|'+sua.browser.version+''; } </script>

Comments ( 0 )

You need to Sign in for post a comment

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025