forked from hexojs/hexo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hexojs#489 from korvin101/duoshuo-ua-style
修改多说评论UA显示样式
- Loading branch information
Showing
2 changed files
with
62 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,65 @@ | ||
if (typeof DUOSHUO !== 'undefined') { | ||
hook_duoshuo_templates(); | ||
} else { | ||
$('#duoshuo-script')[0].onload = hook_duoshuo_templates; | ||
} | ||
var is_hook_duoshuo = false; | ||
if (typeof DUOSHUO !== 'undefined') hookDUOSHUO_tp(); | ||
else $('[src="http://static.duoshuo.com/embed.js"]')[0].onload = hookDUOSHUO_tp; | ||
|
||
function hook_duoshuo_templates() { | ||
if (is_hook_duoshuo) { | ||
return; | ||
} else { | ||
is_hook_duoshuo = true; | ||
} | ||
var _D_post = DUOSHUO.templates.post; | ||
DUOSHUO.templates.post = function(e, t) { | ||
var rs = _D_post(e, t); | ||
var is_admin; | ||
if (typeof duoshuo_user_ID !== 'undefined') { | ||
if (e.post.author.user_id && (e.post.author.user_id == duoshuo_user_ID)) { | ||
if(duoshuo_admin_nickname){ | ||
is_admin = '<span class="this_ua admin">'+duoshuo_admin_nickname+'</span>' | ||
}else{ | ||
is_admin = '<span class="this_ua admin">博主</span>' | ||
} | ||
} else { | ||
is_admin = ''; | ||
} | ||
} else { | ||
is_admin = ''; | ||
} | ||
var agent = e.post.agent; | ||
if (agent && /^Mozilla/.test(agent)) { | ||
rs = rs.replace(/<\/div><p>/, is_admin + show_ua(agent) + '</div><p>') | ||
}; | ||
return rs; | ||
} | ||
function hookDUOSHUO_tp() { | ||
var _D_post = DUOSHUO.templates.post | ||
DUOSHUO.templates.post = function (e, t) { | ||
var rs = _D_post(e, t); | ||
var agent = e.post.agent; | ||
var isAdmin; | ||
if (typeof duoshuo_user_ID !== 'undefined') { | ||
if (e.post.author.user_id && (e.post.author.user_id == duoshuo_user_ID)) { | ||
if (duoshuo_admin_nickname) { | ||
isAdmin = '<span class="fa">' + duoshuo_admin_nickname + '</span>'; | ||
} else { | ||
isAdmin = '<span class="fa">博主</span>'; | ||
} | ||
} else { | ||
isAdmin = ''; | ||
} | ||
} else { | ||
isAdmin = ''; | ||
} | ||
if (agent && /^Mozilla/.test(agent)) rs = rs.replace(/<\/div><p>/, isAdmin + showUa(agent) + '</div><p>'); | ||
return rs; | ||
} | ||
} | ||
//移动客户端判断 | ||
function checkMobile() { | ||
var isiPad = navigator.userAgent.match(/iPad/i) !== null; | ||
if (isiPad) { | ||
return false; | ||
} | ||
var isMobile = navigator.userAgent.match(/iphone|android|phone|mobile|wap|netfront|x11|java|opera mobi|opera mini|ucweb|windows ce|symbian|symbianos|series|webos|sony|blackberry|dopod|nokia|samsung|palmsource|xda|pieplus|meizu|midp|cldc|motorola|foma|docomo|up.browser|up.link|blazer|helio|hosin|huawei|novarra|coolpad|webos|techfaith|palmsource|alcatel|amoi|ktouch|nexian|ericsson|philips|sagem|wellcom|bunjalloo|maui|smartphone|iemobile|spice|bird|zte-|longcos|pantech|gionee|portalmmm|jig browser|hiptop|benq|haier|^lct|320x320|240x320|176x220/i) != null; | ||
if (isMobile) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function show_ua(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>'; | ||
function showUa(string) { | ||
$.ua.set(string); | ||
var sua = $.ua; | ||
var br = ' '; | ||
var osIco = '<i class="fa fa-desktop"></i> '; | ||
var browserIco = '<i class="fa fa-globe"></i> ' | ||
var osName = sua.os.name; | ||
var browserName = sua.browser.name; | ||
if (checkMobile()) br = '<br><br>'; | ||
|
||
if (osName == 'Android') osIco = '<i class="fa fa-android"></i> '; | ||
if (osName.match(/linux/i)) osIco = '<i class="fa fa-linux"></i> '; | ||
if (osName.match(/mac os|ios/i)) osIco = '<i class="fa fa-apple"></i> '; | ||
if (sua.os.version == 'x86_64') sua.os.version = 'x64'; | ||
|
||
if (browserName.match(/chrome|chromium/i)) browserIco = '<i class="fa fa-chrome"></i> '; | ||
if (browserName.match(/firefox/i)) browserIco = '<i class="fa fa-firefox"></i> '; | ||
if (browserName.match(/opera/i)) browserIco = '<i class="fa fa-opera"></i> '; | ||
if (browserName.match(/safari/i)) browserIco = '<i class="fa fa-safari"></i> '; | ||
if (browserName.match(/ie/i)) browserIco = '<i class="fa fa-internet-explorer"></i> '; | ||
|
||
return br + '<span class="platform ' + sua.os.name + '">' + osIco + | ||
sua.os.name + ' ' + sua.os.version + '</span>' + br + | ||
'<span class="browser ' + sua.browser.name + '">' + browserIco + | ||
sua.browser.name + '|' + sua.browser.version + '</span>'; | ||
} |