shared.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var downinfo = {
  2. pc: 'http://app.autohome.com.cn/apps/1.html',
  3. android: 'http://app.autohome.com.cn/download/Autohome_4.2.5_share.apk',
  4. ios: 'https://itunes.apple.com/cn/app/qi-che-zhi-jia/id385919493?mt=8',
  5. weixin: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.cubic.autohome&ckey=CK1286547003996',
  6. peccancypc: 'http://app.wz.qichecdn.com/down/?from=ceshiaaa',
  7. peccancyweixin: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.autohome.mycar&g_f=991653'
  8. };
  9. var browser = {
  10. versions: function () {
  11. var u = navigator.userAgent,
  12. app = navigator.appVersion;
  13. return {
  14. trident: u.indexOf('Trident') > -1,
  15. presto: u.indexOf('Presto') > -1,
  16. webKit: u.indexOf('AppleWebKit') > -1,
  17. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,
  18. mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
  19. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
  20. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
  21. iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1,
  22. iPad: u.indexOf('iPad') > -1,
  23. webApp: u.indexOf('Safari') == -1,
  24. QQbrw: u.indexOf('MQQBrowser') > -1,
  25. ucLowEnd: u.indexOf('UCWEB7.') > -1,
  26. ucSpecial: u.indexOf('rv:1.2.3.4') > -1,
  27. safari: u.indexOf('Safari') > -1 && u.indexOf("Chrome") < 1,
  28. chrome: u.indexOf("Chrome") > -1,
  29. weixinweibo: u.toLowerCase().indexOf("weibo") > -1 || u.toLowerCase().indexOf("micromessenger") > -1,
  30. ucweb: function () {
  31. try {
  32. return parseFloat(u.match(/ucweb\d+\.\d+/gi).toString().match(/\d+\.\d+/).toString()) >= 8.2
  33. } catch (e) {
  34. if (u.indexOf('UC') > -1) {
  35. return true
  36. } else {
  37. return false
  38. }
  39. }
  40. }(),
  41. Symbian: u.indexOf('Symbian') > -1,
  42. ucSB: u.indexOf('Firefox/1.') > -1
  43. }
  44. }()
  45. };
  46. function dealImg(screenWidth, widths) {
  47. var arr = widths.split(",");
  48. for (var i = 0; i < arr.length; i++) {
  49. if (parseInt(arr[i]) > 0 || arr[i] == "") {
  50. var id = "img_" + arr[i] + "_";
  51. var width = arr[i] == "" ? screenWidth - 20 : ((parseInt(arr[i]) > screenWidth - 20) ? screenWidth - 20 : arr[i]);
  52. var iswidthEmpty = arr[i] == "";
  53. $("img[id^='" + id + "']").each(function () {
  54. var heightValue = iswidthEmpty ? "auto" : width * parseFloat(this.id.split("_")[2]) / parseFloat(this.id.split("_")[1]);
  55. $(this).css({
  56. 'width': width + 'px',
  57. 'height': heightValue + 'px'
  58. })
  59. })
  60. }
  61. }
  62. }
  63. function dealVideoImg(screenWidth, ispc) {
  64. var height = ispc ? "500px" : "185px";
  65. $(".picboxvideo a img").css({
  66. "width": screenWidth + "px",
  67. "height": height
  68. });
  69. if ($(".objectVideo").length > 0) $(".objectVideo").css({
  70. "height": height
  71. });
  72. if ($(".picboxvideo a").length > 0) $(".picboxvideo a").attr("href", $(".picboxvideo a").attr("href").replace('insidebrowser:', ''))
  73. }
  74. function dealArtileLink(sharedType) {
  75. $("a").each(function () {
  76. var curHref = $(this).attr("href");
  77. if (sharedType == 5 && curHref.indexOf('cont.app') > 0) {
  78. //不做替换
  79. }
  80. else if (curHref.indexOf('.autohome.com.cn') > -1 && curHref.indexOf('.m.autohome.com.cn')==-1) {
  81. $(this).attr("href", curHref.replace('.autohome.com.cn', '.m.autohome.com.cn').replace('www.', ''));
  82. if (sharedType == 2) $(this).attr("href", $(this).attr("href").replace('shuoke.', '').replace('article', 'shuoke'))
  83. }
  84. if (curHref.indexOf('actionfrom:browser㊣') > -1 || curHref.indexOf('insidebrowser:') > -1) {
  85. $(this).attr("href", curHref.replace('actionfrom:browser㊣.', '').replace('insidebrowser:', ''))
  86. }
  87. })
  88. }
  89. function applink(fail) {
  90. var link = setTimeout(function () {
  91. window.location = fail
  92. },
  93. 2000)
  94. }
  95. function dealDownLoad(ischeckbrowser, isweixin, isPc, isApple, platForm, sharedType, id, title, bbsid, bbstype,appid) {
  96. var downloadLink = "";
  97. var btnTip = sharedType == 4 ? "下载汽车之家客户端看回帖" : "下载汽车之家客户端看评论";
  98. if (sharedType == 5) btnTip = "下载汽车之家客户端看直播快报";
  99. var openAppurl = "autohome://open?type=" + sharedType + "&id=" + id;
  100. //当是快报详情页分享页面时,在传一个消息id
  101. if (sharedType == 6) {
  102. var messagetype = bbstype.split('|')[0];
  103. var shareimg = bbstype.split('|')[1];
  104. openAppurl = openAppurl + "&messageid=" + bbsid + "&messagetype=" + messagetype + "&title=" + title + "&shareimg=" + shareimg;
  105. }
  106. if (appid == '8')
  107. {
  108. if (isPc) {
  109. downloadLink = downinfo.peccancypc
  110. } else {
  111. downloadLink = downinfo.peccancyweixin;
  112. if (sharedType == 4) openAppurl += "&smallpic=0&title=" + title + "&bbsid=" + bbsid + "&bbstype=" + bbstype
  113. }
  114. }
  115. else
  116. {
  117. if (isPc) {
  118. downloadLink = downinfo.pc
  119. } else {
  120. downloadLink = downinfo.weixin;
  121. if (sharedType == 4) openAppurl += "&smallpic=0&title=" + title + "&bbsid=" + bbsid + "&bbstype=" + bbstype
  122. }
  123. }
  124. if (appid == '8') {
  125. $(".comment-btn-main").html("");
  126. $(".app-btn").attr("href", downloadLink).text("立即下载")
  127. }
  128. else {
  129. if (ischeckbrowser) {
  130. $(".comment-btn").attr("href", openAppurl).html("<i class=\"comment-btn-icon iconfont\"></i>立即打开汽车之家客户端").click(function () {
  131. applink(downloadLink)
  132. });
  133. $(".app-btn").attr("href", openAppurl).text("立即打开").click(function () {
  134. applink(downloadLink)
  135. })
  136. } else {
  137. $(".comment-btn").attr("href", downloadLink).html("<i class=\"comment-btn-icon iconfont comment-down\"></i>" + btnTip);
  138. $(".app-btn").attr("href", downloadLink).text("立即下载")
  139. }
  140. }
  141. }