code.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. function isWeixin() {
  2. var e = navigator.userAgent.toLowerCase();
  3. if (e.match(/MicroMessenger/i) == "micromessenger") {
  4. return true
  5. } else {
  6. return false
  7. }
  8. }
  9. function closeshare() {
  10. document.getElementById("share-wx").style.display = "none"
  11. }
  12. function closewx() {
  13. document.getElementById("wx-qr").style.display = "none"
  14. }
  15. function addShareWX() {
  16. var e = document.createElement("div");
  17. e.id = "share-wx";
  18. e.onclick = closeshare;
  19. document.body.appendChild(e);
  20. var t = document.createElement("p");
  21. t.style.cssText = "text-align:right;padding-left:10px;";
  22. e.appendChild(t);
  23. }
  24. function addWXQR() {
  25. var e = document.createElement("div");
  26. e.style.cssText = "background:rgba(0,0,0,0.8); position:fixed;top:0px; left:0px; width:100%; height:" + document.height + "px; z-index:10000; display:none;";
  27. e.id = "wx-qr";
  28. e.onclick = closewx;
  29. document.body.appendChild(e);
  30. wxqrP1 = document.createElement("p");
  31. wxqrP1.style.cssText = "text-align:center;width:220px;color:#fff;margin:50px auto 0 auto;font: bold 16px Arial, Helvetica, Microsoft Yahei, 微软雅黑, STXihei, 华文细黑, sans-serif";
  32. wxqrP1.innerHTML = "分享给朋友一起玩!";
  33. e.appendChild(wxqrP1);
  34. }
  35. if (getCookie("num")) {
  36. var nn = parseInt(getCookie("num"));
  37. setCookie("num", ++nn);
  38. } else {
  39. setCookie("num", 1);
  40. }
  41. function getCookie(name)
  42. {
  43. var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
  44. if(arr=document.cookie.match(reg)) return unescape(arr[2]);
  45. else return null;
  46. }
  47. function setCookie(name, value) {
  48. var Days = 30;
  49. var exp = new Date();
  50. exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
  51. document.cookie = name + "=" + escape(value) + ";expires" + exp.toGMTString();
  52. }
  53. function isMobile() {
  54. return navigator.userAgent.match(/android|iphone|ipod|blackberry|meego|symbianos|windowsphone|ucbrowser/i)
  55. }
  56. function isIOS() {
  57. return navigator.userAgent.match(/iphone|ipod|ios/i)
  58. }
  59. var RESOURCE_IMG_PATH = RESOURCE_IMG_PATH || "/vapp/",
  60. HORIZONTAL = HORIZONTAL || false,
  61. COVER_SHOW_TIME = COVER_SHOW_TIME || 2e3;
  62. document.addEventListener("WeixinJSBridgeReady",
  63. function() {
  64. if (HORIZONTAL == true) {
  65. WeixinJSBridge.call("hideToolbar")
  66. }
  67. },
  68. false); (function() {
  69. function n() {
  70. window.scroll(0, 0);
  71. var e;
  72. if (window.orientation == 0 || window.orientation == 180) {
  73. e = false
  74. } else if (window.orientation == -90 || window.orientation == 90) {
  75. e = true
  76. }
  77. if (e == HORIZONTAL) {
  78. t.style.display = "none"
  79. } else {
  80. setTimeout(function() {
  81. r();
  82. t.style.width = window.innerWidth + "px";
  83. t.style.display = "block"
  84. },
  85. isIOS() ? 0 : 600)
  86. }
  87. if (HORIZONTAL == true && isWeixin() && !isIOS()) {
  88. WeixinJSBridge.call("hideToolbar")
  89. }
  90. }
  91. function r() {
  92. e.style.height = window.innerHeight + "px";
  93. e.style.width = window.innerWidth + "px";
  94. t.style.height = window.innerHeight + "px"
  95. }
  96. if (!isMobile()) return;
  97. var e = document.createElement("div");
  98. e.style.cssText = "position:absolute;z-index:1000000;left:0;top:0;background:#6699ff url(" + RESOURCE_IMG_PATH + "cover.jpg) no-repeat center center;background-size: 50%;width:" + window.innerWidth + "px;height:" + Math.max(window.innerHeight, window.document.documentElement.offsetHeight) + "px";
  99. e.className = "common_cover";
  100. document.body.appendChild(e);
  101. setTimeout(function() {
  102. e.parentNode.removeChild(e)
  103. },
  104. COVER_SHOW_TIME);
  105. document.addEventListener("touchmove",
  106. function(e) {
  107. e.preventDefault()
  108. },
  109. false);
  110. var t = document.createElement("div");
  111. t.className = "common_notice";
  112. t.style.cssText = "position:absolute;z-index:999999;left:0;top:0;background:#6699ff url(" + RESOURCE_IMG_PATH + "rotate_tip.jpg) no-repeat center center;background-size: 50%;";
  113. document.body.appendChild(t);
  114. window.addEventListener("orientationchange", n);
  115. window.addEventListener("load", n);
  116. window.addEventListener("scroll", r)
  117. })();
  118. document.oncontextmenu = function() {
  119. return false
  120. };
  121. if (isWeixin()) {
  122. addShareWX()
  123. } else {
  124. addWXQR()
  125. }
  126. /*if (getCookie("num") != 3){
  127. window.onbeforeunload=function(){return " "}
  128. }*/