Paymh

Untitled

Dec 31st, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.80 KB | None | 0 0
  1. $(document).ready(function() {
  2. playVoid();
  3. $(".playerTopMenu .trigger").click(function() {
  4. $(this).toggleClass("active");
  5. if ($(this).is(".active")) {
  6. $(".playerTopMenu .icons.carrot.grey").removeClass("down").addClass("up");
  7. $(".speechBubble").css("z-index", 0);
  8. $(".playerTopMenu").animate({
  9. height: "112px"
  10. }, 200)
  11. } else {
  12. $(".playerTopMenu .icons.carrot.grey").removeClass("up").addClass("down");
  13. $(".playerTopMenu").animate({
  14. height: "45px"
  15. }, 200, function() {
  16. $(".speechBubble").css("z-index", 200)
  17. })
  18. }
  19. });
  20. $("#info-bar .lobbySort").click(function() {
  21. if ($(this).is(".active")) {
  22. $(".carrot", this).removeClass("up").addClass("down");
  23. $(this).removeClass("active")
  24. } else {
  25. $("#info-bar .lobbySort").removeClass("active");
  26. $("#info-bar .lobbySort .carrot").removeClass("up").addClass("down");
  27. $(".carrot", this).removeClass("down").addClass("up");
  28. $(this).addClass("active")
  29. }
  30. });
  31. $(".content-requirements input[type='radio']").change(function() {
  32. update_restrictions($(this).val())
  33. });
  34. $("#game-type").change(function() {
  35. $(".class-reservations").html($("#class-reservations-" + $(this).val()).html());
  36. $(".class-reservations .class-row .slot").click(function() {
  37. if ($(this).hasClass("reserved")) {
  38. $(this).removeClass("reserved");
  39. $(this).children(".reserve").removeClass("lock");
  40. $(this).children(".reserve").addClass("unlock");
  41. $(this).children("label").text("Reserve slot")
  42. } else {
  43. $(this).addClass("reserved");
  44. $(this).children(".reserve").removeClass("unlock");
  45. $(this).children(".reserve").addClass("lock");
  46. $(this).children("label").text("Reserved")
  47. }
  48. });
  49. selected_requirements = $(".content-requirements input[type='radio']:checked").val();
  50. if (selected_requirements == "some-classes-requirements") {
  51. update_restrictions(selected_requirements)
  52. }
  53. });
  54. $("#advancedSettingsLink").click(function() {
  55. if ($(".content-advanced").hasClass("hidden")) {
  56. $("#advancedSettingsLink .carrot").removeClass("right");
  57. $("#advancedSettingsLink .carrot").addClass("left");
  58. $("#_wicket_window_0").animate({
  59. width: [967, "swing"]
  60. }, 200, function() {
  61. $(".content-advanced").removeClass("hidden")
  62. })
  63. } else {
  64. $(".content-advanced").addClass("hidden");
  65. $("#_wicket_window_0").animate({
  66. width: [474, "swing"]
  67. }, 200);
  68. $("#advancedSettingsLink .carrot").removeClass("left");
  69. $("#advancedSettingsLink .carrot").addClass("right")
  70. }
  71. });
  72. $("#shareLinkBtn").click(function() {
  73. $("#linkInput").addClass("selected green");
  74. $("#linkText").removeClass("invisible");
  75. return false
  76. });
  77. $("#enterPasswordBtn").click(function() {
  78. $("#enterPasswordInput").addClass("selected red");
  79. $("#wrongPasswordText").removeClass("invisible");
  80. return false
  81. });
  82. if ($(".wicket-modal input:radio").length) {
  83. $(".wicket-modal input:radio").transformRadio({
  84. base: "image",
  85. checked: "../assets/images/box_checked_dark.png",
  86. unchecked: "../assets/images/box_unchecked_dark.png"
  87. });
  88. $(".wicket-modal input:radio").each(function() {
  89. var A = this;
  90. $("label[for='" + A.id + "']").click(function() {
  91. $("#" + A.id + " + img").click()
  92. })
  93. })
  94. }
  95. $(".playerScrollContainerLoading").addClass("hidden");
  96. $(".playerScrollContainer").removeClass("hidden");
  97. if ($(".scrollable").length) {
  98. $(".scrollable").jScrollPane()
  99. }
  100. initConnectionPanelHeader();
  101. $("textArea#chatInput").keypress(function(A) {
  102. if (A.keyCode == 13) {
  103. A.preventDefault(A)
  104. }
  105. });
  106. $("#FAQmenu h3").click(function() {
  107. $("#FAQmenu ul ul").slideUp();
  108. if (!$(this).next().is(":visible")) {
  109. $(this).next().slideDown()
  110. }
  111. });
  112. $("#info-bar .playersOnline.hideable").click(function() {
  113. if ($(this).is(".active")) {
  114. $(".carrot", this).removeClass("up").addClass("down");
  115. $(this).removeClass("active");
  116. $("#players-online").stop().slideUp(300);
  117. toggleChatSize()
  118. } else {
  119. $("#info-bar .infoPanel").removeClass("active");
  120. $("#info-bar .infoPanel .carrot").removeClass("up").addClass("down");
  121. $(".carrot", this).removeClass("down").addClass("up");
  122. $(this).addClass("active");
  123. $("#players-online").stop().slideDown(300);
  124. toggleChatSize()
  125. }
  126. });
  127. $("#achvFullBtn").click(function() {
  128. if ($(this).hasClass("off")) {
  129. $(this).removeClass("off").addClass("on");
  130. $("#achvCompBtn").removeClass("on").addClass("off");
  131. $(this).parent().removeClass("active");
  132. $(".achvItem").removeClass("ym-g1220-3").addClass("ym-g1220-6");
  133. $(".achvDesc, .achvGrades").show(200)
  134. } else {
  135. return
  136. }
  137. });
  138. $("#achvCompBtn").click(function() {
  139. if ($(this).hasClass("off")) {
  140. $(this).removeClass("off").addClass("on");
  141. $("#achvFullBtn").removeClass("on").addClass("off");
  142. $(this).parent().removeClass("active");
  143. $(".achvItem").removeClass("ym-g1220-6").addClass("ym-g1220-3");
  144. $(".achvDesc, .achvGrades").hide(200)
  145. } else {
  146. return
  147. }
  148. });
  149. $("#achvCompBtn, #achvFullBtn").hover(function() {
  150. if ($(this).hasClass("off")) {
  151. $(this).parent().addClass("active")
  152. }
  153. }, function() {
  154. if ($(this).hasClass("off")) {
  155. $(this).parent().removeClass("active")
  156. }
  157. });
  158. $(".userBansHeader").click(function() {
  159. $(".userBansList").slideToggle(400);
  160. $(".userBansHeader .arrow").toggleClass("down")
  161. });
  162. ranksChartAnimation()
  163. });
  164.  
  165. function update_restrictions(A) {
  166. if (A == "some-classes-requirements") {
  167. $(".class-requirements").html($("#" + A + "-" + $("#game-type").val()).html())
  168. } else {
  169. $(".class-requirements").html($("#" + A).html())
  170. }
  171. }
  172.  
  173. function checkAndAddDefaultPort() {
  174. var A = $("#hostAndPort").val();
  175. if (A != "" && A.indexOf(":") == -1) {
  176. $("#hostAndPort").val(A + ":27015")
  177. }
  178. }
  179.  
  180. function setPreReadyTimer(C, A) {
  181. if ($(document).ready) {
  182. var D = "#pre-ready-timer";
  183. var B = "#pre-ready-button";
  184. $(D).buildCounter({
  185. now_timestamp: A - C,
  186. stardate_timestamp: 0,
  187. enddate_timestamp: A,
  188. color: "#213438",
  189. backgroundcolor: "#3f5a61",
  190. backgroundwidth: "4",
  191. frontwidth: "6",
  192. size: "36",
  193. countsize: "8",
  194. countcolor: "#5f94a2",
  195. callback: function() {
  196. $(D).trigger("click")
  197. },
  198. });
  199. $(B).hide();
  200. $(D).show()
  201. } else {
  202. return
  203. }
  204. }
  205.  
  206. function isMySteamId(A) {
  207. return (typeof mySteamId != "undefined") && (mySteamId == A)
  208. }
  209.  
  210. function initConnectionPanelHeader() {
  211. $("#connectionPanel .connectionHeader span").click(function() {
  212. $(this).toggleClass("active");
  213. if ($(this).is(".active")) {
  214. $("#connectionPanel .connectionHeader .icons.carrot.grey").removeClass("down").addClass("up");
  215. $("#connectionPanel .connectionDetails").stop().slideDown(200, "swing", function() {
  216. $(this).css("display", "table")
  217. })
  218. } else {
  219. $("#connectionPanel .connectionHeader .icons.carrot.grey").removeClass("up").addClass("down");
  220. $("#connectionPanel .connectionDetails").css("display", "block");
  221. $("#connectionPanel .connectionDetails").stop().slideUp(200, "swing")
  222. }
  223. })
  224. }
  225.  
  226. function meetsHoursRestriction(A) {
  227. return typeof A === "undefined" || myTotalHoursPlayed >= A
  228. }
  229.  
  230. function meetsMinimumLobbiesRestriction(A) {
  231. return typeof A === "undefined" || myLobbiesPlayed >= A
  232. }
  233.  
  234. function meetsReliabilityRestriction(A) {
  235. return typeof A === "undefined" || myReliability >= A
  236. }
  237.  
  238. function isHostUp(A) {
  239. result = false;
  240. jQuery.ajax({
  241. url: "http://" + A + "/about",
  242. async: false,
  243. success: function() {
  244. result = true
  245. }
  246. });
  247. return result
  248. }
  249.  
  250. function ranksChartAnimation() {
  251. var C = $(".ranksChartCol").toArray(),
  252. A, B = 0;
  253. A = setInterval(function() {
  254. $(C[B]).slideDown(500, "easeOutBounce");
  255. ++B;
  256. if (C[B] === undefined) {
  257. clearInterval(A);
  258. return
  259. }
  260. }, 50)
  261. }
  262. if (navigator.userAgent.indexOf("Googlebot") == -1) {
  263. if (!("WebSocket" in window) || navigator.userAgent.indexOf("MSIE") > -1 || navigator.userAgent.indexOf("Valve Steam GameOverlay") > -1) {
  264. window.location = "/unsupported"
  265. }
  266. }
  267. $(document).ready(function() {
  268. var A = !("adblockAllowed" in window);
  269. var B = $(".join-steam-group").length;
  270. var C = $(".joinALs").length;
  271. if (A) {
  272. $(".youShallNotPass").show();
  273. $(".youShallNotPass").animate({
  274. height: "26px"
  275. }, 250, "swing")
  276. }
  277. if (B) {
  278. $(".join-steam-group").show();
  279. $(".join-steam-group").animate({
  280. height: "26px"
  281. }, 250, "swing")
  282. }
  283. if (C) {
  284. $(".joinALs").show();
  285. $(".joinALs").animate({
  286. height: "26px"
  287. }, 250, "swing")
  288. }
  289. if (A || B || C) {
  290. $(".youShallNotPassEnabled").animate({
  291. marginTop: "29px"
  292. }, 300, "swing")
  293. } else {
  294. $(".youShallNotPassEnabled").removeClass("youShallNotPassEnabled")
  295. }
  296. });
  297.  
  298. function isBlocked2(A) {
  299. return !A || A.closed || typeof A.closed == "undefined" || A.outerHeight === 0
  300. }
  301.  
  302. function openWindow(B, A) {
  303. var C = window.open(B, A);
  304. setTimeout(function() {
  305. if (isBlocked2(C)) {
  306. alert("Your browser is blocking a new window! Please adjust popup settings for this domain.")
  307. }
  308. }, 1000)
  309. }
  310.  
  311. function playReadySoundHeavy() {
  312. new Audio("/assets/sounds/ready_heavy.wav").play()
  313. }
  314.  
  315. function playLaunchSoundAnnouncer() {
  316. new Audio("/assets/sounds/announcer_am_gamestarting.mp3").play()
  317. }
  318.  
  319. function playIncomingSoundHeavy() {
  320. new Audio("/assets/sounds/incoming_heavy.ogg").play()
  321. }
  322.  
  323. function playPrematureLobbyEnding() {
  324. new Audio("/assets/sounds/heavy_premature_ending.wav").play()
  325. }
  326.  
  327. function playAchievementUnlocked() {
  328. new Audio("/assets/sounds/achievement-unlocked.mp3").play()
  329. }
  330.  
  331. function playTeamsBalanced() {
  332. new Audio("/assets/sounds/gong.mp3").play()
  333. }
  334.  
  335. function playVoid() {
  336. new Audio("/assets/sounds/void.wav").play()
  337. }
  338.  
  339. function delayedReload(A) {
  340. setTimeout("location.href='" + A + "'", 2000)
  341. }
  342.  
  343. function advancedLobbyClearAnimation() {
  344. var A = 0;
  345. players = shufflePlayers($(".blue-team div.playerSlot.lobbySlot, .red-team div.playerSlot.lobbySlot").toArray());
  346. $("#balanceLogo").addClass("balanceProgress");
  347. setInterval(function() {
  348. $(players[A]).children(".showOnHover").hide();
  349. $(players[A]).children(":not(.showOnHover)").fadeToggle(200, function() {
  350. if ($(this).is(":last-child")) {
  351. $(this).parent().css({
  352. "border-bottom": "1px solid #1b1b1b"
  353. }).animate({
  354. "background-color": "#2c2b2b"
  355. }, 200)
  356. }
  357. });
  358. ++A
  359. }, 100)
  360. }
  361.  
  362. function advancedLobbyFillAnimation() {
  363. var A = $(".blue-team div.playerSlot.lobbySlot").toArray(),
  364. C = $(".red-team div.playerSlot.lobbySlot").toArray(),
  365. B = 0;
  366. $("#lobbyPanel").addClass("balanced");
  367. $("#balanceLogo").removeClass("balanceProgress").addClass("balanceDone");
  368. playTeamsBalanced();
  369. $(".blue-team .playerSlot.header.advanced").animate({
  370. "background-color": "#48707d",
  371. "border-bottom-color": "#2e4952"
  372. }, 200, function() {
  373. $(this).removeClass("advanced").addClass("blue")
  374. });
  375. $(".red-team .playerSlot.header.advanced").animate({
  376. "background-color": "#9e403d",
  377. "border-bottom-color": "#66302e"
  378. }, 200, function() {
  379. $(this).removeClass("advanced").addClass("red")
  380. });
  381. setInterval(function() {
  382. $(C[B]).removeClass("balanced-hidden").css({
  383. "border-bottom": "1px solid #2c2b2b"
  384. }).animate({
  385. "background-color": "#1b1b1b"
  386. }, 200);
  387. $(A[B]).removeClass("balanced-hidden").css({
  388. "border-bottom": "1px solid #2c2b2b"
  389. }).animate({
  390. "background-color": "#1b1b1b"
  391. }, 200);
  392. ++B
  393. }, 600)
  394. }
  395.  
  396. function shufflePlayers(A) {
  397. for (var C = A.length - 1; C > 0; C--) {
  398. var B = Math.floor(Math.random() * (C + 1));
  399. var D = A[B];
  400. A[B] = A[C];
  401. A[C] = D
  402. }
  403. return A
  404. }
  405. var friendsArray;
  406. $(document).ready(function() {
  407. setupChatScrollPane(true)
  408. });
  409.  
  410. function isSteamFriend(A) {
  411. if (friendsArray == undefined) {
  412. if (friendsJsonStr == undefined || friendsJsonStr == null) {
  413. return false
  414. }
  415. friendsArray = $.parseJSON(friendsJsonStr)
  416. }
  417. return friendsArray.indexOf(A) !== -1
  418. }
  419.  
  420. function addChatMsg(A, B) {
  421. if (!checkLobbyFilter(B)) {
  422. return
  423. }
  424. var C = $(".chatLinePanel.templateHolder li").clone();
  425. var F = "/profile/" + A.authorSteamId;
  426. var E = new Date(A.created).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1");
  427. C.find(".date").text(E);
  428. C.find(".author").attr("href", F);
  429. if (A.admin) {
  430. C.find(".author .name").addClass("admin");
  431. C.find(".message").addClass("admin")
  432. }
  433. if (A.donator) {
  434. C.find(".author .name").addClass("donator")
  435. } else {
  436. C.find(".donateLink").hide()
  437. }
  438. if (!A.advanced) {
  439. C.find(".icons.playerRank.blue").hide()
  440. }
  441. if (isMySteamId(A.authorSteamId)) {
  442. C.find(".author").addClass("me")
  443. }
  444. if (isSteamFriend(A.authorSteamId)) {
  445. C.find(".author").addClass("friend");
  446. C.find(".author .icons.person").addClass("friend")
  447. }
  448. C.find(".author .name").text(A.authorName);
  449. C.find(".message").html(A.message);
  450. var D = $(".chatScrollContainer").jScrollPane().data("jsp").getIsScrollableV() == false || $(".chatScrollContainer").jScrollPane().data("jsp").getPercentScrolledY() == 1;
  451. $("#chat .chatContainer").append(C);
  452. if ($("#chat .chatContainer > li").size() > 250) {
  453. $("#chat .chatContainer > li").slice(0, -250).remove()
  454. }
  455. setupChatScrollPane(D)
  456. }
  457.  
  458. function checkLobbyFilter(A) {
  459. try {
  460. if (A != null && !lobbyMatchesFilter1(A)) {
  461. return false
  462. }
  463. } catch (B) {}
  464. return true
  465. }
  466.  
  467. function setupChatScrollPane(B) {
  468. if (!$(".chatScrollContainer").length) {
  469. return
  470. }
  471. var A = $(".chatScrollContainer").jScrollPane().data("jsp");
  472. if (B == true || A != null && A.getPercentScrolledY() == 1) {
  473. A.scrollToPercentY(100)
  474. } else {
  475. $(".chatScrollContainer").jScrollPane({
  476. maintainPosition: true
  477. })
  478. }
  479. }
  480.  
  481. function toggleChatSize() {
  482. var A = 535;
  483. if ($(".chatScrollContainer").height() == 535) {
  484. A = 250
  485. }
  486. $(".chatScrollContainer").animate({
  487. height: A
  488. }, {
  489. duration: 300,
  490. queue: false
  491. });
  492. $("#chat .scrollable").animate({
  493. height: A
  494. }, {
  495. duration: 300,
  496. queue: false
  497. });
  498. setTimeout(function() {
  499. $(".chatScrollContainer").jScrollPane().data("jsp").scrollToPercentY(100)
  500. }, 450);
  501. $(".chatPanel").animate({
  502. height: A + 150
  503. }, {
  504. duration: 300,
  505. queue: false
  506. })
  507. }
  508.  
  509. var displayedNotifications = [];
  510.  
  511. function createLobbyOverviewItemElement(E) {
  512. var B = $(".lobby.templateHolder div.lobbyOverviewPanel").clone();
  513. var F = E.no;
  514. B.attr("id", "lobbyOverview-" + F);
  515. B.find("a.lobbyLink").attr("href", "/lobbies/" + F);
  516. B.find(".lobbyID").text("#" + F);
  517. B.find(".icons.flags").addClass(E.region.toLowerCase());
  518. B.find(".mapName").text(E.map);
  519. B.find(".mapThumb img").attr("src", E.thumbnailUrl);
  520. B.find(".gameType").text(E.gameType);
  521. B.find(".restrictionText").text(E.restrictionsText);
  522. B.find(".lobbyPlayerCount").text(E.playersInLobby);
  523. B.find(".lobbySize").text(E.playersForGame);
  524. B.addClass(E.advanced ? "advanced" : "manual");
  525. if (E.mumbleRequired == false) {
  526. B.find(".mumbleReq").remove()
  527. }
  528. if (E.inReadyUpMode == false) {
  529. B.find(".icons.lobbyReady").remove()
  530. }
  531. var A = userCanOverrideRestrictedSlots(E.leaderSteamId);
  532. for (var C = 0; C < E.slots.length; C++) {
  533. var D = createClassSlotElement(F, E.slots[C], A);
  534. B.find(".lobbyClassContainer").append(D)
  535. }
  536. if(displayedNotifications.indexOf(F) === -1) {
  537. var notification = new Notification(E.map,{
  538. tag: F,
  539. icon:E.thumbnailUrl,
  540. body:"Game Type: " + E.gameType + "\r\nPlayers: " + E.playersInLobby + " of " + E.playersForGame + "\r\nCountry: " + E.region
  541. });
  542. notification.onclick = function() {
  543. window.open("/lobbies/" + F, '_blank');
  544. };
  545. notification.onshow = function () { setTimeout(notification.close.bind(notification), 5000); };
  546. displayedNotifications.push(F);
  547. }
  548. return B
  549. }
  550.  
  551. function userCanOverrideRestrictedSlots(A) {
  552. return (typeof canOverrideRestrictedSlots !== "undefined" && canOverrideRestrictedSlots == true) || isMySteamId(A)
  553. }
  554.  
  555. function createClassSlotElement(F, C, B) {
  556. var E = $(".classSlot.templateHolder div").clone();
  557. var G = C.tf2Class;
  558. if (C.availableSlots.length > 0) {
  559. var D = C.availableSlots[0].team;
  560. var A = "/join/lobby/" + F + "/" + D + "/" + G;
  561. E.find(".link").attr("href", A);
  562. if (C.availableSlots.length == 1) {
  563. E.append('<span class="icons available ' + D + '"></span>')
  564. } else {
  565. E.append('<span class="icons available blue"></span>');
  566. E.append('<span class="icons available red"></span>')
  567. }
  568. if (allSlotsHaveRestrictions(C)) {
  569. E.addClass(B || meetsRestrictionsForAnySlot(C) ? "green" : "red")
  570. }
  571. }
  572. if (C.availableReservedSlots.length > 0) {
  573. if (C.availableReservedSlots.length == 1) {
  574. E.append('<span class="icons available reserved-' + C.availableReservedSlots[0].team + '"></span>')
  575. } else {
  576. E.append('<span class="icons available reserved-blue"></span>');
  577. E.append('<span class="icons available reserved-red"></span>')
  578. }
  579. }
  580. if (C.availableSlots.length + C.availableReservedSlots.length == 0) {
  581. E.find(".icons.classes").addClass("unavailable")
  582. }
  583. E.find(".icons.classes").addClass(getCssClassForTf2Class(G));
  584. return E
  585. }
  586.  
  587. function getCssClassForTf2Class(A) {
  588. switch (A) {
  589. case "solly":
  590. return "soldier";
  591. case "demo":
  592. return "demoman";
  593. case "med":
  594. return "medic";
  595. case "engie":
  596. return "engineer";
  597. case "roamer":
  598. return "soldier classextra roamer";
  599. case "pocket":
  600. return "soldier classextra pocket";
  601. default:
  602. return A
  603. }
  604. }
  605.  
  606. function allSlotsHaveRestrictions(B) {
  607. for (var A = 0; A < B.availableSlots.length; A++) {
  608. if ($.isEmptyObject(B.availableSlots[A].restrictions)) {
  609. return false
  610. }
  611. }
  612. return true
  613. }
  614.  
  615. function meetsRestrictionsForAnySlot(C) {
  616. for (var A = 0; A < C.availableSlots.length; A++) {
  617. var B = C.availableSlots[A].restrictions;
  618. if ($.isEmptyObject(B)) {
  619. continue
  620. }
  621. if (!meetsRestrictions(B)) {
  622. continue
  623. }
  624. return true
  625. }
  626. return false
  627. }
  628.  
  629. function meetsRestrictions(A) {
  630. if ($.isEmptyObject(A)) {
  631. return true
  632. }
  633. if (!(meetsHoursRestriction(A.hours))) {
  634. return false
  635. }
  636. if (!(meetsReliabilityRestriction(A.reliability))) {
  637. return false
  638. }
  639. if (!(meetsMinimumLobbiesRestriction(A.games))) {
  640. return false
  641. }
  642. return true
  643. }
  644.  
  645. function replaceAllLobbies(B) {
  646. B = filterLobbies(B);
  647. $("#lobbyContainer").children().remove();
  648. for (var A = 0; A < B.length; A++) {
  649. $("#lobbyContainer").append(createLobbyOverviewItemElement(B[A]))
  650. }
  651. }
  652.  
  653. function replaceSingleLobby(B) {
  654. if ($.cookie("filter") != undefined) {
  655. var A = JSON.parse($.cookie("filter"));
  656. if (A.filterEnabled == true && !lobbyMatchesFilter(B, A)) {
  657. return
  658. }
  659. }
  660. var C = B.no;
  661. $("#lobbyContainer").find("#lobbyOverview-" + C).replaceWith(createLobbyOverviewItemElement(B))
  662. }
  663.  
  664. function filterLobbies(E) {
  665. E = filterRegionLocked(E);
  666. if ($.cookie("filter") == undefined) {
  667. return E
  668. }
  669. var C = JSON.parse($.cookie("filter"));
  670. var A = [];
  671. if (C.filterEnabled) {
  672. for (var B = 0; B < E.length; B++) {
  673. var D = E[B];
  674. if (lobbyMatchesFilter(D, C)) {
  675. A.push(D)
  676. }
  677. }
  678. } else {
  679. A = E
  680. }
  681. A = sortLobbiesByKey(A, C.sortField, C.sortAscending);
  682. return A
  683. }
  684.  
  685. function filterRegionLocked(A) {
  686. return A.filter(function(B) {
  687. return !B.regionLock || B.region == myRegion
  688. })
  689. }
  690.  
  691. function lobbyMatchesFilter1(B) {
  692. if ($.cookie("filter") == undefined) {
  693. return true
  694. }
  695. var A = JSON.parse($.cookie("filter"));
  696. if (A.filterEnabled) {
  697. return lobbyMatchesFilter(B, A)
  698. }
  699. return true
  700. }
  701.  
  702. function lobbyMatchesFilter(B, A) {
  703. if (A.mumbleRequired == true && !B.mumbleRequired == true) {
  704. return false
  705. }
  706. if (A.advancedOnly == true && !B.advanced == true) {
  707. return false
  708. }
  709. if (!arrayContainsGameType(A.gameTypes, B.gameType)) {
  710. return false
  711. }
  712. if (!arrayContainsRegion(A.locations, B.region)) {
  713. return false
  714. }
  715. if (!arrayContainsMapType(A.mapTypes, B.map)) {
  716. return false
  717. }
  718. return true
  719. }
  720.  
  721. function arrayContainsGameType(C, A) {
  722. if (C.length == 0) {
  723. return true
  724. }
  725. switch (A) {
  726. case "Highlander":
  727. A = "HIGHLANDER";
  728. break;
  729. case "6v6":
  730. A = "_6VS6";
  731. break;
  732. case "4v4":
  733. A = "_4VS4";
  734. break;
  735. case "Ultiduo":
  736. A = "ULTIDUO";
  737. break;
  738. case "BBall":
  739. A = "BBALL";
  740. break;
  741. case "Test 1v1":
  742. A = "TEST2";
  743. break
  744. }
  745. for (var B = 0; B < C.length; B++) {
  746. if (A == C[B]) {
  747. return true
  748. }
  749. }
  750. return false
  751. }
  752.  
  753. function arrayContainsRegion(C, D) {
  754. if (C.length == 0) {
  755. return true
  756. }
  757. var A;
  758. switch (D) {
  759. case "EU":
  760. A = "EUROPE";
  761. break;
  762. case "NA":
  763. A = "NORTH_AMERICA";
  764. break;
  765. case "SA":
  766. A = "SOUTH_AMERICA";
  767. break;
  768. case "RU":
  769. A = "RUSSIA";
  770. break;
  771. case "AS":
  772. A = "ASIA";
  773. break;
  774. case "AF":
  775. A = "AFRICA";
  776. break;
  777. case "AU":
  778. A = "OCEANIA";
  779. break
  780. }
  781. for (var B = 0; B < C.length; B++) {
  782. if (A == C[B]) {
  783. return true
  784. }
  785. }
  786. return false
  787. }
  788.  
  789. function arrayContainsMapType(B, C) {
  790. if (B.length == 0) {
  791. return true
  792. }
  793. var E = C.split("_")[0];
  794. var D;
  795. switch (E) {
  796. case "cp":
  797. D = "CONTROL_POINT";
  798. break;
  799. case "pl":
  800. D = "PAYLOAD";
  801. break;
  802. case "koth":
  803. D = "KOTH";
  804. break;
  805. case "ctf":
  806. D = "CTF";
  807. break;
  808. case "sd":
  809. D = "SPECIAL_DELIVERY";
  810. break;
  811. case "mvm":
  812. D = "MVM";
  813. break
  814. }
  815. for (var A = 0; A < B.length; A++) {
  816. if (D == B[A]) {
  817. return true
  818. }
  819. }
  820. return false
  821. }
  822.  
  823. function sortLobbiesByKey(A, C, D) {
  824. var E;
  825. switch (C) {
  826. case "map.name":
  827. E = "map";
  828. break;
  829. case "restriction":
  830. E = "restrictionsText";
  831. break;
  832. case "location":
  833. E = "region";
  834. break;
  835. case "gameType":
  836. E = "gameType";
  837. break;
  838. default:
  839. E = "no"
  840. }
  841. var B = A.sort(function(H, G) {
  842. if (H.advanced && !G.advanced) {
  843. return -1
  844. }
  845. if (!H.advanced && G.advanced) {
  846. return 1
  847. }
  848. var F = sort(H, G, E);
  849. return D ? F : 1 - F
  850. });
  851. return B
  852. }
  853.  
  854. function sort(C, B, D) {
  855. var A = C[D];
  856. var E = B[D];
  857. if (A == E) {
  858. return C.no < B.no ? -1 : 1
  859. }
  860. return ((A < E) ? -1 : 1)
  861. }
  862. $(document).ready(function() {
  863. $(document).bind("tf2center.overview.refresh-substitutes", function(E, D) {
  864. $("#substituteRequests").children().remove();
  865. if (myLobbiesPlayed < 20) {
  866. return
  867. }
  868. var C = 0;
  869. for (var B = 0; B < D.data.length && C < maxSubsToDisplay; B++) {
  870. var A = createSubstituteRequest(D.data[B]);
  871. if (typeof A !== undefined) {
  872. $("#substituteRequests").append(A);
  873. C++
  874. }
  875. }
  876. })
  877. });
  878.  
  879. function createSubstituteRequest(B) {
  880. if (!($.isEmptyObject(B.restrictions)) && !(userCanOverrideRestrictedSlots(B.leaderSteamId)) && !(meetsRestrictions(B.restrictions))) {
  881. return
  882. }
  883. if (!substituteRequestMatchesFilter(B)) {
  884. return
  885. }
  886. var D = $(".substituteRequest.templateHolder div.lobbySubPanel").clone();
  887. var C = generateRequestId(B);
  888. D.attr("id", C);
  889. D.find("a.joinLink").attr("href", B.joinLink);
  890. D.find("a.joinLink").attr("onClick", 'if (!confirm("' + getConfirmText(B) + '"))return false;');
  891. D.find(".icons.flags").addClass(B.region.toLowerCase());
  892. D.find(".lobbySubClass").addClass(B.team);
  893. D.find(".subName .icons.classes").addClass(getCssClassForTf2Class(B.tf2Class));
  894. D.find(".subName .displayName").text(B.className);
  895. D.find(".mapName").text(B.map);
  896. D.find(".gameType").text(B.gameType);
  897. D.addClass(B.advanced ? "advanced" : "manual");
  898. if (B.mumbleRequired == false) {
  899. D.find(".mumbleReq").addClass("hidden")
  900. }
  901. if ($.isEmptyObject(B.restrictions)) {
  902. D.find(".requirements").text("None")
  903. } else {
  904. var A = createStatsPanel(B.restrictions, B.leaderSteamId);
  905. D.find(".requirements").html(A)
  906. }
  907. var notification = new Notification(B.map,{
  908. tag: C,
  909. icon:"", //TODO: Think of way to use icons since we aren't given information, maybe a switch statement ick
  910. body:"Team: " + B.team.charAt(0).toUpperCase() + B.team.substring(1) + "\r\nClass: " + B.className + "\r\nGame Type: " + B.gameType + "\r\nCountry: " + B.region
  911. });
  912. notification.onclick = function() {
  913. window.open(B.joinLink, '_blank');
  914. };
  915. notification.onshow = function () { setTimeout(notification.close.bind(notification), 5000); };
  916. return D
  917. }
  918.  
  919. function getConfirmText(A) {
  920. return "Are you sure you wish to take this sub as " + A.region + " " + A.team.toUpperCase() + " " + A.tf2Class.toUpperCase() + "?"
  921. }
  922.  
  923. function generateRequestId(A) {
  924. return "subRequest-" + A.lobbyNo + "-" + A.slotIndex
  925. }
  926.  
  927. function filterRegionLocked(A) {
  928. return A.filter(function(B) {
  929. return !B.regionLock || B.region == myRegion
  930. })
  931. }
  932.  
  933. function substituteRequestMatchesFilter(B, A) {
  934. if (B.regionLock && B.region != myRegion) {
  935. return false
  936. }
  937. if ($.cookie("filter") == undefined) {
  938. return true
  939. }
  940. var A = JSON.parse($.cookie("filter"));
  941. if (A.filterEnabled != true) {
  942. return true
  943. }
  944. if (A.mumbleRequired == true && !B.mumbleRequired == true) {
  945. return false
  946. }
  947. if (A.advancedOnly == true && !B.advanced == true) {
  948. return false
  949. }
  950. if (!arrayContainsGameType(A.gameTypes, B.gameType)) {
  951. return false
  952. }
  953. if (!arrayContainsRegion(A.locations, B.region)) {
  954. return false
  955. }
  956. if (!arrayContainsMapType(A.mapTypes, B.map)) {
  957. return false
  958. }
  959. return true
  960. }
  961.  
  962. function testSubstituteRequestPanel() {
  963. var A = {
  964. lobbyNo: "1234",
  965. leaderSteamId: "76561197985830365",
  966. joinLink: "/join/lobby/1234/red/scout",
  967. slotIndex: 5,
  968. region: "EU",
  969. mumbleRequired: false,
  970. map: "koth_lakeside_final",
  971. gameType: "Highlander",
  972. team: "red",
  973. tf2Class: "roamer",
  974. className: "Soldier",
  975. advanced: true,
  976. restrictions: {
  977. hours: 1500,
  978. reliability: 85
  979. }
  980. };
  981. console.log(A);
  982. $("#substituteRequests").append(createSubstituteRequest(A));
  983. A = {
  984. lobbyNo: "1235",
  985. leaderSteamId: "76561197985822365",
  986. joinLink: "/join/lobby/1234/red/scout",
  987. slotIndex: 5,
  988. region: "EU",
  989. mumbleRequired: false,
  990. map: "koth_pro_viaduct_rc4",
  991. gameType: "Highlander",
  992. team: "red",
  993. tf2Class: "demoman",
  994. className: "Demoman",
  995. advanced: false,
  996. restrictions: {}
  997. };
  998. $("#substituteRequests").append(createSubstituteRequest(A));
  999. A = {
  1000. lobbyNo: "1236",
  1001. leaderSteamId: "76561197985822365",
  1002. joinLink: "/join/lobby/1234/red/scout",
  1003. slotIndex: 5,
  1004. region: "NA",
  1005. regionLock: true,
  1006. mumbleRequired: false,
  1007. map: "pl_badwater",
  1008. gameType: "Highlander",
  1009. team: "blue",
  1010. tf2Class: "scout",
  1011. className: "Scout",
  1012. restrictions: {
  1013. hours: 750,
  1014. games: 150,
  1015. reliability: 85
  1016. }
  1017. };
  1018. $("#substituteRequests").append(createSubstituteRequest(A))
  1019. }
  1020.  
  1021. function createStatsPanel(E, D) {
  1022. var C = $(".restrictedSlotStats.templateHolder div.statsContainer").clone();
  1023. var G;
  1024. var A;
  1025. var B;
  1026. var F = canOverrideRestrictedSlots;
  1027. if (!F && typeof D !== "undefined") {
  1028. F = userCanOverrideRestrictedSlots(D)
  1029. }
  1030. if (F) {
  1031. G = "darkgrey";
  1032. A = "darkgrey";
  1033. B = "darkgrey"
  1034. } else {
  1035. if (meetsHoursRestriction(E.hours)) {
  1036. G = "green"
  1037. } else {
  1038. G = "red"
  1039. }
  1040. if (meetsMinimumLobbiesRestriction(E.games)) {
  1041. A = "green"
  1042. } else {
  1043. A = "red"
  1044. }
  1045. if (meetsReliabilityRestriction(E.reliability)) {
  1046. B = "green"
  1047. } else {
  1048. B = "red"
  1049. }
  1050. }
  1051. C.find(".hours.value").text(E.hours > 0 ? E.hours : 0);
  1052. C.find(".lobbies.value").text(E.games > 0 ? E.games : 0);
  1053. C.find(".reliability.value").text(E.reliability > 0 ? E.reliability : 0);
  1054. C.find(".hours").addClass(G);
  1055. C.find(".lobbies").addClass(A);
  1056. C.find(".reliability").addClass(B);
  1057. return C
  1058. }
  1059. var friendsOnline = new Array();
  1060. var diffSinceLastPlayersOnlineScrollGeneration = 0;
  1061. $(document).ready(function() {
  1062. setupPlayersOnlineScrollPane();
  1063. $(document).bind("tf2center.refresh-players-online", function(B, C) {
  1064. $(".playerScrollContainer .jspPane").children().remove();
  1065. for (var A = 0; A < C.data.length; A++) {
  1066. $(".playerScrollContainer .jspPane").append(createPlayerOnlineRow(C.data[A]))
  1067. }
  1068. playersOnlineCount = C.data.length;
  1069. sortPlayersOnline();
  1070. setupPlayersOnlineScrollPane();
  1071. setupFriendsOnlineCount(C.data)
  1072. });
  1073. $(document).bind("tf2center.player-login", function(C, B) {
  1074. for (var A = 0; A < B.data.length; A++) {
  1075. if (isSteamFriend(B.data[A].steamId)) {
  1076. incFriendsOnline(B.data[A].steamId)
  1077. }
  1078. addPlayerInLine(B.data[A]);
  1079. diffSinceLastPlayersOnlineScrollGeneration = diffSinceLastPlayersOnlineScrollGeneration + 1
  1080. }
  1081. if (Math.abs(diffSinceLastPlayersOnlineScrollGeneration) >= 5) {
  1082. setupPlayersOnlineScrollPane()
  1083. }
  1084. });
  1085. $(document).bind("tf2center.player-logout", function(B, C) {
  1086. for (var A = 0; A < C.data.length; A++) {
  1087. if (isSteamFriend(C.data[A])) {
  1088. decFriendsOnline(C.data[A])
  1089. }
  1090. removePlayerRow(C.data[A]);
  1091. diffSinceLastPlayersOnlineScrollGeneration = diffSinceLastPlayersOnlineScrollGeneration - 1
  1092. }
  1093. if (Math.abs(diffSinceLastPlayersOnlineScrollGeneration) >= 5) {
  1094. setupPlayersOnlineScrollPane()
  1095. }
  1096. });
  1097. $(".playerScrollContainer").removeClass("hidden")
  1098. });
  1099.  
  1100. function setupFriendsOnlineCount(C) {
  1101. for (var A = 0; A < C.length; A++) {
  1102. var B = C[A].steamId;
  1103. if (isSteamFriend(B)) {
  1104. incFriendsOnline(B)
  1105. }
  1106. }
  1107. showFriendsOnlineCounter()
  1108. }
  1109.  
  1110. function incFriendsOnline(A) {
  1111. if ($.inArray(A, friendsOnline) == -1) {
  1112. friendsOnline.push(A);
  1113. showFriendsOnlineCounter()
  1114. }
  1115. }
  1116.  
  1117. function decFriendsOnline(B) {
  1118. var A = friendsOnline.indexOf(B);
  1119. if (A > -1) {
  1120. friendsOnline.splice(A, 1);
  1121. showFriendsOnlineCounter()
  1122. }
  1123. }
  1124.  
  1125. function showFriendsOnlineCounter() {
  1126. $("#friendsOnline").text(friendsOnline.length)
  1127. }
  1128.  
  1129. function addPlayerInLine(D) {
  1130. if ($('.friend-row[steamid="' + D.steamId + '"]').length) {
  1131. return
  1132. }
  1133. var C = createPlayerOnlineRow(D);
  1134. var A = isSteamFriend(D.steamId);
  1135. var B = false;
  1136. $("#players-online .friend-row").each(function() {
  1137. var E = ($(this).attr("friend") == "true");
  1138. if (E && !A) {
  1139. return
  1140. }
  1141. if ((A && !E) || $(this).attr("steamname").localeCompare(D.playerName) === 1) {
  1142. C.insertBefore($(this));
  1143. B = true;
  1144. return false
  1145. }
  1146. });
  1147. if (!B) {
  1148. $(".playerScrollContainer .jspPane").append(C)
  1149. }
  1150. }
  1151.  
  1152. function createPlayerOnlineRow(B) {
  1153. var A = $(".singleSpectatorRow.templateHolder div.friend-row").clone();
  1154. if (isSteamFriend(B.steamId)) {
  1155. A.attr("friend", "true");
  1156. A.find(".friend-icon.icons.person").addClass("friend")
  1157. }
  1158. A.attr("steamname", B.playerName);
  1159. A.attr("steamId", B.steamId);
  1160. A.find(".name").text(B.playerName);
  1161. A.find("a.profileLink").attr("href", "/profile/" + B.steamId);
  1162. return A
  1163. }
  1164.  
  1165. function removePlayerRow(A) {
  1166. $('.friend-row[steamid="' + A + '"]').remove()
  1167. }
  1168.  
  1169. function setupPlayersOnlineScrollPane() {
  1170. if (!$(".playerScrollContainer.scrollable").length) {
  1171. return
  1172. }
  1173. var A = $(".playerScrollContainer.scrollable").jScrollPane().data("jsp");
  1174. if (A != null && A.getPercentScrolledY() == 1) {
  1175. A.scrollToPercentY(100)
  1176. } else {
  1177. $(".playerScrollContainer.scrollable").jScrollPane({
  1178. maintainPosition: true
  1179. })
  1180. }
  1181. diffSinceLastPlayersOnlineScrollGeneration = 0
  1182. }
  1183.  
  1184. function sortPlayersOnline() {
  1185. $(".playerScrollContainer .jspPane div.friend-row").sort(function(B, A) {
  1186. var D = $(B).attr("friend") == "true";
  1187. var C = $(A).attr("friend") == "true";
  1188. if (D !== C) {
  1189. return (D && !C) ? -1 : 1
  1190. }
  1191. return $(B).attr("steamname").localeCompare($(A).attr("steamname"))
  1192. }).appendTo(".playerScrollContainer .jspPane")
  1193. }
  1194. var slider;
  1195. var notifications;
  1196. var currentNotification;
  1197. $(document).ready(function() {
  1198. notifications = $.parseJSON(notificationsJsonStr);
  1199. var D = 0;
  1200. var C = false;
  1201. var B = false;
  1202. var E = true;
  1203. for (var A = 0; A < notifications.length; A++) {
  1204. $("#notificationSlider").append(createDOMNotification(notifications[A]));
  1205. if (isLoggedIn()) {
  1206. if (notifications[A].created > notificationLastRead) {
  1207. C = true;
  1208. if (notifications[A].level == "CRITICAL") {
  1209. B = true;
  1210. D = A
  1211. }
  1212. if (!B) {
  1213. D = A
  1214. }
  1215. }
  1216. }
  1217. }
  1218. $(document).bind("tf2center.global-notification-added", function(F, H) {
  1219. notifications.unshift(H.data);
  1220. $("#notificationSlider").prepend(createDOMNotification(H.data));
  1221. var G = slider.getCurrentSlide();
  1222. slider.reloadSlider();
  1223. if (H.data.level == "CRITICAL") {
  1224. playIncomingSoundHeavy();
  1225. slider.goToSlide(getFirstUnreadIndex());
  1226. openNotifications()
  1227. } else {
  1228. if ($(".notificationButton").is(".active")) {
  1229. calSetToday();
  1230. slider.goToSlide(G + 1);
  1231. $("#notificationSlider, .bx-wrapper").hide().show();
  1232. $("#notificationSlider .notificationBox").first().hide().prop("z-index", 0)
  1233. } else {
  1234. if (getUnreadCount() == 1) {
  1235. slider.goToSlide(0)
  1236. }
  1237. }
  1238. updateUnreadCounter(true)
  1239. }
  1240. });
  1241. if ($(".notificationButton.enabled").length) {
  1242. setInterval(function() {
  1243. if (!$(".notificationButton").is(".active")) {
  1244. if (getUnreadCount() > 0) {
  1245. $(".notificationButton .red").fadeTo(500, 0.1).fadeTo(900, 1)
  1246. }
  1247. }
  1248. }, 500 + 900)
  1249. }
  1250. if ($("#notificationSlider").length) {
  1251. slider = $("#notificationSlider").bxSlider({
  1252. startSlide: D,
  1253. slideWidth: 718,
  1254. minSlides: 1,
  1255. maxSlides: 1,
  1256. slideMargin: 14,
  1257. mode: "fade",
  1258. speed: 300,
  1259. pager: false,
  1260. infiniteLoop: true,
  1261. hideControlOnEnd: false,
  1262. onSliderLoad: function(F) {
  1263. if (E) {
  1264. E = false;
  1265. if (B && isLoggedIn()) {
  1266. showNotification(notifications[F])
  1267. }
  1268. }
  1269. },
  1270. onSlideNext: function(F) {
  1271. showNotification(getNotificationById(+(F.find(".id").text())))
  1272. },
  1273. onSlidePrev: function(F) {
  1274. showNotification(getNotificationById(+(F.find(".id").text())))
  1275. }
  1276. });
  1277. $(".notificationCalendar").pickmeup({
  1278. flat: true,
  1279. format: "Y-m-d",
  1280. render: function(G) {
  1281. var F = getCssClassForDate(G);
  1282. if (F != null) {
  1283. return {
  1284. class_name: F
  1285. }
  1286. }
  1287. return {
  1288. disabled: true
  1289. }
  1290. },
  1291. change: function(F) {
  1292. var G = getNotificationIndexByDate(new Date(F));
  1293. slider.goToSlide(G);
  1294. showNotification(notifications[G])
  1295. }
  1296. });
  1297. $(".notificationToday a").click(function() {
  1298. calSetToday()
  1299. });
  1300. $(".notificationButton.enabled").click(function() {
  1301. toggleNotifications()
  1302. });
  1303. $(".notificationClose").click(function() {
  1304. closeNotifications()
  1305. });
  1306. if (isLoggedIn()) {
  1307. if (C) {
  1308. updateUnreadCounter(true);
  1309. if (B) {
  1310. playIncomingSoundHeavy();
  1311. openNotifications()
  1312. }
  1313. } else {
  1314. clearUnreadCounter()
  1315. }
  1316. }
  1317. } else {
  1318. updateUnreadCounter(true)
  1319. }
  1320. if (!isLoggedIn()) {
  1321. notificationLastRead = new Date().getTime();
  1322. clearUnreadCounter()
  1323. }
  1324. });
  1325.  
  1326. function preview(D, C, B) {
  1327. playIncomingSoundHeavy = function() {};
  1328. var A = {
  1329. id: 1,
  1330. created: new Date().getTime(),
  1331. dateDay: "12",
  1332. dateMonth: "DEC",
  1333. level: D,
  1334. title: $("<div/>").text(C).html(),
  1335. message: $("<div/>").text(B).html(),
  1336. author: "TF2Center"
  1337. };
  1338. $(document).trigger("tf2center.global-notification-added", {
  1339. data: A
  1340. });
  1341. showNotification(A);
  1342. openNotifications()
  1343. }
  1344.  
  1345. function isLoggedIn() {
  1346. return mySteamId != ""
  1347. }
  1348.  
  1349. function showNotification(A) {
  1350. currentNotification = A;
  1351. updateNotificationLastRead(A);
  1352. applyHeader(A.level == "REGULAR");
  1353. calSetDate(A.created)
  1354. }
  1355.  
  1356. function createDOMNotification(B) {
  1357. var A = $("#notificationTemplate").clone();
  1358. A.find(".id").text(B.id);
  1359. A.find(".date").text(B.dateDay);
  1360. A.find(".month").text(B.dateMonth);
  1361. A.find("h1").html($("<span />").html(B.title).text());
  1362. A.find(".notificationText").html($("<span />").html(B.message).text());
  1363. A.addClass(B.level == "CRITICAL" ? "critical" : "regular");
  1364. A.removeAttr("style");
  1365. A.removeAttr("id");
  1366. return A
  1367. }
  1368.  
  1369. function applyHeader(C) {
  1370. var A = C ? "regular" : "critical";
  1371. var B = C ? "critical" : "regular";
  1372. $("#mainHeader").removeClass(B).addClass(A);
  1373. $("#mainHeader .backgroundMain").removeClass(B).addClass(A)
  1374. }
  1375.  
  1376. function showUnreadCounter(A) {
  1377. $(".notificationButton .icons").removeClass("grey").addClass("red").text(A)
  1378. }
  1379.  
  1380. function clearUnreadCounter() {
  1381. $(".notificationButton .icons").removeClass("red").addClass("grey").text("")
  1382. }
  1383.  
  1384. function calSetToday() {
  1385. calSetDate(new Date())
  1386. }
  1387.  
  1388. function calSetDate(A) {
  1389. $(".notificationCalendar").pickmeup("set_date", A)
  1390. }
  1391.  
  1392. function toggleNotifications() {
  1393. if ($(".notificationButton").toggleClass("active").is(".active")) {
  1394. openNotifications()
  1395. } else {
  1396. closeNotifications()
  1397. }
  1398. }
  1399.  
  1400. function openNotifications() {
  1401. $(".notificationButton").addClass("active");
  1402. $("#mainHeader .backgroundLeft").css("visibility", "hidden");
  1403. $(".lobbyVoteCreate, .mostVotedMaps, .speechBubbleText, .lobbyHeader, .userProfile, .editProfile, .userProfileAdminButtons").hide();
  1404. $(".notificationClose, #notificationSlider, .bx-wrapper, .notificationCalendar, .notificationToday").show();
  1405. showNotification(getCurrentNotification())
  1406. }
  1407.  
  1408. function getCurrentNotification() {
  1409. var A = $($("#notificationSlider .notificationBox").get(slider.getCurrentSlide()));
  1410. return getNotificationById(+(A.find(".id").text()))
  1411. }
  1412.  
  1413. function closeNotifications() {
  1414. $(".notificationButton").removeClass("active");
  1415. $("#mainHeader").removeClass("critical regular");
  1416. $("#mainHeader .backgroundMain").removeClass("critical regular");
  1417. $("#mainHeader .backgroundLeft").css("visibility", "visible");
  1418. $(".bx-wrapper, .notificationClose, .notificationCalendar, .notificationToday").hide();
  1419. $(".lobbyVoteCreate, .mostVotedMaps, .speechBubbleText, .lobbyHeader, .userProfile, .editProfile, .userProfileAdminButtons").show()
  1420. }
  1421.  
  1422. function updateNotificationLastRead(A) {
  1423. if (A != null) {
  1424. if (A.created > notificationLastRead) {
  1425. notificationLastRead = A.created;
  1426. $.get("/notifications/lastread/" + notificationLastRead)
  1427. }
  1428. updateUnreadCounter()
  1429. }
  1430. }
  1431.  
  1432. function updateUnreadCounter(A) {
  1433. var B = getUnreadCount();
  1434. if (B > 0) {
  1435. if (A) {
  1436. showUnreadCounter(B)
  1437. } else {
  1438. $("#notificationUnreadCounter").text(B)
  1439. }
  1440. } else {
  1441. clearUnreadCounter()
  1442. }
  1443. }
  1444.  
  1445. function getFirstUnreadIndex() {
  1446. for (var A = 0; A < notifications.length; A++) {
  1447. if (notifications[A].created > notificationLastRead) {
  1448. return A
  1449. }
  1450. }
  1451. return 0
  1452. }
  1453.  
  1454. function getUnreadCount() {
  1455. var B = 0;
  1456. for (var A = 0; A < notifications.length; A++) {
  1457. if (notifications[A].created > notificationLastRead) {
  1458. B++
  1459. }
  1460. }
  1461. return B
  1462. }
  1463.  
  1464. function getNotificationById(B) {
  1465. for (var A = 0; A < notifications.length; A++) {
  1466. if (notifications[A].id == B) {
  1467. return notifications[A]
  1468. }
  1469. }
  1470. return null
  1471. }
  1472.  
  1473. function getCssClassForDate(A) {
  1474. var B = getNotificationByDate(A);
  1475. var C = B != null && currentNotification && datesEqual(new Date(currentNotification.created), A) ? " active" : "";
  1476. return B != null ? B.level == "CRITICAL" ? "critical" + C : "regular" + C : null
  1477. }
  1478.  
  1479. function getNotificationByDate(A) {
  1480. for (var B = 0; B < notifications.length; B++) {
  1481. if (datesEqual(new Date(notifications[B].created), A)) {
  1482. return notifications[B]
  1483. }
  1484. }
  1485. return null
  1486. }
  1487.  
  1488. function getNotificationIndexByDate(A) {
  1489. for (var B = 0; B < notifications.length; B++) {
  1490. if (datesEqual(new Date(notifications[B].created), A)) {
  1491. return B
  1492. }
  1493. }
  1494. return 0
  1495. }
  1496.  
  1497. function datesEqual(B, A) {
  1498. B.setHours(0, 0, 0, 0);
  1499. A.setHours(0, 0, 0, 0);
  1500. return B.getTime() == A.getTime()
  1501. }
  1502. var ws;
  1503. var wsOpened = false;
  1504. var WS_CHECK_TIMEOUT_SEC = 7;
  1505. var WS_CHECK_JUST_STARTED_TIMEOUT_SEC = 30;
  1506. $(document).ready(function() {
  1507. openWebSocket();
  1508. scheduleCheck()
  1509. });
  1510.  
  1511. function openWebSocket() {
  1512. console.info("Paymh custom script loaded - Opening web socket()");
  1513. try {
  1514. ws = new WebSocket(getWebsocketPath());
  1515. ws.onopen = function(event) {
  1516. console.debug("websocket successfully established")
  1517. };
  1518. ws.onclose = function(event) {
  1519. console.warn("websocket disconnected; reconnecting...");
  1520. setTimeout(function() {
  1521. window.location.reload()
  1522. }, 40000 + Math.floor(Math.random() * 30000))
  1523. };
  1524. ws.onmessage = function(event) {
  1525. wsOpened = true;
  1526. try {
  1527. if (event.data.indexOf('<?xml version="1.0" encoding="UTF-8"?>') === 0) {
  1528. Wicket.Ajax.process(event.data)
  1529. } else {
  1530. eval(event.data)
  1531. }
  1532. } catch (e) {
  1533. console.error("failed to process data: " + e)
  1534. }
  1535. };
  1536. ws.onerror = function(event) {
  1537. console.error("ws.onerror(): " + event)
  1538. }
  1539. } catch (e) {
  1540. console.error(e)
  1541. }
  1542. }
  1543.  
  1544. function scheduleCheck() {
  1545. setTimeout(function() {
  1546. var A = window.location;
  1547. if (!wsOpened && A.pathname.indexOf("/lobbies") == 0) {
  1548. if (A.host == "tf2center.com" && A.protocol === "http:") {
  1549. window.location = "https://" + A.host + A.pathname
  1550. } else {
  1551. console.warn("failed to open websocket; reloading page...");
  1552. window.location.reload()
  1553. }
  1554. }
  1555. }, (hasJustStarted ? WS_CHECK_JUST_STARTED_TIMEOUT_SEC : WS_CHECK_TIMEOUT_SEC) * 1000)
  1556. }
  1557.  
  1558. function getWebsocketPath() {
  1559. var B = window.location,
  1560. A;
  1561. if (B.protocol === "https:") {
  1562. A = "wss:"
  1563. } else {
  1564. A = "ws:"
  1565. }
  1566. A += "//" + B.host;
  1567. A += "/ws" + B.pathname;
  1568. return A
  1569. };
Add Comment
Please, Sign In to add comment