shake.min.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. var d = !0,
  2. e = null,
  3. g = !1,
  4. h;
  5. function k(a) {
  6. var b, c = this;
  7. this.c = g;
  8. this.e = 0;
  9. this.a = e;
  10. this.p = this.r = this.q = 0;
  11. this.B = 10;
  12. this.D = a;
  13. if (!a || !a.nodeType) throw new TypeError("Layer must be a document node");
  14. this.h = function() {
  15. return k.prototype.h.apply(c, arguments)
  16. };
  17. this.d = function() {
  18. return k.prototype.d.apply(c, arguments)
  19. };
  20. this.k = function() {
  21. return k.prototype.k.apply(c, arguments)
  22. };
  23. this.j = function() {
  24. return k.prototype.j.apply(c, arguments)
  25. };
  26. this.i = function() {
  27. return k.prototype.i.apply(c, arguments)
  28. };
  29. l() || (this.f && (a.addEventListener("mouseover", this.d, d), a.addEventListener("mousedown", this.d, d), a.addEventListener("mouseup", this.d, d)), a.addEventListener("click", this.h, d), a.addEventListener("touchstart", this.k, g), a.addEventListener("touchend", this.j, g), a.addEventListener("touchcancel", this.i, g), Event.prototype.stopImmediatePropagation || (a.removeEventListener = function(b, c, q) {
  30. var r = Node.prototype.removeEventListener;
  31. "click" === b ? r.call(a, b, c.n || c, q) : r.call(a, b, c, q)
  32. },
  33. a.addEventListener = function(b, c, q) {
  34. var r = Node.prototype.addEventListener;
  35. "click" === b ? r.call(a, b, c.n || (c.n = function(a) {
  36. a.A || c(a)
  37. }), q) : r.call(a, b, c, q)
  38. }), "function" === typeof a.onclick && (b = a.onclick, a.addEventListener("click",
  39. function(a) {
  40. b(a)
  41. },
  42. g), a.onclick = e))
  43. }
  44. h = k.prototype;
  45. h.f = 0 < navigator.userAgent.indexOf("Android");
  46. h.b = /iP(ad|hone|od)/.test(navigator.userAgent);
  47. h.g = k.prototype.b && /OS 4_\d(_\d)?/.test(navigator.userAgent);
  48. h.u = k.prototype.b && /OS ([6-9]|\d{2})_\d/.test(navigator.userAgent);
  49. function m(a, b) {
  50. switch (b.nodeName.toLowerCase()) {
  51. case "button":
  52. case "select":
  53. case "textarea":
  54. if (b.disabled) return d;
  55. break;
  56. case "input":
  57. if (a.b && "file" === b.type || b.disabled) return d;
  58. break;
  59. case "label":
  60. case "video":
  61. return d
  62. }
  63. return /\bneedsclick\b/.test(b.className)
  64. }
  65. function n(a) {
  66. switch (a.nodeName.toLowerCase()) {
  67. case "textarea":
  68. case "select":
  69. return d;
  70. case "input":
  71. switch (a.type) {
  72. case "button":
  73. case "checkbox":
  74. case "file":
  75. case "image":
  76. case "radio":
  77. case "submit":
  78. return g
  79. }
  80. return ! a.disabled && !a.readOnly;
  81. default:
  82. return /\bneedsfocus\b/.test(a.className)
  83. }
  84. }
  85. h.focus = function(a) {
  86. var b;
  87. this.b && a.setSelectionRange ? (b = a.value.length, a.setSelectionRange(b, b)) : a.focus()
  88. };
  89. h.k = function(a) {
  90. var b, c, f;
  91. if (1 < a.targetTouches.length) return d;
  92. b = a.target.nodeType === Node.TEXT_NODE ? a.target.parentNode: a.target;
  93. c = a.targetTouches[0];
  94. if (this.b) {
  95. f = window.getSelection();
  96. if (f.rangeCount && !f.isCollapsed) return d;
  97. if (!this.g) {
  98. if (c.identifier === this.p) return a.preventDefault(),
  99. g;
  100. this.p = c.identifier;
  101. var p;
  102. f = b.m;
  103. if (!f || !f.contains(b)) {
  104. p = b;
  105. do {
  106. if (p.scrollHeight > p.offsetHeight) {
  107. f = p;
  108. b.m = p;
  109. break
  110. }
  111. p = p.parentElement
  112. } while ( p )
  113. }
  114. f && (f.v = f.scrollTop)
  115. }
  116. }
  117. this.c = d;
  118. this.e = a.timeStamp;
  119. this.a = b;
  120. this.q = c.pageX;
  121. this.r = c.pageY;
  122. 200 > a.timeStamp - this.o && a.preventDefault();
  123. return d
  124. };
  125. h.j = function(a) {
  126. var b, c, f;
  127. f = this.a;
  128. b = a.changedTouches[0];
  129. c = this.B;
  130. if (Math.abs(b.pageX - this.q) > c || Math.abs(b.pageY - this.r) > c || 300 < a.timeStamp - this.e) this.c = g,
  131. this.a = e;
  132. if (!this.c) return d;
  133. if (200 > a.timeStamp - this.o) return this.t = d;
  134. this.o = a.timeStamp;
  135. b = this.e;
  136. this.c = g;
  137. this.e = 0;
  138. this.u && (f = a.changedTouches[0], f = document.elementFromPoint(f.pageX - window.pageXOffset, f.pageY - window.pageYOffset));
  139. c = f.tagName.toLowerCase();
  140. if ("label" === c) {
  141. if (b = void 0 !== f.control ? f.control: f.htmlFor ? document.getElementById(f.htmlFor) : f.querySelector("button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea")) {
  142. this.focus(f);
  143. if (this.f) return g;
  144. f = b
  145. }
  146. } else if (n(f)) {
  147. if (100 < a.timeStamp - b || this.b && window.top !== window && "input" === c) return this.a = e,
  148. g;
  149. this.focus(f);
  150. if (!this.g || "select" !== c) this.a = e,
  151. a.preventDefault();
  152. return g
  153. }
  154. if (this.b && !this.g && (b = f.m) && b.v !== b.scrollTop) return d;
  155. m(this, f) || (a.preventDefault(), document.activeElement && document.activeElement !== f && document.activeElement.blur(), b = a.changedTouches[0], a = document.createEvent("MouseEvents"), a.initMouseEvent("click", d, d, window, 1, b.screenX, b.screenY, b.clientX, b.clientY, g, g, g, g, 0, e), a.w = d, f.dispatchEvent(a));
  156. return g
  157. };
  158. h.i = function() {
  159. this.c = g;
  160. this.a = e
  161. };
  162. h.d = function(a) {
  163. return ! this.a || a.w || !a.cancelable ? d: !m(this, this.a) || this.t ? (a.stopImmediatePropagation ? a.stopImmediatePropagation() : a.A = d, a.stopPropagation(), a.preventDefault(), g) : d
  164. };
  165. h.h = function(a) {
  166. if (this.c) return this.a = e,
  167. this.c = g,
  168. d;
  169. if ("submit" === a.target.type && 0 === a.detail) return d;
  170. a = this.d(a);
  171. a || (this.a = e);
  172. return a
  173. };
  174. function l() {
  175. var a;
  176. if ("undefined" === typeof window.ontouchstart) return d;
  177. if (/Chrome\/[0-9]+/.test(navigator.userAgent)) if (k.prototype.f) {
  178. if ((a = document.querySelector("meta[name=viewport]")) && -1 !== a.content.indexOf("user-scalable=no")) return d
  179. } else return d;
  180. return g
  181. }
  182. var t = [];
  183. function u(a) {
  184. if ( - 1 != t.indexOf(a)) return g;
  185. t.push(a);
  186. return new k(a)
  187. }
  188. "undefined" !== typeof define && define.C ? define(function() {
  189. return k
  190. }) : "undefined" !== typeof module && module.l ? (module.l = u, module.l.s = k) : window.s = k;
  191. u(document);
  192. var v = document,
  193. w = window,
  194. x = 0,
  195. y = 0,
  196. z = 0,
  197. A = 0,
  198. B = 0,
  199. C = 0,
  200. D = 0,
  201. E = 0,
  202. F = g,
  203. G = 0,
  204. H = 0,
  205. I = d,
  206. J = g;
  207. function K(a) {
  208. a = a.accelerationIncludingGravity;
  209. var b = (new Date).getTime(),
  210. c = 0,
  211. c = 0;
  212. if (100 < b - D) {
  213. c = b - D;
  214. D = b;
  215. x = a.x;
  216. y = a.y;
  217. z = a.z;
  218. c = 1E4 * (Math.abs(x + y + z - A - B - C) / c);
  219. if (I && 500 < c) {
  220. if (E = D, F || (F = d, L()), G += c / 500 / 4, G = 100 <= G ? 100 : G, M(), J || (J = d, document.getElementById("shake").play()), 100 == G) {
  221. clearTimeout(N);
  222. I = g;
  223. v.querySelector(".main").className = "main open";
  224. v.getElementById("fizzing").play();
  225. a = 0;
  226. b = v.querySelector(".time").innerHTML;
  227. v.getElementById("t").innerHTML = b;
  228. 2E4 > O && (a = parseInt(100 * ((2E4 - O) / 2E4)));
  229. v.getElementById("b").innerHTML = a + "%";
  230. P = "我用" + b + "秒摇爆可乐,击败了" + a + "%燥热的人,快来全民摇可乐!";
  231. v.querySelector(".progress_num").style.display = "none";
  232. setTimeout(Q, 3E3);
  233. clearTimeout(R);
  234. document.querySelector(".ready").className = "ready";
  235. try {
  236. w._hmt.push(["_trackEvent", "CM_shake_cola", "devicemotion", "CM_shake_cola_shake_success", "1"])
  237. } catch(f) {}
  238. dp_submitScore(b,a);
  239. }
  240. } else I && 1E3 < b - E && (G--, G = 0 >= G ? 0 : G, M());
  241. A = x;
  242. B = y;
  243. C = z
  244. }
  245. }
  246. var R = e;
  247. function L() {
  248. v.querySelector(".ready").style.display = "none";
  249. v.querySelector(".progress_num").style.display = "block";
  250. H = (new Date).getTime();
  251. S();
  252. document.getElementById("shake").play();
  253. R = setTimeout(function() {
  254. document.querySelector(".ready").className = "ready ready_lost"
  255. },
  256. 5E3);
  257. try {
  258. w._hmt.push(["_trackEvent", "CM_shake_cola", "devicemotion", "CM_shake_cola_shake_start", "1"])
  259. } catch(a) {}
  260. }
  261. function M() {
  262. v.querySelector(".progress").style.height = G + "%";
  263. v.querySelector(".bf_2").innerHTML = parseInt(G) + "%";
  264. v.querySelector(".bf").innerHTML = parseInt(100 - G) + "%";
  265. 0 == G ? v.querySelector(".bf").style.fontSize = "16px": v.querySelector(".bf").style.fontSize = "20px"
  266. }
  267. var N = e,
  268. O = 0;
  269. function S() {
  270. var a = (new Date).getTime() - H,
  271. b = 0,
  272. c = a.toString().substr(a.toString().length - 3);
  273. str = "";
  274. 1E3 <= a ? (b = parseInt(a / 1E3), 10 > b && (b = b)) : b = "0";
  275. str = b + "." + c;
  276. v.querySelector(".time").innerHTML = str;
  277. O = a;
  278. clearTimeout(N);
  279. N = setTimeout(S, 50)
  280. }
  281. function Q() {
  282. v.querySelector(".main").className = "main";
  283. v.querySelector(".layer").style.display = "block";
  284. v.querySelector(".time").style.display = "none"
  285. }
  286. function T() {
  287. clearTimeout(N);
  288. clearTimeout(R);
  289. document.querySelector(".ready").className = "ready";
  290. R = setTimeout(function() {
  291. document.querySelector(".ready").className = "ready ready_lost"
  292. },
  293. 5E3);
  294. E = G = H = 0;
  295. F = g;
  296. v.querySelector(".ready").style.display = "block";
  297. v.querySelector(".time").innerHTML = "00:000";
  298. v.querySelector(".progress").style.height = "0";
  299. v.querySelector(".layer").style.display = "none";
  300. v.querySelector(".time").style.display = "block";
  301. I = d
  302. }
  303. var W = "",
  304. X = "",
  305. Y = "",
  306. P = "我正在玩全民摇可乐,你也过来试一试,看你有多快!";
  307. (function() {
  308. w.addEventListener("devicemotion", K, g);
  309. w.navigator.userAgent.toLowerCase().match(/MicroMessenger/i);
  310. R = setTimeout(function() {
  311. document.querySelector(".ready").className = "ready ready_lost"
  312. },
  313. 5E3);
  314. v.getElementById("shake").addEventListener("ended",
  315. function() {
  316. J = g
  317. },
  318. g);
  319. v.getElementById("tryagain").addEventListener("click",
  320. function() {
  321. try {
  322. w._hmt.push(["_trackEvent", "CM_shake_cola", "click", "CM_shake_cola_restart", "1"])
  323. } catch(a) {}
  324. T()
  325. },
  326. g);
  327. })();