Tidy up your Dashboard

Customizable Userscript which tidies up your Dashboard!

当前为 2015-12-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Tidy up your Dashboard
  3. // @namespace https://gf.qytechs.cn/users/10154
  4. // @grant none
  5. // @match https://www.warlight.net/*
  6. // @description Customizable Userscript which tidies up your Dashboard!
  7. // @version 1.9.11.5
  8. // @icon http://i.imgur.com/XzA5qMO.png
  9. /// @require http://code.jquery.com/jquery-1.11.3.min.js
  10. /// @require https://gf.qytechs.cn/scripts/14620-randomized-bonus/code/Randomized%20Bonus.user.js
  11. /// @require https://gf.qytechs.cn/scripts/8981-spammers-be-gone/code/Spammers%20be%20gone!.user.js
  12.  
  13. // ==/UserScript==
  14. //this.$ = this.jQuery = jQuery.noConflict(true);
  15.  
  16. var version = "1.9.11.5";
  17.  
  18. function checkVersion() {
  19. var currentVersion = localStorage.getItem('version');
  20.  
  21. if (currentVersion == version) {
  22. //Script Up to date
  23.  
  24. } else if (currentVersion == undefined) {
  25. //Script new installed
  26. $(".userscript-show").fadeIn();
  27. $(".overlay").fadeIn();
  28. if (!localStorage.getItem("bookmarks")) {
  29. addDefaultBookmark();
  30. }
  31. } else {
  32. //Script Updated
  33. //$("label[for='showPrivateNotesOnProfile']").addClass('newSetting');
  34. //$(".userscript-show").fadeIn();
  35. //$(".overlay").fadeIn();
  36.  
  37. }
  38.  
  39. localStorage.setItem('version', version);
  40. }
  41.  
  42.  
  43. var lastRefresh;
  44. var myGamesTable = $("#MyGamesTable");
  45. var openGamesTable = $("#OpenGamesTable");
  46. var promotedGamesTable = $("#PromotedGamesTable");
  47. var lastClick = new Date();
  48.  
  49. var openGamesFilters;
  50. var bookmarks;
  51.  
  52. var userscriptSettings = [
  53. {
  54. id: 'scrollGames',
  55. text: 'Fixed Window with scrollable Games',
  56. selected: false,
  57. title: 'Dashboard',
  58. addBreak: false,
  59. help: 'This Option displays My-, Open-, Coin-Games in a scrollable box, which removes lots of unesessary scrolling. You can find tabs to switch between the different type of games. '
  60. },
  61. {
  62. id: 'hideMyGamesIcons',
  63. text: 'Hide Icons in "My Games"',
  64. selected: false,
  65. title: '',
  66. addBreak: false,
  67. help: 'This Option hides Game-Icons like ( <img src="https://d2wcw7vp66n8b3.cloudfront.net/Images/GameInfoIcons/Teams.png">,<img src="https://d2wcw7vp66n8b3.cloudfront.net/Images/GameInfoIcons/ManualDistribution.png"> , etc) in "My Games"'
  68. },
  69. {
  70. id: 'autoRefreshOnFocus',
  71. text: 'Automatically refresh Games on Tab-Focus',
  72. selected: false,
  73. title: '',
  74. addBreak: false,
  75. help: 'This Option automatically refreshes your Games after switching back to Warlight from a different tab / program. This only applies if Warlight was idle for 30 or more seconds.'
  76. },
  77. {
  78. id: 'highlightTournaments',
  79. text: 'Highlight Tournament invites',
  80. selected: false,
  81. title: '',
  82. addBreak: false,
  83. },
  84. {
  85. id: 'highlightNewForumPosts',
  86. text: 'Highlight new Clan Posts',
  87. selected: false,
  88. title: '',
  89. addBreak: false,
  90. help: 'This Option highlights Forum Posts in the Clan Forum Posts section which you haven\'t read yet.'
  91. },
  92. {
  93. id: 'hideRightColumn',
  94. text: 'Hide Right Column',
  95. selected: false,
  96. title: '',
  97. addBreak: false,
  98. help: 'This Option hides the right column completely and leaves you alone with My-, Open- and Coin-Games.'
  99. },
  100. {
  101. id: 'hidePromotedGames',
  102. text: 'Hide Promoted Games',
  103. selected: false,
  104. title: '',
  105. addBreak: false,
  106. help: 'This Option hides the Promoted Games on the Dashboard'
  107. },
  108. {
  109. id: 'useDefaultBootLabel',
  110. text: 'Use the Default Boot Time Label',
  111. selected: false,
  112. title: '',
  113. addBreak: false
  114. },
  115. {
  116. id: 'showOpenGamesTab',
  117. text: 'Show Open Games Tab in Menu Bar',
  118. selected: false,
  119. title: 'Global',
  120. addBreak: false,
  121. help: 'This Option displays a link to the "Open Games" site right next to the "Past Games" Link.'
  122. },
  123. {
  124. id: 'hideCoinsGlobally',
  125. text: 'Hide Coins Globally',
  126. selected: false,
  127. title: '',
  128. addBreak: false,
  129. help: 'This Option removes everything from Warlight related to Coins'
  130. },
  131. {
  132. id: 'showPrivateNotesOnProfile',
  133. text: 'Show Private Notes on Profile',
  134. selected: false,
  135. title: '',
  136. addBreak: false,
  137. help: 'This Option will show you your Private Notes which you made on a player directly on their Profile page. You can find them on the left side under the profile picture.'
  138. },
  139. {
  140. id: 'unlinkDashboard',
  141. text: 'Link Dashboard to "old" My-Games Site',
  142. selected: false,
  143. title: '',
  144. addBreak: false,
  145. help: 'This Option links the Dashboard to the "old" My-Games Site'
  146. },
  147. {
  148. id: 'disableSnow',
  149. text: 'Disable Snow',
  150. selected: false,
  151. title: 'Special',
  152. addBreak: false,
  153. help: 'Turns off the snow animation on all sites'
  154. },
  155. {
  156. id: 'snowLight',
  157. text: 'Reduce the number of Snowflakes',
  158. selected: false,
  159. title: '',
  160. addBreak: false,
  161. help: 'Reduce the number of Snowflakes for a better performance'
  162. }
  163. ];
  164.  
  165. var filters = [
  166. {
  167. id: "disableAll",
  168. text: "Disable All Filters",
  169. selected: false,
  170. type: "checkbox"
  171. },
  172. {
  173. id: "",
  174. text: "<div style='display:inline-block;height:30px; width: 10px'> </div>",
  175. selected: false,
  176. type: "custom"
  177. },
  178. {
  179. id: "hideTeam",
  180. text: "Hide Team Games",
  181. selected: false,
  182. type: "checkbox"
  183. }, {
  184. id: "hideManualDistribution",
  185. text: "Hide Manual Distribution Games",
  186. selected: false,
  187. type: "checkbox"
  188. },
  189. {
  190. id: "hideFFA",
  191. text: "Hide FFA Games",
  192. selected: false,
  193. type: "checkbox"
  194. },
  195. {
  196. id: "hideAutoDistribution",
  197. text: "Hide Auto Distribution Games",
  198. selected: false,
  199. type: "checkbox"
  200. },
  201. {
  202. id: "hide1v1",
  203. text: "Hide 1 v 1 Games",
  204. selected: false,
  205. type: "checkbox"
  206. },
  207. {
  208. id: "hideCustomScenario",
  209. text: "Hide Custom Scenario Games",
  210. selected: false,
  211. type: "checkbox"
  212. },
  213. {
  214. id: "hideNoSplit",
  215. text: "Hide No-Split Games",
  216. selected: false,
  217. type: "checkbox"
  218. },
  219. {
  220. id: "hideNonCustomScenario",
  221. text: "Hide Non-Custom Scenario Games",
  222. selected: false,
  223. type: "checkbox"
  224. },
  225. {
  226. id: "hideLocalDeployments",
  227. text: "Hide Local Deployment Games",
  228. selected: false,
  229. type: "checkbox"
  230. },
  231. {
  232. id: "hidePractice",
  233. text: "Hide Practice Games",
  234. selected: false,
  235. type: "checkbox"
  236. },
  237. {
  238. id: "hideLuck",
  239. text: "<label for='hideLuck' style='width:169px'>Hide Luck greater than</label><input type='text' id='hideLuck' class='number'>",
  240. selected: false,
  241. type: "custom"
  242. },
  243. {
  244. id: "hideNonPractice",
  245. text: "Hide Non-Practice Games",
  246. selected: false,
  247. type: "checkbox"
  248. },
  249. {
  250. id: "limitPlayers",
  251. text: '<label>Limit Amount of Players</label><br><div class="filter-small"><label for="hideMinPlayers" style="width:25px">Min </label><input class="number" type="text" id="hideMinPlayers">Players<br><label for="hideMaxPlayers" style="width:25px">Max </label><input class="number" type="text" id="hideMaxPlayers">Players</div>',
  252. selected: false,
  253. type: "custom"
  254. },
  255. {
  256. id: "hideBootTime",
  257. text: '<label>Hide Boot Time lower than</label><br><div class="filter-small"><label for="hideRealTimeBootTime" style="width:100px">Realtime: </label><input class="number" type="text" id="hideRealTimeBootTime">minute(s)<br><label for="hideMinPlayers" style="width:100px">Multiday: </label><input class="number" type="text" id="hideMultiDayBootTimeDays"> day(s) and <input class="number" type="text" id="hideMultiDayBootTimeHours"> hour(s)</div>',
  258. selected: false,
  259. type: "custom"
  260. },
  261. {
  262. id: "hideKeyword",
  263. text: '<label for="hideKeyword" style="width:115px">Hide Keywords<img src="https://i.imgur.com/TUyoZOP.png" class="help-icon" onclick="showFilterHelp(\'You can separate multiple Keywords with a comma. Each keyword must have 3 or more letters. The Keyword-Filter searches for case insensitive matches in the complete game title.<br>Example: The keyword ´Rop´ removes the game ´Europe 3v3´\', this)"></label><br><input type="text" id="hideKeyword" style="width: 95%;margin-left: 6px;"><hr>',
  264. selected: false,
  265. type: "custom",
  266. }
  267.  
  268. ];
  269.  
  270. var showGamesActive = "ShowMyGames";
  271.  
  272.  
  273. var openGames = [];
  274. readLocalstorage();
  275. setGlobalStyles();
  276. setupUserscriptMenu();
  277. setupBookmarkMenu();
  278. checkVersion();
  279. setupExternalJS();
  280.  
  281. $.fn.settingIsEnabled = function (setting) {
  282. var selected = false;
  283. $.each(userscriptSettings, function (key, set) {
  284. if (set.id == setting) {
  285. selected = set.selected;
  286. }
  287. });
  288. return selected;
  289. };
  290.  
  291. if (isEnabled('unlinkDashboard')) {
  292. $("#MultiPlayerBtn").attr('href', 'https://www.warlight.net/MultiPlayer?MyGames=1');
  293. $("#SubTabRow td > a[href='/MultiPlayer/'").attr('href', 'https://www.warlight.net/MultiPlayer?MyGames=1');
  294.  
  295. }
  296.  
  297. if (pageIsForumThread() || pageIsClanForumThread()) {
  298. //Show Open Games Link
  299. $("[href='#Reply']").after(" | <a style='cursor:pointer' onclick='bookmarkForumThread()'>Bookmark</a>")
  300. $("#PostReply").after(" | <a style='cursor:pointer' onclick='bookmarkForumThread()'>Bookmark</a>")
  301. }
  302.  
  303. if (pageIsTournament()) {
  304. $(document).ready(function () {
  305. setupTournamentFindMe()
  306. });
  307. $("#HostLabel").after(" | <a style='cursor:pointer' onclick='bookmarkTournament()'>Bookmark</a>");
  308. $("#HostLabel").css("display", "inline-block")
  309. $("#LeftToStartMessage").text(" | " + $("#LeftToStartMessage").text())
  310. createSelector("#LeftToStartMessage:before", "content: ' | '")
  311. }
  312.  
  313. if (pageIsMultiplayer()) {
  314. //Show Open Games Link
  315. if (isEnabled('showOpenGamesTab')) {
  316. showOpenGamesLink();
  317. }
  318. }
  319.  
  320. if(pageIsLadderOverview()) {
  321. setupLadderClotOverview()
  322. }
  323.  
  324.  
  325. if (pageIsDashboard()) {
  326. window.StringTools.htmlEscape = function (a) {
  327. if (a.indexOf("##joined##") >= 0) {
  328. a = a.replace("##joined##", "");
  329. return htmlEscape(a) + '<img style="display:inline-block;height:16px;width:16px;margin-left:10px;z-index:10;cursor:default" src="https://i.imgur.com/6akgXa7.png" title="You already joined this game">';
  330. } else {
  331. return htmlEscape(a);
  332. }
  333.  
  334. }
  335. hideBlacklistedThreads();
  336. setupBasicDashboardStyles();
  337. refreshOpenGames();
  338.  
  339. setupOpenGamesFilter();
  340.  
  341.  
  342. if (isEnabled('hideCoinsGlobally')) {
  343. hideCoinsGlobally()
  344. }
  345.  
  346. if (isEnabled('highlightTournaments')) {
  347. createSelector("#MyTournamentsTable tbody", "background:#4C4C33;");
  348. }
  349.  
  350. if (isEnabled('hidePromotedGames') || isEnabled('hideCoinsGlobally')) {
  351. createSelector("#PromotedGamesTable", "display:none");
  352. }
  353.  
  354. if (isEnabled('hideMyGamesIcons')) {
  355. createSelector("#MyGamesTable td div img, #MyGamesTable td div a img", "display:none;");
  356. }
  357.  
  358. if (isEnabled('highlightNewForumPosts')) {
  359. hightlightNewClanForumPosts();
  360. }
  361.  
  362. if (isEnabled('scrollGames')) {
  363. setupFixedWindowWithScrollableGames();
  364. }
  365. setupRightColumn(true);
  366.  
  367. if (isEnabled('hideRightColumn')) {
  368. hideRightColumn();
  369. }
  370.  
  371. $("label[for='MultiDayRadio']").on("click", function () {
  372. registerGameTabClick()
  373.  
  374. });
  375.  
  376. $("label[for='RealTimeRadio']").on("click", function () {
  377. registerGameTabClick()
  378. });
  379.  
  380. $("label[for='BothRadio']").on("click", function () {
  381. registerGameTabClick()
  382. });
  383.  
  384. $(window).resize(function () {
  385. if (isEnabled('scrollGames')) {
  386. refreshSingleColumnSize();
  387. }
  388. });
  389.  
  390. checkBookmarkTable();
  391. setupRefreshFunction();
  392.  
  393. } else {
  394. if (isEnabled('hideCoinsGlobally')) {
  395. hideCoinsGlobally()
  396. }
  397. }
  398.  
  399. if (pageIsClanThread()) {
  400. registerClanThread();
  401. }
  402.  
  403. if (pageIsProfile() && isEnabled('showPrivateNotesOnProfile') && $("#BlackListImage").length > 0) {
  404. loadPrivateNotes();
  405. }
  406.  
  407.  
  408. function hideCoinsGlobally() {
  409. $("#CoinsBtn").parent().next().css('left', 512);
  410. $("#CoinsBtn").parent().next().next().css('left', 635);
  411. $("#CoinsBtn").parent().next().next().next().css('left', 740);
  412.  
  413. $("#LeaderboardTable").prev().remove();
  414. $("#LeaderboardTable").css({
  415. opacity: 0,
  416. cursor: 'default'
  417. });
  418. $("#LeaderboardTable a").css('display', 'none');
  419. $(".TopRightBar").find("a[href='/Coins/']").css('display', 'none');
  420. $(".dropdown-menu a[href='/Coins/']").parent().remove()
  421.  
  422. $("a[href='/Win-Money']").css('display', 'none');
  423.  
  424. $("#OpenTournamentsTable").css('display', 'none');
  425. }
  426.  
  427. /**
  428. * Reads the User-Settings from Localstorage
  429. */
  430. function readLocalstorage() {
  431.  
  432. //Settings
  433.  
  434. $.each(userscriptSettings, function (key, setting) {
  435. setting.selected = localStorage.getItem(setting.id) == "true";
  436. });
  437.  
  438. //Filters
  439. var filters = localStorage.getItem("openGamesFilters");
  440.  
  441. if (filters) {
  442. openGamesFilters = $.parseJSON(filters);
  443. } else {
  444. openGamesFilters = {};
  445. }
  446.  
  447. var bm = localStorage.getItem("bookmarks");
  448.  
  449. if (bm) {
  450. bookmarks = $.parseJSON(bm);
  451. } else {
  452. bookmarks = [];
  453. }
  454.  
  455. hideCoinSymbol = true;
  456. }
  457.  
  458. /**
  459. * Creates the Userscript-Menu
  460. */
  461. function setupUserscriptMenu() {
  462.  
  463. var inputs = '';
  464.  
  465. $.each(userscriptSettings, function (key, setting) {
  466. if (setting.title != '') {
  467. inputs += '<span class="title">' + setting.title + '</span><br>';
  468. }
  469. var help = setting.help != undefined ? '<img src="https://i.imgur.com/TUyoZOP.png" class="help-icon" onclick=\'showSettingHelp("' + setting.id + '", this)\'>' : ''
  470. inputs += '<label for="_' + setting.id + '">' + setting.text + help + '</label>' + '<input type="checkbox" id="' + setting.id + '"><br>';
  471. if (setting.addBreak) {
  472. inputs += '<hr>';
  473. }
  474. });
  475.  
  476. inputs += '<div class="close-userscript">Close and Refresh</div>';
  477. $("body").append('<ul class="custom-menu"><div class="content"></div></ul>');
  478. $("body").append("<div class='overlay' style='display: none'></div><div class='popup popup600 userscript-show' style='display: none'><div class='head'>Change Userscript Settings<img class='close-popup-img' src='https://i.imgur.com/RItbpDS.png' height='25' width='25'></div>" + inputs + "</div>");
  479. $(".userscript-show").on("change", function () {
  480. storeSettingsVariables();
  481. });
  482. $("#TopRightDropDown .dropdown-divider").before('<li><div class="userscript-menu">Userscript</div></li>');
  483.  
  484. $(".userscript-menu").on("click", function () {
  485. $(".userscript-show").fadeIn();
  486. $(".overlay").fadeIn();
  487. $("#TopRightDropDown").fadeOut();
  488. $("embed#main").attr('wmode', 'transparent');
  489. $("embed#main").css('opacity', '0');
  490. $("embed#main").attr('align', 'left');
  491.  
  492. });
  493.  
  494. $(".close-userscript").on("click", function () {
  495. $(".userscript-show").fadeOut();
  496. $(".overlay").fadeOut();
  497. location.reload();
  498. });
  499.  
  500. $(".close-popup-img").on("click", function () {
  501. $(".userscript-show").fadeOut();
  502. $(".overlay").fadeOut();
  503. $("embed#main").css('opacity', '1');
  504. });
  505. $("#hideRightColumn").after('<button id="sortTables">Sort Right Column Tables</button><br>')
  506. createSelector("#sortTables","margin-top: 5px")
  507. $("#sortTables").on("click", function() {
  508. showSortTables()
  509. })
  510. var tables = getSortTables()
  511. var tableCode = ''
  512. $.each(tables, function(key, table) {
  513. tableCode += '<div class="sortableLadder ' + (table.hidden ? 'tableSortHidden' : '') +'" data-name="' + table.name + '" data-tableId="' + table.id + '">' + table.name + '<div class="tableSortNavigation"><span class="tableSortUp">▲</span><span class="tableSortDown">▼</span><span class="tableSortHideShow">?</span></div></div>'
  514. })
  515. createSelector(".sortableLadder", "border: 1px gray solid;margin: 5px;padding: 5px;background-color:rgb(25, 25, 25);")
  516. createSelector(".tableSortNavigation", "display: inline-block;float: right;margin-top: -2px;")
  517. createSelector(".tableSortNavigation span", "padding: 3px 10px; cursor: pointer")
  518. createSelector(".tableSortNavigation span:hover", "color: #C0D0FF")
  519. createSelector(".sortTableHighlight", "background-color: rgb(60, 60, 60)")
  520. createSelector(".tableSortHidden", "opacity: 0.2;")
  521. $("body").append(' <div class="popup popup600" id="sortTablePopup" style="display:none;margin-top: 150px; width: 500px; margin-left: -282px;"><div class="head" style=" margin-top: 152px;width:560px;">Sort Tables<img class="close-popup-img" src="https://i.imgur.com/RItbpDS.png" height="25" width="25"></div>' + tableCode +' <div class="close-userscript" onclick="window.saveTableSort()">Save & Refresh</div></div>')
  522. $(".tableSortUp").on("click", function() {
  523. $(".sortTableHighlight").removeClass("sortTableHighlight")
  524. var table = $(this).closest(".sortableLadder")
  525. table.addClass("sortTableHighlight")
  526. var prev = table.prev()
  527. table = table.detach()
  528. prev.before(table)
  529. })
  530. $(".tableSortDown").on("click", function() {
  531. $(".sortTableHighlight").removeClass("sortTableHighlight")
  532. var table = $(this).closest(".sortableLadder")
  533. table.addClass("sortTableHighlight")
  534. var next = table.next()
  535. table = table.detach()
  536. next.after(table)
  537. })
  538. $(".tableSortHideShow").on("click", function() {
  539. $(".sortTableHighlight").removeClass("sortTableHighlight")
  540. var table = $(this).closest(".sortableLadder")
  541. table.addClass("sortTableHighlight")
  542. table.toggleClass("tableSortHidden")
  543. })
  544. checkUserscriptMenuButtons();
  545.  
  546. }
  547.  
  548. function getSortTables() {
  549. var defaultTables =
  550. [
  551. {id: "#BookmarkTable", name: "Bookmarks", hidden: false, order: 0},
  552. {id: "#ClotTable", name: "CLOTs", hidden: false, order: 1},
  553. {id: "#MyTournamentsTable", name: "Tournaments", hidden: false, order: 2},
  554. {id: "#RealTimeLadderTable", name: "Real-Time Ladder", hidden: false, order: 3},
  555. {id: "#MapOfTheWeekTable", name: "Map of the Week", hidden: false, order: 4},
  556. {id: "#ForumTable", name: "Forum Posts", hidden: false, order: 5},
  557. {id: "#ClanForumTable", name: "Clan Forum Posts", hidden: false, order: 6},
  558. {id: "#BlogTable", name: "Recent Blog Posts", hidden: false, order: 7},
  559. {id: "#LeaderboardTable", name: "Coin Leaderboard", hidden: false, order: 8}
  560. ]
  561. var tables;
  562. var tableData = localStorage.getItem("tableSort")
  563. try {
  564. tables = (tableData != undefined && isJson(tableData)) ? JSON.parse(tableData) : defaultTables
  565. }
  566. catch(e) {
  567. return $(defaultTables).sort(compareTable)
  568. }
  569. return $(tables).sort(compareTable);
  570. }
  571.  
  572. window.saveTableSort = function() {
  573. var tables = []
  574. $.each($("#sortTablePopup > div.sortableLadder"), function(key, table) {
  575. var order = key
  576. var id = $(table).attr('data-tableId')
  577. var hidden = $(table).hasClass("tableSortHidden")
  578. var name = $(table).attr('data-name')
  579. tables.push({id: id, name: name, hidden: hidden, order: order})
  580. })
  581. localStorage.setItem("tableSort", JSON.stringify(tables))
  582. $("#sortTablePopup").fadeOut();
  583. $(".overlay").fadeOut();
  584. window.location.reload()
  585. }
  586.  
  587. function showSortTables() {
  588. $(".popup").fadeOut();
  589. $("#sortTablePopup").fadeIn();
  590. $(".overlay").fadeIn();
  591. }
  592.  
  593. function compareTable(a,b) {
  594. if (a.order < b.order)
  595. return -1;
  596. if (a.order > b.order)
  597. return 1;
  598. return 0;
  599. }
  600.  
  601. function showInfo(text, x, y) {
  602. window.setTimeout(function () {
  603. if (!$(".custom-menu").is(':visible')) {
  604. $(".custom-menu .content").html(text);
  605. $(".custom-menu").finish().toggle(100).
  606.  
  607. // In the right position (the mouse)
  608. css({
  609. top: x + "px",
  610. left: y + "px"
  611. });
  612. }
  613.  
  614. }, 10);
  615. }
  616.  
  617. window.showSettingHelp = function (id, obj) {
  618. var help = '';
  619. $.each(userscriptSettings, function (key, setting) {
  620. if (setting.id == id) {
  621. help = setting.help;
  622. }
  623. });
  624. var x = $(obj).offset().top;
  625. var y = $(obj).offset().left;
  626. showInfo(help, x, y);
  627.  
  628.  
  629. }
  630.  
  631. function checkUserscriptMenuButtons() {
  632. $.each(userscriptSettings, function (key, setting) {
  633. $("#" + setting.id).prop("checked", setting.selected);
  634. });
  635. }
  636.  
  637. function StickyTitles(stickies) {
  638. var thisObj = this;
  639. thisObj.load = function () {
  640. stickies.each(function () {
  641. var thisSticky = $(this).wrap('<div class="followWrap" />');
  642. thisSticky.parent().height(thisSticky.outerHeight());
  643. var pos = parseInt(thisSticky.offset().top, 10) - parseInt($(".showSide").offset().top, 10);
  644. $.data(thisSticky[0], 'pos', pos);
  645. });
  646. $(".showSide").off("scroll.stickies").on("scroll.stickies", function () {
  647. thisObj.scroll();
  648. });
  649. };
  650.  
  651. thisObj.scroll = function () {
  652. stickies.each(function (i) {
  653. var thisSticky = $(this),
  654. nextSticky = stickies.eq(i + 1),
  655. prevSticky = stickies.eq(i - 1),
  656. pos = $.data(thisSticky[0], 'pos');
  657. var showSide = $(".showSide");
  658. if (pos <= showSide.scrollTop()) {
  659. thisSticky.addClass("fixed");
  660. if (nextSticky.length > 0 && thisSticky.offset().top >= $.data(nextSticky[0], 'pos') - thisSticky.outerHeight()) {
  661. thisSticky.addClass("absolute").css("top", jQuery.data(nextSticky[0], 'pos') - thisSticky.outerHeight());
  662. }
  663. } else {
  664. thisSticky.removeClass("fixed");
  665. if (prevSticky.length > 0 && showSide.scrollTop() <= $.data(thisSticky[0], 'pos') - prevSticky.outerHeight()) {
  666. prevSticky.removeClass("absolute").removeAttr("style");
  667. }
  668. }
  669. });
  670. }
  671. }
  672.  
  673. jQuery.fn.outerHTML = function (s) {
  674. return s ? this.before(s).remove() : jQuery("<p>").append(this.eq(0).clone()).html();
  675. };
  676.  
  677.  
  678. /**
  679. * Stores User-Settings to local Storage
  680. */
  681. function storeSettingsVariables() {
  682.  
  683. $.each(userscriptSettings, function (key, setting) {
  684. localStorage.setItem(setting.id, $("#" + setting.id).prop("checked"));
  685. });
  686.  
  687. }
  688.  
  689. /**
  690. * Refreshes Width & Height of Columns
  691. */
  692. function refreshSingleColumnSize() {
  693. var showSide = $(".showSide");
  694. var showGames = $(".showGames");
  695. showSide.scrollTop(0);
  696. /**
  697. * Sticky Titles
  698. */
  699. $(".followMeBar").each(function () {
  700. $(this).removeClass("fixed");
  701. if ($(this).parent().hasClass("followWrap")) {
  702. $(this).unwrap();
  703. }
  704. var thisSticky = $(this).wrap('<div class="followWrap" />');
  705. thisSticky.parent().height(thisSticky.outerHeight());
  706.  
  707. var pos = parseInt(thisSticky.offset().top) - parseInt(showSide.offset().top);
  708. $.data(thisSticky[0], 'pos', pos);
  709. });
  710. var width = $("#ForumTable").width();
  711. createSelector(".followMeBar", "width:" + width + "px;");
  712.  
  713. showGames.find("table").css({
  714. height: window.innerHeight - 150
  715. });
  716.  
  717. //var height = showGames.find("table thead tr").height() + 30;
  718. var height = 48;
  719. createSelector(".showGames table tbody tr:first-of-type td", "padding-top:" + height + "px");
  720.  
  721.  
  722. showSide.css({
  723. height: window.innerHeight - 150
  724. });
  725. showGames.find("table tbody tr:first-of-type td").css("padding-top", height);
  726.  
  727. $(".showGames thead tr td div").unwrap();
  728. checkBookmarkTable()
  729. }
  730.  
  731. /**
  732. * Create a CSS selector
  733. * @param name The name of the object, which the rules are applied to
  734. * @param rules The CSS rules
  735. */
  736. function createSelector(name, rules) {
  737. var style = document.createElement('style');
  738. style.type = 'text/css';
  739. document.getElementsByTagName('head')[0].appendChild(style);
  740. if (!(style.sheet || {}).insertRule) {
  741. (style.styleSheet || style.sheet).addRule(name, rules);
  742. } else {
  743. style.sheet.insertRule(name + "{" + rules + "}", 0);
  744. }
  745. }
  746.  
  747. /**
  748. * Reloads all Games
  749. */
  750. function refreshAllGames(force) {
  751. if ($(".popup").is(":visible") && !force) {
  752. return;
  753. }
  754. if (isEnabled('scrollGames')) {
  755. openGamesTable.scrollTop(0);
  756. myGamesTable.scrollTop(0);
  757. promotedGamesTable.scrollTop(0);
  758. }
  759.  
  760. $('table').css('overflow-y', 'hidden')
  761. refreshMyGames();
  762. refreshOpenGames();
  763. refreshPromotedGames();
  764. loadClots()
  765. }
  766.  
  767.  
  768. function refreshMyGames() {
  769. myGamesTable.find("tbody").fadeTo('fast', 0.15);
  770. var filter = $("#MyGamesFilter").val() || 4;
  771. wljs.Jsutil.Post("?", "FilterChange=" + 4, function (a) {
  772. myGames = wljs.Jsutil.GamesFromDump(a);
  773. d = $("#MyGamesTable").children("tbody");
  774. d.children().remove();
  775.  
  776. if (myGames.length == 0) {
  777. d.append('<tr><td colspan="2" style="color: #C1C1C1">' + warlight.shared.viewmodels.main.MultiPlayerDashboardVM.NoGamesHtml(0) + "</td></tr>");
  778. } else {
  779. for (var f = 0; f < myGames.length;) {
  780. var g = myGames[f];
  781. ++f;
  782. g = (new warlight.shared.viewmodels.main.MyGamesGameVM).Init(1, g, warlight.shared.viewmodels.SignIn.get_CurrentPlayer());
  783. d.append(warlight.shared.viewmodels.main.MultiPlayerDashboardVM.RenderGameHtml(g, null))
  784. }
  785. }
  786. myGamesTable.find("tbody").fadeTo('fast', 1, function () {
  787. myGamesTable.css('overflow-y', 'scroll');
  788. });
  789. $(window).trigger('resize');
  790. });
  791. }
  792.  
  793. function refreshOpenGames() {
  794. deletedMD = deletedRT = 0;
  795. openGamesTable.find("tbody").fadeTo('fast', 0.15);
  796. var page = $('<div />').load('https://www.warlight.net/MultiPlayer/ ', function () {
  797. var data = page.find('#AllOpenGamesData').html();
  798. $('#AllOpenGamesData').html(data);
  799.  
  800. if (openGamesFilters["disableAll"] != true) {
  801. var games = filterGames(wljs.Jsutil.GamesFromDump(data));
  802. } else {
  803. var games = wljs.Jsutil.GamesFromDump(data);
  804. }
  805. $.each(games, function (key, game) {
  806. if ($(game).playerJoined()) {
  807. games[key] = $(game).markJoined();
  808. }
  809. });
  810.  
  811. wljs.multiplayer.OpenGames();
  812. wljs.AllOpenGames = wljs.multiplayer.Ctrl.AllOpenGames = games;
  813. var RealTimeLadderTable = page.find("#RealTimeLadderTable tbody tr:first-of-type").outerHTML();
  814. $("#RealTimeLadderTable tbody tr:first-of-type")
  815. if(RealTimeLadderTable.length == 0) {
  816. $("#RealTimeLadderTable tbody tr:first-of-type").replaceWith("<tr><td>Nobody is playing in the real-time ladder. <a href='/LadderSeason?ID=3'>Join them!</a></td></tr>")
  817. } else {
  818. $("#RealTimeLadderTable tbody tr:first-of-type").replaceWith(RealTimeLadderTable)
  819. }
  820. $("#ForumTable").replaceWith(page.find("#ForumTable").outerHTML())
  821. $("#ClanForumTable").replaceWith(page.find("#ClanForumTable").outerHTML())
  822. setupRightColumn()
  823. updateOpenGamesCounter();
  824.  
  825. wljs.AllOpenGamesData = wljs.multiplayer.Ctrl.AllOpenGamesData = data;
  826. var player = warlight.shared.viewmodels.SignIn.get_CurrentPlayer();
  827. if ((new js.JQuery(this.BothRadio)).is(":checked")) {
  828. player.OpenGamePreference = 1;
  829. } else if ((new js.JQuery(this.MultiDayRadio)).is(":checked")) {
  830. player.OpenGamePreference = 2;
  831. } else if ((new js.JQuery(this.RealTimeRadio)).is(":checked")) {
  832. player.OpenGamePreference = 3;
  833. }
  834. wljs.Jsutil.Post("/MultiPlayer/", "ChangePace=" + player.OpenGamePreference, function (a) {});
  835.  
  836.  
  837. var a = $("#OpenGamesTable").children("tbody");
  838. a.children().remove();
  839. var gamesToShow = warlight.shared.viewmodels.main.MultiPlayerDashboardVM.GamesToShow(wljs.AllOpenGames, player.OpenGamePreference, 0 == this.ShowingAllOpenGames)
  840. for (var b = 0; b < gamesToShow.length;) {
  841. var game = gamesToShow[b];
  842. b++;
  843. game.get_IsLottery() && warlight.shared.viewmodels.main.MultiPlayerDashboardVM.get_HideLotteryGames() ||
  844. (game = (new warlight.shared.viewmodels.main.MyGamesGameVM).Init(2, game), a.append(warlight.shared.viewmodels.main.MultiPlayerDashboardVM.RenderGameHtml(game, null)))
  845. }
  846. openGamesTable.find("tbody").fadeTo('fast', 1, function () {
  847. openGamesTable.css('overflow-y', 'scroll');
  848. });
  849. addOpenGamesSuffix();
  850. domRefresh();
  851.  
  852. });
  853. }
  854.  
  855. function refreshPromotedGames() {
  856. promotedGamesTable.find("tbody").fadeTo('fast', 0.15);
  857. var page = $('<div />').load('https://www.warlight.net/MultiPlayer/ ', function () {
  858. var data = page.find('#MorePromotedGamesData').html();
  859. $('#MorePromotedGamesData').html(data);
  860. wljs.PromotedGames = wljs.Jsutil.GamesFromDump(data);
  861.  
  862. var a = $("#PromotedGamesTable").children("tbody");
  863. a.children().remove();
  864. for (var b = 0; b < wljs.PromotedGames.length;) {
  865. var game = wljs.PromotedGames[b];
  866. b++;
  867. (game = (new warlight.shared.viewmodels.main.MyGamesGameVM).Init(2, game), a.append(warlight.shared.viewmodels.main.MultiPlayerDashboardVM.RenderGameHtml(game, null)))
  868. }
  869. domRefresh();
  870. promotedGamesTable.find("tbody").fadeTo('fast', 1, function () {
  871. promotedGamesTable.css('overflow-y', 'scroll');
  872. });
  873.  
  874. });
  875. }
  876.  
  877.  
  878. /**
  879. * Setups the refresh functionality
  880. */
  881. function setupRefreshFunction() {
  882. lastRefresh = new Date();
  883. var oldRefreshBtn = $("#RefreshBtn");
  884. var oldRefreshBtn2 = $("#RefreshBtn2");
  885. if (oldRefreshBtn.length) {
  886. var newRefreshBtn = $("#refreshAll");
  887. oldRefreshBtn.replaceWith(oldRefreshBtn.clone().removeAttr("id").attr("id", "refreshAll").attr("value", "Refresh (R)"));
  888. newRefreshBtn.appendTo("body");
  889. $("#refreshAll").on("click", function () {
  890. if (new Date() - lastRefresh > 3000) {
  891. lastRefresh = new Date();
  892. refreshAllGames();
  893. }
  894. });
  895. } else if (oldRefreshBtn2.length) {
  896. var newRefreshBtn = $("#refreshAll");
  897. oldRefreshBtn2.replaceWith(oldRefreshBtn2.clone().removeAttr("id").attr("id", "refreshAll").attr("value", "Refresh (R)"));
  898. newRefreshBtn.appendTo("body");
  899. $("#refreshAll").on("click", function () {
  900. if (new Date() - lastRefresh > 3000) {
  901. lastRefresh = new Date();
  902. refreshAllGames();
  903. }
  904. });
  905. }
  906.  
  907. $(".MainColumn").prepend($('#refreshAll'))
  908.  
  909. if (isEnabled('autoRefreshOnFocus')) {
  910. $(window).on('focus', function () {
  911. if (new Date() - lastRefresh > 30000) {
  912. lastRefresh = new Date();
  913. refreshAllGames();
  914. }
  915. });
  916. }
  917.  
  918. $("body").keyup(function (event) {
  919. // "R" is pressed
  920. if (event.which == 82) {
  921. if (new Date() - lastRefresh > 3000) {
  922. lastRefresh = new Date();
  923. refreshAllGames();
  924. }
  925. }
  926. });
  927. }
  928.  
  929.  
  930. function getDate(text) {
  931. var date;
  932.  
  933. if (text.match(/[0-9]+ second/)) {
  934. date = new Date() - 1000;
  935.  
  936. } else if (text.match(/[0-9]+ seconds/)) {
  937. date = new Date() - text.match(/[0-9]+/) * 1000;
  938.  
  939. } else if (text.match(/[0-9]+ minute/)) {
  940. date = new Date() - text.match(/[0-9]+/) * 1000 * 60;
  941.  
  942. } else if (text.match(/[0-9]+ minutes/)) {
  943. date = new Date() - text.match(/[0-9]+/) * 1000 * 60;
  944.  
  945. } else if (text.match(/[0-9]+ hour/)) {
  946. date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 59;
  947.  
  948. } else if (text.match(/[0-9]+ hours/)) {
  949. date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 60;
  950.  
  951. } else if (text.match(/[0-9]+ day/)) {
  952. date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 60 * 36;
  953.  
  954. } else if (text.match(/[0-9]+ days/)) {
  955. date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 60 * 24;
  956.  
  957. } else if (text.match(/[0-9]+[\/][0-9]+[\/][0-9]+/)) {
  958. var split = text.split('/');
  959. date = new Date(split[2], split[0] - 1, split[1]);
  960. date.setHours(0, 0, 0, 0);
  961. }
  962. return date;
  963. }
  964.  
  965.  
  966. var searches = 0;
  967.  
  968. function filterMailTo() {
  969. if (searches == 0) {
  970. $($("#MainSiteContent div:nth-of-type(1)")[0]).children().remove()
  971. searches++;
  972. }
  973. var find = $("#search_input").val().toLowerCase()
  974. if (find.length > 1) {
  975. removeUncheckedMail()
  976. $.each(data_mail, function (index, val) {
  977. if ($(val).text().toLowerCase().indexOf(find) > -1) {
  978. var id = $(val).attr("id").replace("Lbl_", "")
  979. if ($("#Lbl_" + id).length == 0) {
  980. $($("#MainSiteContent div:nth-of-type(1)")[0]).append('<input type="checkbox" id="CB_' + id + '" onclick="PlayerClicked(' + id + ')">').append(val).append("<br>")
  981. }
  982.  
  983. }
  984. })
  985. } else {
  986. removeUncheckedMail()
  987. }
  988.  
  989. }
  990.  
  991. function hideBlacklistedThreads() {
  992. var ids = JSON.parse(localStorage.getItem("blackListedThreads"));
  993. $.each($("#ForumTable tr"), function (key, row) {
  994. var href = $(row).html().match(/href="\/([^"]*)"/m);
  995.  
  996. if (href) {
  997. href = "/" + href[1]
  998. if ($.inArray(href, ids) != -1) {
  999. $(row).remove()
  1000. }
  1001. }
  1002.  
  1003. })
  1004. }
  1005.  
  1006. function removeUncheckedMail() {
  1007. $.each($($("#MainSiteContent div:nth-of-type(1)")[0]).find("label"), function (index, val) {
  1008. var id = $(val).attr("id").replace("Lbl_", "")
  1009. if (!$('#CB_' + id).is(":checked")) {
  1010. $(val).next().remove()
  1011. $(val).prev().remove()
  1012. $(val).remove()
  1013. }
  1014. })
  1015. }
  1016. var data_mail = []
  1017. if (location.href.match(/.*warlight[.]net\/Discussion\/SendMail$/)) {
  1018. $($("#MainSiteContent div:nth-of-type(1)")[0]).before('<input id="search_input" placeholder="Filter" style="margin-bottom:10px">')
  1019. $("#search_input").on("input", function () {
  1020. filterMailTo()
  1021.  
  1022. })
  1023.  
  1024. $.each($($("#MainSiteContent div:nth-of-type(1)")[0]).find("label"), function (index, val) {
  1025. data_mail.push($(val))
  1026. });
  1027.  
  1028. }
  1029.  
  1030. if (!isEnabled('useDefaultBootLabel')) {
  1031. createSelector(".BootTimeLabel", "color:white !important;font-weight:normal!important;font-style:italic;font-size:13px!important;z-index:50;");
  1032. } else {
  1033. createSelector(".BootTimeLabel", "z-index:50;");
  1034. }
  1035.  
  1036. function setGlobalStyles() {
  1037. createSelector('.help-icon', 'display:inline-block;position:absolute; margin-left:10px;margin-top: 2px;cursor:pointer; height: 15px; width: 15px;')
  1038. var winHeight = $(window).height();
  1039. createSelector(".userscript-menu", "display: block;color: #555;text-decoration: none;line-height: 18px;padding: 3px 15px;margin: 0;white-space: nowrap;");
  1040. createSelector(".userscript-menu:hover", "cursor:pointer;background-color: #08C;color: #FFF;cursor: pointer;");
  1041. createSelector(".popup", "position: fixed;;left: 50%;background: #171717;top: 100px;z-index: 500001; color:white;padding:60px 30px 30px 30px;border: 2px solid gray;border-radius:8px;max-height:" + (winHeight - 200) + "px;overflow-y:auto");
  1042. createSelector(".close-userscript", "margin-top: 40px;width: 100%;text-align: center;font-size: 15px;cursor: pointer;background: gray;line-height: 30px;border-radius: 8px;clear: both");
  1043. createSelector(".close-popup-img", "float:right;margin:5px;cursor:pointer;margin-right: 20px");
  1044. createSelector(".popup label", "width: 80%;display: inline-block;font-size: 15px;margin: 5px;");
  1045. createSelector(".popup .title", "color: gray;font-size: 15px;margin-top: 10px;display: inline-block;width: 95%;border-bottom: 1px gray solid;padding-bottom: 3px;");
  1046. createSelector(".popup input[type='checkbox']", "width: 20px;height: 20px;margin-left:30px;margin: 5px;-moz-appearance:none;");
  1047. createSelector(".overlay", "position: absolute;background: white;top: 0;left: 0;right: 0;bottom: 0;z-index: 500000;opacity: 0.5;width: 100%;height: 100%;position: fixed;");
  1048. createSelector(".popup .head", "position: fixed;height: 40px;background: #330000;width: 660px;left: 0;right: 0;top: 100px;color: white;font-size: 15px;text-align: center;line-height: 40px;border-top-left-radius:8px;border-top-right-radius:8px;margin:auto;z-index:10000;");
  1049. createSelector(".userscript-show", "display:none");
  1050. createSelector("#MorePromotedGamesHorizontalRow", "display:none");
  1051. createSelector(".newSetting", "color: gold;font-weight: bold;");
  1052. createSelector(".userscript-menu img", "height: 18px;display: inline-block;position: relative;margin-bottom: -5px;margin-right: 7px;");
  1053. createSelector(".custom-menu", "display: none;z-index: 1000;position: absolute;overflow: hidden;border: 1px solid #CCC;white-space: nowrap;font-family: sans-serif;background: #FFF;color: #333;border-radius:5px;padding: 10px;z-index:100000000; cursor:pointer");
  1054. createSelector(".custom-menu .content", "width: 300px;white-space: pre-wrap;");
  1055. createSelector('.popup input[type="text"]', 'display: inline-block;background: none;border-top: none;border-left: none;border-right: none;color: green;font-size: 15px;border-bottom: 1px white dashed;font-family: Verdana;padding: 0 5px 0 5px;text-align: center;margin-right: 5px');
  1056.  
  1057. createSelector(".popup840", "width: 840px;margin-left: -452px");
  1058. createSelector(".popup600", "width: 600px;margin-left: -332px");
  1059.  
  1060. createSelector(".popup840 .head", "width: 900px");
  1061. createSelector(".popup600 .head", "width: 660px");
  1062. createSelector(".context-menu", "display: none;z-index: 1000;position: absolute;overflow: hidden;border: 1px solid #CCC;white-space: nowrap;font-family: sans-serif;background: #FFF;color: #333;border-radius: 5px;padding: 0;");
  1063. createSelector(".context-menu li", "padding: 8px 12px;cursor: pointer;list-style-type: none;");
  1064. createSelector(".context-menu li:hover", "background-color: #DEF;");
  1065.  
  1066.  
  1067. $("body").on("click", function (e) {
  1068. if ($(".custom-menu").is(':visible')) {
  1069. $(".custom-menu").hide(100);
  1070. }
  1071. });
  1072. }
  1073.  
  1074. var deletedRT = 0;
  1075. var deletedMD = 0;
  1076.  
  1077. function filterGames(games) {
  1078. var filteredGames = [];
  1079. var deletedGames = [];
  1080.  
  1081. $.each(games, function (key, game) {
  1082. if (!$(game).getsFiltered()) {
  1083. filteredGames.push(game);
  1084. } else {
  1085. if (game.RealTimeGame) {
  1086. deletedRT++;
  1087. } else {
  1088. deletedMD++;
  1089. }
  1090. }
  1091. });
  1092.  
  1093. return filteredGames;
  1094. }
  1095.  
  1096. (function ($) {
  1097. $.fn.getsFiltered = function () {
  1098. var game = this[0];
  1099.  
  1100. if (openGamesFilters["hideMaxPlayers"] <= 100 && $(game).numOfPlayers() > openGamesFilters["hideMaxPlayers"]) return true;
  1101. if (openGamesFilters["hideMinPlayers"] <= 100 && $(game).numOfPlayers() < openGamesFilters["hideMinPlayers"]) return true;
  1102. if (openGamesFilters["hideLuck"] < 100 && game.SettingsOpt.LuckModifier * 100 > openGamesFilters["hideLuck"]) return true;
  1103. if (openGamesFilters["hideFFA"] && $(game).numOfTeams() == 0 && $(game).numOfPlayers() > 2) return true;
  1104. if (openGamesFilters["hideTeam"] && $(game).numOfTeams() > 0) return true;
  1105. if (openGamesFilters["hide1v1"] && $(game).numOfPlayers() == 2) return true;
  1106. if (openGamesFilters["hideCustomScenario"] && game.SettingsOpt.DistributionMode === -3) return true;
  1107. if (openGamesFilters["hideNonCustomScenario"] && game.SettingsOpt.DistributionMode !== -3) return true;
  1108. if (openGamesFilters["hidePractice"] && !game.SettingsOpt.RankedGame) return true;
  1109. if (openGamesFilters["hideNoSplit"] && game.SettingsOpt.NoSplit) return true;
  1110. if (openGamesFilters["hideLocalDeployments"] && game.SettingsOpt.LocalDeployments) return true;
  1111. if (openGamesFilters["hideNonPractice"] && game.SettingsOpt.RankedGame) return true;
  1112. if (openGamesFilters["hideManualDistribution"] && !game.SettingsOpt.AutoDistribution) return true;
  1113. if (openGamesFilters["hideAutoDistribution"] && game.SettingsOpt.AutoDistribution) return true;
  1114. if (openGamesFilters["hideKeyword"] && openGamesFilters["hideKeyword"].length > 0 && $(game).containsKeyword()) return true;
  1115. if (openGamesFilters["hideRealTimeBootTime"] > 0 && game.RealTimeGame && game.DirectBoot < openGamesFilters["hideRealTimeBootTime"]) return true;
  1116. if (openGamesFilters["hideMultiDayBootTimeInMs"] > 0 && !game.RealTimeGame && game.DirectBoot < openGamesFilters["hideMultiDayBootTimeInMs"]) return true;
  1117.  
  1118. return false;
  1119. };
  1120.  
  1121. $.fn.numOfPlayers = function () {
  1122. var game = this[0];
  1123. return game.Players.length + game.OpenSeats.length;
  1124.  
  1125. };
  1126.  
  1127. $.fn.playerJoined = function () {
  1128. var game = this[0];
  1129. var playerJoined = false;
  1130. var id = warlight.shared.viewmodels.SignIn.get_CurrentPlayer().ID;
  1131. $.each(game.Players, function (key, player) {
  1132. if (player.PlayerID == id) {
  1133. playerJoined = true;
  1134. }
  1135. });
  1136. return playerJoined;
  1137. };
  1138.  
  1139. $.fn.markJoined = function () {
  1140. var game = this[0];
  1141. game.Name += '##joined##';
  1142. return game;
  1143. };
  1144.  
  1145. $.fn.numOfTeams = function () {
  1146. var game = this[0];
  1147. var teams = 0;
  1148. if (game.AtStartDivideIntoTeamsOfIfOpenGame > 0) return $(game).numOfPlayers() / game.AtStartDivideIntoTeamsOfIfOpenGame;
  1149. if (Math.max.apply(Math, game.OpenSeats) == -1) return 0;
  1150. var maxTeam = Math.max.apply(Math, game.OpenSeats);
  1151. $.each(game.Players, function (key, player) {
  1152. if (player.Team > maxTeam) {
  1153. maxTeam = player.Team;
  1154. };
  1155. });
  1156. return maxTeam + 1;
  1157. }
  1158.  
  1159. $.fn.containsKeyword = function () {
  1160. var game = this[0];
  1161. var keywords = openGamesFilters["hideKeyword"].split(",");
  1162. var title = game._nameLowered || game.Name.toLowerCase();
  1163. var filtered = false;
  1164. $.each(keywords, function (key, keyword) {
  1165. if (title.indexOf(keyword.trim().toLowerCase()) >= 0) {
  1166. filtered = true;
  1167. }
  1168. })
  1169. return filtered;
  1170.  
  1171. };
  1172.  
  1173. }(jQuery));
  1174.  
  1175.  
  1176. function storeFilterVariables() {
  1177. openGamesFilters = {};
  1178.  
  1179. $.each(filters, function (key, filter) {
  1180. if (filter.type == "checkbox") {
  1181. openGamesFilters[filter.id] = $("#" + filter.id).prop("checked");
  1182. }
  1183. });
  1184. openGamesFilters["hideKeyword"] = $("#hideKeyword").val()
  1185. openGamesFilters["hideRealTimeBootTime"] = $("#hideRealTimeBootTime").val()
  1186. openGamesFilters["hideMultiDayBootTimeDays"] = $("#hideMultiDayBootTimeDays").val()
  1187. openGamesFilters["hideMultiDayBootTimeHours"] = $("#hideMultiDayBootTimeHours").val()
  1188.  
  1189. var luck = $("#hideLuck").val();
  1190. openGamesFilters["hideLuck"] = ($.isNumeric(luck) && luck <= 100 && luck >= 0) ? luck : 100;
  1191.  
  1192. var minPlayers = $("#hideMinPlayers").val();
  1193. openGamesFilters["hideMinPlayers"] = ($.isNumeric(minPlayers) && minPlayers <= 100 && minPlayers >= 2) ? minPlayers : 2;
  1194.  
  1195. var maxPlayers = $("#hideMaxPlayers").val();
  1196. openGamesFilters["hideMaxPlayers"] = ($.isNumeric(maxPlayers) && maxPlayers <= 100 && maxPlayers >= 2) ? maxPlayers : 100;
  1197.  
  1198. if (parseFloat(openGamesFilters["hideMinPlayers"]) > parseFloat(openGamesFilters["hideMaxPlayers"])) {
  1199. openGamesFilters["hideMaxPlayers"] = openGamesFilters["hideMinPlayers"]
  1200. }
  1201.  
  1202. var rtBoot = $("#hideRealTimeBootTime").val();
  1203. openGamesFilters["hideRealTimeBootTime"] = $.isNumeric(rtBoot) ? rtBoot * 60 * 1000 : 0;
  1204.  
  1205. var mdBoot = calculateMDBoot($("#hideMultiDayBootTimeHours").val(), $("#hideMultiDayBootTimeDays").val());
  1206.  
  1207. openGamesFilters["hideMultiDayBootTimeDays"] = mdBoot.days;
  1208. openGamesFilters["hideMultiDayBootTimeHours"] = mdBoot.hours;
  1209.  
  1210. openGamesFilters["hideMultiDayBootTimeInMs"] = (parseInt(mdBoot.days) * 24 + parseInt(mdBoot.hours)) * 60 * 60 * 1000;
  1211.  
  1212. localStorage.setItem("openGamesFilters", JSON.stringify(openGamesFilters));
  1213. updateFilterSettings()
  1214. }
  1215.  
  1216. function calculateMDBoot(hours, days) {
  1217. hours = $.isNumeric(hours) ? hours : 0;
  1218. days = $.isNumeric(days) ? days : 0;
  1219.  
  1220. if (hours >= 24) {
  1221. days = parseFloat(days) + parseInt(hours / 24);
  1222. hours -= parseInt(hours / 24) * 24
  1223. }
  1224.  
  1225. return {
  1226. hours: hours,
  1227. days: days
  1228. }
  1229.  
  1230. }
  1231.  
  1232. function updateFilterSettings() {
  1233.  
  1234. $.each(filters, function (key, filter) {
  1235. if (filter.type == "checkbox") {
  1236. $("#" + filter.id).prop("checked", openGamesFilters[filter.id]);
  1237. }
  1238. });
  1239. $("#hideLuck").val(openGamesFilters["hideLuck"] || 100);
  1240. $("#hideMinPlayers").val(openGamesFilters["hideMinPlayers"] || 0);
  1241. $("#hideMaxPlayers").val(openGamesFilters["hideMaxPlayers"] || 100);
  1242. $("#hideKeyword").val(openGamesFilters["hideKeyword"] || "");
  1243. $("#hideRealTimeBootTime").val(openGamesFilters["hideRealTimeBootTime"] / 1000 / 60 || 0);
  1244. $("#hideMultiDayBootTimeDays").val(openGamesFilters["hideMultiDayBootTimeDays"] || 0);
  1245. $("#hideMultiDayBootTimeHours").val(openGamesFilters["hideMultiDayBootTimeHours"] || 0);
  1246. }
  1247.  
  1248. function isEnabled(setting) {
  1249. return $(userscriptSettings).settingIsEnabled(setting);
  1250. }
  1251.  
  1252. function pageIsMultiplayer() {
  1253. return location.href.match(/.*warlight[.]net\/MultiPlayer.*/);
  1254. }
  1255.  
  1256. function pageIsDashboard() {
  1257. return location.href.match(/.*warlight[.]net\/MultiPlayer\/#?$/);
  1258. }
  1259.  
  1260. function pageIsProfile() {
  1261. return location.href.match(/.*warlight[.]net\/[P|p]rofile\?p=[0-9]+$/);
  1262. }
  1263.  
  1264. function pageIsClanThread() {
  1265. return location.href.match(/.*warlight[.]net\/Discussion/);
  1266. }
  1267.  
  1268. function pageIsForumThread() {
  1269. return location.href.match(/.*warlight[.]net\/Forum\/[0-9]+.*/);
  1270. }
  1271.  
  1272. function pageIsForum() {
  1273. return location.href.match(/.*warlight[.]net\/Forum\/.*/);
  1274. }
  1275.  
  1276. function pageIsLadderOverview() {
  1277. return location.href.match(/.*warlight[.]net\/Ladders/);
  1278. }
  1279.  
  1280. function pageIsClanForumThread() {
  1281. return location.href.match(/.*warlight[.]net\/Discussion\/\?ID=[0-9]+.*/);
  1282. }
  1283.  
  1284. function pageIsTournament() {
  1285. return location.href.match(/.*warlight[.]net\/MultiPlayer\/Tournament\?ID=[0-9]+/);
  1286. }
  1287.  
  1288. function pageIsGame() {
  1289. return location.href.match(/.*warlight[.]net\/MultiPlayer\?GameID=[0-9]+/);
  1290. }
  1291.  
  1292. function showOpenGamesLink() {
  1293. $("#SubTabRow td:nth-child(8)").after('<td valign="top"><img src="https://d2wcw7vp66n8b3.cloudfront.net/Images/Tabs/SubSelectedLeft.png" width="6" height="16" style="visibility: hidden"></td><td nowrap="nowrap" class="SubTabCell" id="openGamesTab"><a href="/MultiPlayer/OpenGames">Open Games</a></td><td valign="top"><img src="https://d2wcw7vp66n8b3.cloudfront.net/Images/Tabs/SubSelectedRight.png" width="6" height="16" style="visibility: hidden"></td><td width="10">&nbsp;</td>');
  1294.  
  1295. if (location.href.match(/.*warlight[.]net\/MultiPlayer\/OpenGames.*/)) {
  1296. $("#openGamesTab").addClass("SubTabCellSelected");
  1297. $("#openGamesTab").prev().children().css("visibility", "visible");
  1298. $("#openGamesTab").next().children().css("visibility", "visible");
  1299. }
  1300. }
  1301.  
  1302. function setupOpenGamesFilter() {
  1303. $("#OpenGamesTable thead tr td").prepend('<a id="editFilters" style="color:#DDDDDD;font-size: 14px;float: right;">▼</a>');
  1304.  
  1305.  
  1306. var filtersHTML = "<hr>";
  1307. $.each(filters, function (key, filter) {
  1308. if (filter.type == "checkbox") {
  1309. filtersHTML += '<div class="filterOption"><label for="' + filter.id + '">' + filter.text + '</label><input type="checkbox" id="' + filter.id + '"></div>';
  1310. } else if (filter.type == "custom") {
  1311. filtersHTML += '<div class="filterOption">' + filter.text + '</div>';
  1312. }
  1313. });
  1314.  
  1315. $("body").append("<div class='popup popup840 filters-show' style='display: none'><div class='head'>Change Filter Settings<img class='close-popup-img' src='https://i.imgur.com/RItbpDS.png' height='25' width='25'></div>" + filtersHTML + '<div class="close-userscript">Close and Apply</div></div>');
  1316.  
  1317. createSelector('hr', 'height: 1px;border: none;background-color: gray;opacity:0.5;');
  1318. createSelector('.number', 'width: 31px');
  1319. createSelector('.filterOption', 'width: 400px;float: left;margin: 5px;');
  1320. createSelector('.info', 'font-size: 12px;color: gray;border: 1px gray solid;padding: 5px;display: block;margin: 8px 0 8px 0;line-height: 20px;overflow: hidden; max-height:18px;transition:max-height 2s;-webkit-transition:max-height 2s;');
  1321. createSelector('.info:hover', 'max-height:500px');
  1322. createSelector('#hideKeyword', 'text-align: left;');
  1323. createSelector('.filter-small, .filter-small label', 'font-size: 12px!important;color: #aaa;');
  1324.  
  1325. $("#hideLuck").after("%");
  1326.  
  1327. createSelector('.ui-button-text-only .ui-button-text', 'padding: .4em 0.6em;');
  1328. createSelector('#editFilters:hover', 'cursor:pointer');
  1329.  
  1330. $(".filters-show").on("change", function () {
  1331. storeFilterVariables();
  1332. });
  1333.  
  1334. $("#editFilters").on("click", function () {
  1335. window.showFilterOptions();
  1336. });
  1337.  
  1338. $(".close-userscript").on("click", function () {
  1339. $(".filters-show").fadeOut();
  1340. $(".overlay").fadeOut();
  1341. refreshAllGames(true);
  1342. });
  1343.  
  1344. $(".close-popup-img").on("click", function () {
  1345. $(".overlay").fadeOut();
  1346. $(".popup").fadeOut();
  1347. });
  1348.  
  1349. updateFilterSettings();
  1350. }
  1351.  
  1352. function hightlightNewClanForumPosts() {
  1353.  
  1354. var regex1 = /.* commented [\n \t]+/;
  1355. var regex2 = / ago/;
  1356. var regex3 = /.*\/Forum\//;
  1357. var regex4 = /-.*/;
  1358.  
  1359. var data = localStorage.getItem('clanForumThreadsTime');
  1360. if (data != null) {
  1361. data = JSON.parse(data);
  1362. } else if (data == null) {
  1363. data = [];
  1364. $.each($('#ClanForumTable tbody tr'), function (index, row) {
  1365. if ($(row).find('td a')[0].href.match(/.*Forum\/[0-9]+/)) {
  1366. var id = $(row).find('td a')[0].href.replace(regex3, "").replace(regex4, "");
  1367. data.push({
  1368. id: id,
  1369. date: new Date()
  1370. });
  1371. }
  1372. });
  1373.  
  1374. localStorage.setItem('clanForumThreadsTime', JSON.stringify(data));
  1375. }
  1376.  
  1377. $.each($('#ClanForumTable tbody tr'), function (index, row) {
  1378. if ($(row).find('td a')[0].href.match(/.*Forum\/[0-9]+/)) {
  1379. var lastComment = $(row).find('td span').text().trim().replace(regex1, "").replace(regex2, "");
  1380. var id = $(row).find('td a')[0].href.replace(regex3, "").replace(regex4, "");
  1381. var found = false;
  1382.  
  1383. $.each(data, function (key, val) {
  1384. if (val.id == id) {
  1385. found = true;
  1386. if (getDate(lastComment) > new Date(val.date)) {
  1387. $(row).css('background', '#4C4C33');
  1388. }
  1389. }
  1390. });
  1391. if (!found) {
  1392. $(row).css('background', '#4C4C33');
  1393. }
  1394. }
  1395. });
  1396. }
  1397.  
  1398. function setupBasicDashboardStyles() {
  1399. createSelector(".GameRow a", "font-size:16px !important;");
  1400. createSelector('#PromotedGamesTable td:last-of-type a img', 'display:none');
  1401. createSelector("#MyGamesTable td > a > img", 'display:none');
  1402. createSelector(".GameRow td:last-of-type span,#OpenGamesTable .GameRow td:last-of-type span:first-child, #PromotedGamesTable .GameRow td:last-of-type span:first-child", "margin:5px 0px;position:relative !important;z-index:10;");
  1403. createSelector("#MyGamesTable td span a img, #MyGamesTable td span a img", "display:inherit;");
  1404. createSelector(".GameRow:hover", "background-color:rgb(50, 50, 50);cursor:pointer;");
  1405. createSelector(".GameRow a:hover", "text-decoration:none;");
  1406. createSelector(".TournamentRow a:hover", "text-decoration:none;");
  1407. createSelector(".TournamentRow:hover", "background-color:rgb(50, 50, 50);cursor:pointer;");
  1408. createSelector(".ui-buttonset label", "font-size:11px;");
  1409. createSelector("#OpenGamesTable label:hover", " border: 1px solid #59b4d4;background: #0078a3 50% 50% repeat-x;font-weight: bold;color: #ffffff;");
  1410. createSelector("#OpenGamesTable td:last-child,#MyGamesTable td:last-child, #PromotedGamesTable td:last-child", "position: relative;");
  1411. createSelector("#OpenGamesTable td:nth-child(2) > a,#MyGamesTable td:nth-child(2) > a, #PromotedGamesTable td:nth-child(2) > a", " display: block;width: 100%;height: 100%;float: left;position: absolute;margin-top: -5px;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;");
  1412. createSelector(".loading", "position: absolute;height: 100%;width: 100%;background-color: rgba(255, 255, 255, 0.2);text-align: center;z-index: 12;margin-top: 34px;display:none;");
  1413. createSelector(".loading img", "position: absolute;top: 50%;left: 50%;margin-left: -16px;margin-top: -16px;");
  1414. createSelector("img", "position: relative;z-index:50;");
  1415. createSelector("input", "z-index: 1000;position: relative;");
  1416. createSelector(".showGames thead tr", "background: rgb(51, 0, 0) none repeat scroll 0% 0%;z-index: 500000;position: absolute;padding: 5px;border-bottom: 1px solid rgb(68, 68, 68);border-top-left-radius: 8px;width: calc(100% - 30px);letter-spacing: 1px;");
  1417. createSelector(".showGames table tbody", "display:table;width:100%;");
  1418. createSelector(".showGames table thead", "position:inherit;");
  1419.  
  1420. $.each($(".TournamentRow td"), function () {
  1421. $(this).find("font:first-of-type").appendTo($(this).find("a")).css("font-size", "10px");
  1422. });
  1423. }
  1424.  
  1425. function setupFixedWindowStyles() {
  1426. createSelector(".followMeBar", "background: #330000;padding: 5px 0px;position: relative;z-index: 1;color: #fff;border-top-right-radius:8px;border-top-left-radius:8px;border: 1px solid gray;border-bottom:none");
  1427. var top = parseInt($(".showSide").offset().top) + parseInt(43);
  1428. createSelector(".followMeBar.fixed", "position: fixed;top: " + top + "px;z-index: 0;z-index:100;");
  1429. createSelector(".followMeBar.fixed.absolute", "position: absolute;");
  1430.  
  1431. createSelector(".showSide", "overflow-y:scroll;float: left;margin-top: 43px;padding-right: 6px;");
  1432. createSelector(".showSide thead", "display:none");
  1433. createSelector(".showSide table", "border-top-right-radius:0;border-top-left-radius:0");
  1434.  
  1435. createSelector("#switchGameRadio label", "margin-left: 6px !important");
  1436. createSelector(".showGames table", "display:block !important");
  1437. createSelector("#switchGameRadio label:hover", "border: 1px solid rgb(89, 180, 212);border-image-source: initial;border-image-slice: initial;border-image-width: initial;border-image-outset: initial;border-image-repeat: initial;background:rgb(0, 120, 163);font-weight: bold;color: rgb(255, 255, 255);");
  1438. createSelector("#MyGamesTable, #PromotedGamesTable, #OpenGamesTable", "display:none");
  1439. createSelector("#MainSiteContent > table > tbody > tr > td", "width:100%");
  1440. createSelector(".MainColumn", "width: calc(60% - 98px)!important;max-width: 800px;min-width:535px");
  1441. createSelector(".SideColumn", "float:left !important");
  1442. createSelector("h2 + span", "margin-right: 50px;");
  1443. createSelector("body", "overflow:hidden");
  1444. createSelector(".SideColumn", "width: 100% !important;");
  1445. createSelector("#MyGamesFilter", "width:200px");
  1446. createSelector(".showGames table", "display:block; overflow-y:scroll; overflow-x:hidden; border:1px gray solid; border-radius:8px");
  1447. createSelector(".adsbygoogle", "margin-top: 25px;");
  1448. createSelector(".showSide", "overflow-y:scroll;float: left;margin-top: 43px;padding-right: 6px;width:33.55%; min-width:500px;margin-left: 20px;border-top-left-radius:8px;border-top-right-radius:8px");
  1449. createSelector("#refreshAll", "width: 140px;float: right;margin-top: 10px;");
  1450. createSelector("#fakeOpenGameMenu label", "margin-right:2px");
  1451. createSelector("#RestoreLotteryGamesBtn", "display:none");
  1452.  
  1453. createSelector('#ForumTable tbody tr td, #ClanForumTable tbody tr td', 'overflow:hidden;position:relative');
  1454. createSelector('#ForumTable tbody tr td > a, #ClanForumTable tbody tr td > a', 'width: 100%;display: block;height: 100%;float: left;position: absolute;overflow: hidden;z-index: 1;');
  1455. createSelector('#ForumTable tbody tr td span, #ClanForumTable tbody tr td span', 'display: inline-block;z-index: 1;float: left;position: relative;');
  1456. createSelector('#ForumTable tbody tr:hover, #ClanForumTable tbody tr:hover', 'background-color:rgb(50, 50, 50)');
  1457.  
  1458. createSelector('#ForumTable tbody tr td a[href="/Forum/Forum"]', 'position: relative;');
  1459. createSelector('#ClanForumTable tbody tr td a[href="/Clans/Forum"]', 'position: relative;');
  1460.  
  1461.  
  1462. }
  1463.  
  1464. function setupFixedTitlesInSideColumn() {
  1465. var blogTable = $("#BlogTable");
  1466. var realTimeLadderTable = $("#RealTimeLadderTable");
  1467. var forumTable = $("#ForumTable");
  1468. var clanForumTable = $("#ClanForumTable");
  1469. var mapOfTheWeekTable = $("#MapOfTheWeekTable");
  1470. var leaderboardTable = $("#LeaderboardTable");
  1471. var myTournamentsTable = $("#MyTournamentsTable");
  1472. var bookmarkTable = $("#BookmarkTable");
  1473.  
  1474. blogTable.before("<div class='followMeBar'>" + blogTable.find("thead > tr > td").html() + "</div>");
  1475. realTimeLadderTable.before("<div class='followMeBar'>" + realTimeLadderTable.find("thead > tr > td").html() + "</div>");
  1476. forumTable.before("<div class='followMeBar'>" + forumTable.find("thead > tr > td").html() + "</div>");
  1477. clanForumTable.before("<div class='followMeBar'>" + clanForumTable.find("thead > tr > td").html() + "</div>");
  1478. mapOfTheWeekTable.before("<div class='followMeBar'>" + mapOfTheWeekTable.find("thead > tr > td").html() + "</div>");
  1479. if (!isEnabled("hideCoinsGlobally")) {
  1480. leaderboardTable.before("<div class='followMeBar'>" + leaderboardTable.find("thead > tr > td").html() + "</div>");
  1481. }
  1482. myTournamentsTable.before("<div class='followMeBar'>" + myTournamentsTable.find("thead > tr > td").html() + "</div>");
  1483. bookmarkTable.before("<div class='followMeBar'>" + bookmarkTable.find("thead > tr > td").html() + "</div>");
  1484. var clotTable = $("#ClotTable");
  1485. clotTable.before("<div class='followMeBar'>" + clotTable.find("thead > tr > td").html() + "</div>");
  1486.  
  1487. new StickyTitles(jQuery(".followMeBar")).load();
  1488. }
  1489.  
  1490. function setupFixedWindowWithScrollableGames() {
  1491. var gameButtons = '<div style="margin: 10px;" id="switchGameRadio" class="ui-buttonset">';
  1492. gameButtons += '<input type="radio" id="ShowMyGames" name="switchGames" checked="checked" class="ui-helper-hidden-accessible">';
  1493. gameButtons += '<label for="ShowMyGames" class="ui-state-active ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button"><span class="ui-button-text">My Games</span></label>';
  1494. if (isEnabled('hidePromotedGames') || isEnabled('hideCoinsGlobally')) {
  1495. gameButtons += '<input type="radio" id="ShowOpenGames" name="switchGames" class="ui-helper-hidden-accessible">';
  1496. gameButtons += '<label for="ShowOpenGames" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right" role="button"><span class="ui-button-text">Open Games</span></label>';
  1497. } else {
  1498. gameButtons += '<input type="radio" id="ShowOpenGames" name="switchGames" class="ui-helper-hidden-accessible">';
  1499. gameButtons += '<label for="ShowOpenGames" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button"><span class="ui-button-text">Open Games</span></label>';
  1500. gameButtons += '<input type="radio" id="ShowCoinGames" name="switchGames" class="ui-helper-hidden-accessible">';
  1501. gameButtons += '<label for="ShowCoinGames" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right" role="button"><span class="ui-button-text">Coin Games</span></label>';
  1502. }
  1503.  
  1504. gameButtons += '</div>';
  1505.  
  1506.  
  1507. var mainColumn = $(".MainColumn ");
  1508. mainColumn.prepend('<div class="showGamesContainer">' + gameButtons + '<div class="showGames"></div></div>');
  1509. myGamesTable.appendTo(".showGames");
  1510.  
  1511. mainColumn.after('<div class="showSide"></div>');
  1512. $(".SideColumn").appendTo(".showSide");
  1513.  
  1514. setupFixedWindowStyles();
  1515.  
  1516. refreshSingleColumnSize();
  1517.  
  1518. $("#switchGameRadio").find("label").on("click", function () {
  1519. var newShowGames = $(this).attr("for");
  1520. if (newShowGames != showGamesActive) {
  1521. $.each($("#switchGameRadio").find("label"), function () {
  1522. $(this).removeClass("ui-state-active");
  1523. });
  1524. $(this).addClass("ui-state-active");
  1525.  
  1526. if (newShowGames == "ShowMyGames") {
  1527. showGamesActive = newShowGames;
  1528. promotedGamesTable.appendTo("body");
  1529. openGamesTable.appendTo("body");
  1530. myGamesTable.appendTo(".showGames");
  1531. } else if (newShowGames == "ShowCoinGames") {
  1532. showGamesActive = newShowGames;
  1533. myGamesTable.appendTo("body");
  1534. openGamesTable.appendTo("body");
  1535. promotedGamesTable.appendTo(".showGames");
  1536. } else if (newShowGames == "ShowOpenGames") {
  1537. showGamesActive = newShowGames;
  1538. myGamesTable.appendTo("body");
  1539. promotedGamesTable.appendTo("body");
  1540. openGamesTable.appendTo(".showGames");
  1541. }
  1542.  
  1543. refreshSingleColumnSize()
  1544. }
  1545. });
  1546. }
  1547.  
  1548. function hideRightColumn() {
  1549. if (isEnabled('scrollGames')) {
  1550. $(".showSide").css("display", "none");
  1551. createSelector(".MainColumn", "margin: auto;");
  1552. createSelector(".MainColumn", "max-width: 800px;");
  1553. createSelector(".MainColumn", "width: 60%!important;");
  1554. createSelector(".MainColumn", "float: none !important;");
  1555. createSelector(".MainColumn", "min-width: 600px !important;");
  1556. } else {
  1557. $(".SideColumn").css("display", "none");
  1558. $(".MainColumn").css("width", "100%");
  1559. $(".MainColumn").css("max-width", "800px");
  1560. }
  1561. }
  1562.  
  1563. function registerGameTabClick() {
  1564. if (lastClick - new Date() > 2000) {
  1565. openGamesTable.scrollTop(0);
  1566. lastClick = new Date();
  1567. }
  1568. window.setTimeout(function () {
  1569. domRefresh();
  1570. addOpenGamesSuffix();
  1571. }, 1);
  1572. }
  1573.  
  1574. function registerClanThread() {
  1575. var id = location.href.replace(/.*warlight[.]net\/Discussion\/[?]ID=/, "");
  1576. var data = localStorage.getItem('clanForumThreadsTime');
  1577.  
  1578. if (data != null) {
  1579. data = JSON.parse(data)
  1580. } else {
  1581. data = [];
  1582. }
  1583. var found = false;
  1584.  
  1585. $.each(data, function (key, val) {
  1586. if (val.id == id) {
  1587. data[key] = {
  1588. id: id,
  1589. date: new Date()
  1590. };
  1591. found = true;
  1592. }
  1593. });
  1594. if (!found) {
  1595. data.push({
  1596. id: id,
  1597. date: new Date()
  1598. });
  1599. }
  1600.  
  1601. localStorage.setItem('clanForumThreadsTime', JSON.stringify(data))
  1602. }
  1603.  
  1604. function updateOpenGamesCounter() {
  1605. var numMD = countGames(wljs.AllOpenGames, 1);
  1606. var numRT = countGames(wljs.AllOpenGames, 2);
  1607. var numBoth = parseInt(numMD) + parseInt(numRT)
  1608.  
  1609. //Both
  1610. $("#OpenGamesTable [for='BothRadio'] span").text('Both (' + numBoth + ')')
  1611. //Real
  1612. $("#OpenGamesTable [for='RealTimeRadio'] span").text('Real-Time (' + numRT + ')')
  1613. //Multi-Day
  1614. $("#OpenGamesTable [for='MultiDayRadio'] span").text('Multi-Day (' + numMD + ')')
  1615. }
  1616.  
  1617. // Type 1 : Multiday
  1618. // Type 2 : Realtime
  1619. function countGames(games, type) {
  1620. games = system.linq.Enumerable.Where(games, function (a) {
  1621. if (type == 1) return !a.RealTimeGame;
  1622. if (type == 2) return a.RealTimeGame;
  1623. });
  1624. return system.linq.Enumerable.ToArray(games).length
  1625. }
  1626.  
  1627. function addOpenGamesSuffix() {
  1628. var deletedBoth = parseInt(deletedMD) + parseInt(deletedRT);
  1629. $("#OpenGamesTable tbody tr:not(.GameRow)").remove();
  1630. var active = $("#OpenGamesTable .ui-buttonset .ui-state-active").text();
  1631.  
  1632. if (active.indexOf('Both') > -1 && deletedBoth > 0) {
  1633. //Both
  1634. $("#OpenGamesTable tbody").append("<tr id='gamesAreHidden' style='color: gray;font-style: italic;'><td colspan='2'>" + getNumHiddenLabelText(deletedBoth) + " <span style='float: right;cursor: pointer;font-size: 11px;margin-left: 10px;display: inline-block;margin-top: 2px;margin-right: 20px;' onclick='showFilterOptions()'>Change Filter Options</span</td></tr>");
  1635. } else if (active.indexOf('Real') > -1 && deletedRT > 0) {
  1636. //Real
  1637. $("#OpenGamesTable tbody").append("<tr id='gamesAreHidden' style='color: gray;font-style: italic;'><td colspan='2'>" + getNumHiddenLabelText(deletedRT) + " <span style='float: right;cursor: pointer;font-size: 11px;margin-left: 10px;display: inline-block;margin-top: 2px;margin-right: 20px;' onclick='showFilterOptions()'>Change Filter Options</span</td></tr>");
  1638. } else if (active.indexOf('Multi') > -1 && deletedMD > 0) {
  1639. //Multi-Day
  1640. $("#OpenGamesTable tbody").append("<tr id='gamesAreHidden' style='color: gray;font-style: italic;'><td colspan='2'>" + getNumHiddenLabelText(deletedMD) + " <span style='float: right;cursor: pointer;font-size: 11px;margin-left: 10px;display: inline-block;margin-top: 2px;margin-right: 20px;' onclick='showFilterOptions()'>Change Filter Options</span</td></tr>");
  1641. }
  1642.  
  1643. }
  1644.  
  1645. function getNumHiddenLabelText(num) {
  1646. return num == 1 ? "1 Game is hidden" : (num + " Games are hidden");
  1647. }
  1648.  
  1649.  
  1650. function loadPrivateNotes() {
  1651. console.log("loading private notes")
  1652. $("#FeedbackMsg").after('<div id="privateNotes" style="background-image: url(\'https://d2wcw7vp66n8b3.cloudfront.net/Images/ProfileSpeedBackground.png\'); background-repeat: no-repeat; text-align: left; padding:10px;margin-top: 12px;"><h3>Private Notes</h3><p style="width: 285px;overflow:hidden" class="content">Loading Privates Notes..</p></div>');
  1653. var url = $("img[alt='Private Notes']").parent()[0].href;
  1654. var page = $('<div />').load(url, function () {
  1655. var notes = page.find('#PostForDisplay_0').html().trim();
  1656. if (notes) {
  1657. $('#privateNotes .content').html(notes);
  1658. } else {
  1659. $('#privateNotes .content').html('You don\'t have any Private Notes.');
  1660. }
  1661.  
  1662. });
  1663. }
  1664.  
  1665. window.showFilterOptions = function () {
  1666. $(".filters-show").fadeIn();
  1667. $(".overlay").fadeIn();
  1668. }
  1669.  
  1670. function domRefresh() {
  1671. // $("body").css("diplay", "none");
  1672. // $("body").css("diplay", "block");
  1673. $("body").hide(0).show(0);
  1674. $(window).trigger('resize')
  1675. }
  1676.  
  1677. window.showFilterHelp = function (text, obj) {
  1678. window.setTimeout(function () {
  1679. if (!$(".custom-menu").is(':visible')) {
  1680. $(".custom-menu .content").html(text);
  1681. $(".custom-menu").finish().toggle(100).
  1682.  
  1683. // In the right position (the mouse)
  1684. css({
  1685. top: $(obj).offset().top + "px",
  1686. left: $(obj).offset().left + "px"
  1687. });
  1688. }
  1689.  
  1690. }, 10);
  1691. }
  1692.  
  1693. function setupBookmarkMenu() {
  1694. bookmarkBody = "<label for='bookmarkName'>Name</label><input style='width:100%;color: lightgray;text-align: left;' type='text' id='bookmarkName'><br><br><label for='bookmarkURL'>Url</label><input style='width:100%; text-align: left; color: lightgray' id='bookmarkURL' type='text'><br><br><label for='bookmarkNewWindow'>Open in new Window</label><input style='float:left;' id='bookmarkNewWindow' type='checkbox'>";
  1695.  
  1696. $("body").append("<div class='popup popup600' id='bookmarkMenu' style='display: none; margin-top: 150px;width:500px; margin-left:-282px'><div class='head' style=' margin-top: 152px;width:560px;'>Add Bookmark<img class='close-popup-img' src='https://i.imgur.com/RItbpDS.png' height='25' width='25'></div>" + bookmarkBody + "<div class='close-userscript' onclick='saveBookmark()'>Add Bookmark</div></div>");
  1697.  
  1698. $("bookmarkMenu").append('<div id="bookmarkMenu"></div>');
  1699.  
  1700. $(".close-popup-img").on("click", function () {
  1701. $(".popup").fadeOut();
  1702. $(".overlay").fadeOut();
  1703. });
  1704. createSelector(".highlightedBookmark", "background-color:rgb(50, 50, 50);cursor:pointer;");
  1705. $("body").append("<ul class='context-menu'><li onclick='editBookmark()'>Edit</li><li onclick='moveBookmarkUp()'>Move up</li><li onclick='moveBookmarkDown()'>Move Down</li></ul>")
  1706.  
  1707. }
  1708.  
  1709. function setupBookmarkTable() {
  1710. $(".SideColumn").prepend('<table class="dataTable" cellspacing="0" width="100%" id="BookmarkTable" style="text-align: left;"><thead><tr><td style="text-align: center">Bookmarks<img src="https://i.imgur.com/lT6SvSY.png" width="15" height="15" onclick="showAddBookmark()"style="display:inline-block;float:right; opacity: 0.6; margin-right:15px; cursor: pointer"></td></tr></thead></table><br>');
  1711.  
  1712. if (bookmarks.length > 0) {
  1713. refreshBookmarks();
  1714.  
  1715. } else {
  1716. var tables = $(".SideColumn .dataTable").filter(function () {
  1717. return $(this).css('opacity') == '1';
  1718. })
  1719. table = $(tables).get($(tables).length - 1)
  1720. $(table).after('<div style="text-align: left;margin-top: 15px;"><a onclick="showAddBookmark()" style="cursor:pointer">Add a Bookmark...</a></div>')
  1721. }
  1722. }
  1723.  
  1724. function refreshBookmarks() {
  1725. $("#BookmarkTable tbody tr").remove();
  1726. bookmarks.sort((a, b) => {return a.id - b.id})
  1727. var data = "<tbody>";
  1728. $.each(bookmarks, function (key, bookmark) {
  1729. data += '<tr data-bookmarkId="' + bookmark.id + '"><td><a ' + (bookmark.newWindow ? 'target="blank"' : "") + ' href="' + bookmark.url + '">' + bookmark.name + '</a>';
  1730. data += '<a onclick="deleteBookmark(' + bookmark.id + ')" style="display:inline-block;float:right; opacity: 0.6;cursor: pointer;margin-right:5px">';
  1731. data += '<img src="https://i.imgur.com/KrTbICA.png" width="15" height="15" ></a></td></tr>';
  1732. })
  1733.  
  1734. $("#BookmarkTable").prepend(data + '</tbody>');
  1735.  
  1736. }
  1737.  
  1738. var bookmarkId;
  1739. window.showAddBookmark = function () {
  1740. $(".overlay").fadeIn();
  1741. $("#bookmarkMenu").show();
  1742. bookmarkId = undefined
  1743. }
  1744.  
  1745. window.editBookmark = function () {
  1746. $.each(bookmarks, function (key, bookmark) {
  1747. if (bookmarkId == bookmark.id) {
  1748. $("#bookmarkURL").val(bookmark.url);
  1749. $("#bookmarkName").val(bookmark.name);
  1750. $("#bookmarkNewWindow").prop("checked", bookmark.newWindow)
  1751. }
  1752. })
  1753.  
  1754. $(".overlay").fadeIn();
  1755. $("#bookmarkMenu").show();
  1756. }
  1757.  
  1758. window.moveBookmarkUp = function() {
  1759. var oldIdx
  1760. var newIdx = -1
  1761. $.each(bookmarks, function (key, bookmark) {
  1762. if (bookmarkId == bookmark.id) {
  1763. oldIdx = key
  1764. }
  1765. })
  1766. var tempId = -1
  1767. $.each(bookmarks, function (key, bookmark) {
  1768. if (bookmark.id < bookmarkId && bookmark.id > tempId) {
  1769. newIdx = key
  1770. tempId = bookmark.id
  1771. }
  1772. })
  1773. if(newIdx != -1) {
  1774. var oldId = bookmarks[oldIdx].id
  1775. var newId = bookmarks[newIdx].id
  1776. bookmarks[oldIdx].id = -1
  1777. bookmarks[newIdx].id = oldId
  1778. bookmarks[oldIdx].id = newId
  1779.  
  1780. localStorage.setItem("bookmarks", JSON.stringify(bookmarks));
  1781.  
  1782. $("#bookmarkURL").val('');
  1783. $("#bookmarkName").val('');
  1784. $("#bookmarkNewWindow").prop('checked', false);
  1785. $(".overlay").fadeOut();
  1786.  
  1787. showBookmarkTable();
  1788.  
  1789. refreshBookmarks();
  1790. }
  1791. }
  1792.  
  1793. window.moveBookmarkDown = function() {
  1794. var oldIdx
  1795. var newIdx = -1
  1796. $.each(bookmarks, function (key, bookmark) {
  1797. if (bookmarkId == bookmark.id) {
  1798. oldIdx = key
  1799. }
  1800. })
  1801. var tempId = 10000000
  1802. $.each(bookmarks, function (key, bookmark) {
  1803. if (bookmark.id > bookmarkId && bookmark.id < tempId) {
  1804. newIdx = key
  1805. tempId = bookmark.id
  1806. }
  1807. })
  1808. if(newIdx != -1) {
  1809. var oldId = bookmarks[oldIdx].id
  1810. var newId = bookmarks[newIdx].id
  1811. bookmarks[oldIdx].id = -1
  1812. bookmarks[newIdx].id = oldId
  1813. bookmarks[oldIdx].id = newId
  1814.  
  1815. localStorage.setItem("bookmarks", JSON.stringify(bookmarks));
  1816.  
  1817. $("#bookmarkURL").val('');
  1818. $("#bookmarkName").val('');
  1819. $("#bookmarkNewWindow").prop('checked', false);
  1820. $(".overlay").fadeOut();
  1821.  
  1822. showBookmarkTable();
  1823.  
  1824. refreshBookmarks();
  1825. }
  1826. }
  1827.  
  1828.  
  1829. window.deleteBookmark = function (id) {
  1830. var idx;
  1831. $.each(bookmarks, function (key, bookmark) {
  1832. if (id == bookmark.id) {
  1833. idx = key;
  1834. }
  1835. })
  1836. $("[data-bookmarkId='" + id + "']").remove();
  1837. bookmarks.splice(idx, 1);
  1838. localStorage.setItem("bookmarks", JSON.stringify(bookmarks));
  1839.  
  1840. }
  1841.  
  1842. window.saveBookmark = function () {
  1843. $("#bookmarkMenu").hide();
  1844. var url = $("#bookmarkURL").val().trim();
  1845. url = (url.lastIndexOf('http', 0) === 0) ? url : "http://" + url;
  1846. var name = $("#bookmarkName").val().trim();
  1847. var newWindow = $("#bookmarkNewWindow").prop("checked");
  1848. if(bookmarkId == undefined) {
  1849. bookmarks.push({
  1850. name: name,
  1851. url: url,
  1852. newWindow: newWindow,
  1853. id: getBookmarkId()
  1854. });
  1855. } else {
  1856. var idx;
  1857. $.each(bookmarks, function (key, bookmark) {
  1858. if (bookmarkId == bookmark.id) {
  1859. idx = key
  1860. }
  1861. })
  1862. bookmarks[idx] = {
  1863. name: name,
  1864. url: url,
  1865. newWindow: newWindow,
  1866. id: bookmarkId
  1867. }
  1868. }
  1869. localStorage.setItem("bookmarks", JSON.stringify(bookmarks));
  1870.  
  1871. $("#bookmarkURL").val('');
  1872. $("#bookmarkName").val('');
  1873. $("#bookmarkNewWindow").prop('checked', false);
  1874. $(".overlay").fadeOut();
  1875.  
  1876. showBookmarkTable();
  1877.  
  1878. refreshBookmarks();
  1879. }
  1880.  
  1881. function checkBookmarkTable() {
  1882. if (bookmarks.length == 0) {
  1883. hideBookmarkTable();
  1884. }
  1885.  
  1886. }
  1887.  
  1888. function hideBookmarkTable() {
  1889. $("#BookmarkTable").hide();
  1890. if ($("#BookmarkTable").prev().hasClass("followWrap")) {
  1891. $("#BookmarkTable").prev().hide();
  1892. }
  1893. if ($("#BookmarkTable").next().is('br')) {
  1894. $("#BookmarkTable").next().hide();
  1895. }
  1896. }
  1897.  
  1898. function showBookmarkTable() {
  1899. $("#BookmarkTable").show();
  1900. if ($("#BookmarkTable").prev().hasClass("followWrap")) {
  1901. $("#BookmarkTable").prev().show();
  1902. }
  1903. if ($("#BookmarkTable").next().is('br')) {
  1904. $("#BookmarkTable").next().show();
  1905. }
  1906. }
  1907.  
  1908. window.bookmarkForumThread = function () {
  1909. var title = $("title").text().replace(' - Play Risk Online Free - WarLight', '');
  1910. var url = window.location.href;
  1911.  
  1912. $("#bookmarkURL").val(url);
  1913. $("#bookmarkName").val(title);
  1914. showAddBookmark();
  1915.  
  1916. }
  1917. window.bookmarkTournament = function () {
  1918. var title = $("#TournamentName").text().replace("Tournament: ", "").trim();
  1919. var url = window.location.href;
  1920.  
  1921. $("#bookmarkURL").val(url);
  1922. $("#bookmarkName").val(title);
  1923. showAddBookmark();
  1924.  
  1925. }
  1926.  
  1927. function addDefaultBookmark() {
  1928. bookmarks = [];
  1929. bookmarks.push({
  1930. name: "Tidy up Your Dashboard #2",
  1931. url: "https://www.warlight.net/Forum/106092-tidy-up-dashboard-2",
  1932. newWindow: false,
  1933. id: getBookmarkId()
  1934. });
  1935. localStorage.setItem("bookmarks", JSON.stringify(bookmarks));
  1936. }
  1937.  
  1938. function getBookmarkId() {
  1939. var id = 0;
  1940.  
  1941. $.each(bookmarks, function (key, bookmark) {
  1942. id = bookmark.id > id ? bookmark.id : id;
  1943. })
  1944.  
  1945. return id + 1;
  1946. }
  1947.  
  1948. var findMeIndex = -1;
  1949. window.findNextInTournament = function() {
  1950. var boxes = getPlayerBoxes();
  1951. var max = boxes.length - 1;
  1952. findMeIndex = findMeIndex == max ? 0 : findMeIndex + 1;
  1953. panzoomMatrix = undefined;
  1954. findInTournament();
  1955. }
  1956.  
  1957. function setupTournamentFindMe() {
  1958. $("body").keyup(function (event) {
  1959. // "Left" is pressed
  1960. var boxes = getPlayerBoxes();
  1961. var max = boxes.length - 1;
  1962. if(event.which == 37) {
  1963. findMeIndex = findMeIndex == 0 ? max : findMeIndex - 1;
  1964. panzoomMatrix = undefined;
  1965. findInTournament();
  1966. }
  1967. // "Right" is pressed
  1968. else if(event.which == 39) {
  1969. findMeIndex = findMeIndex == max ? 0 : findMeIndex + 1;
  1970. panzoomMatrix = undefined;
  1971. findInTournament();
  1972. }
  1973. // "Home" is pressed
  1974. else if(event.which == 36) {
  1975. findMeIndex = 0;
  1976. panzoomMatrix = undefined;
  1977. findInTournament();
  1978. }
  1979. // "End" is pressed
  1980. else if(event.which == 35) {
  1981. findMeIndex = boxes.length - 1;
  1982. panzoomMatrix = undefined;
  1983. findInTournament();
  1984. }
  1985. });
  1986. window.players = []
  1987. $("[href='#SettingsTab']").parent().after('<li id="findMe" class="ui-state-default ui-corner-top"><div style="cursor: pointer" class="ui-tabs-anchor" onclick="window.findNextInTournament()">Find <label id="activePlayer"></labal></div><a id="showPlayerSelect">▼</a></li>');
  1988. createSelector('#findMe:hover', 'border: 1px solid #59b4d4;background: #0078a3 url("https://d2wcw7vp66n8b3.cloudfront.net/jui4/images/ui-bg_glass_40_0078a3_1x400.png") 50% 50% repeat-x;font-weight: bold;color: #ffffff;border-bottom-width: 0')
  1989. createSelector('#findMe', 'border: 1px solid #666666;border-bottom-width: 0')
  1990.  
  1991. var css = '-webkit-keyframes pulsate{ 0% { background-color: rgba(0,0,0,0); } 50% { background-color: olive; } 100% { background-color: rgba(0,0,0,0); }}@keyframes pulsate { 0% { background-color: rgba(0,0,0,0); } 50% { background-color: olive; } 100% { background-color: rgba(0,0,0,0); }}.pulsate { -webkit-animation: pulsate 1s ease-in 1; -moz-animation: pulsate 1s ease-in 1; -ms-animation: pulsate 1s ease-in 1; -o-animation: pulsate 1s ease-in 1; animation: pulsate 1s ease-in 1;}-webkit-keyframes pulsate-border{ 0% { border: 3px solid #c4c2c4; } 25% { border: 3px solid red; } 50% { border: 3px solid red; } 100% { border: 3px solid #c4c2c4; }}@keyframes pulsate-border { 0% { border: 3px solid #c4c2c4; } 25% { border: 3px solid red; }50% { border: 3px solid red; } 100% { border: 3px solid #c4c2c4; }}.pulsate-border { -webkit-animation: pulsate-border 2s ease-in 1; -moz-animation: pulsate-border 2s ease-in 1; -ms-animation: pulsate-border 2s ease-in 1; -o-animation: pulsate-border 2s ease-in 1; animation: pulsate-border 2s ease-in 1;}',
  1992. head = document.head || document.getElementsByTagName('head')[0],
  1993. style = document.createElement('style');
  1994.  
  1995. style.type = 'text/css';
  1996. if (style.styleSheet) {
  1997. style.styleSheet.cssText = css;
  1998. } else {
  1999. style.appendChild(document.createTextNode(css));
  2000. }
  2001.  
  2002. head.appendChild(style);
  2003.  
  2004.  
  2005. $("#findMe").append('<div id="selectContainer"><div id="playerSelectInputContainer"><input placeholder="Search a Player" type="text" id="playerSelectInput"></input></div><div id="playerContainer"></div></div>');
  2006. self = {
  2007. id: warlight.shared.viewmodels.SignIn.get_CurrentPlayer().ID,
  2008. name: warlight.shared.viewmodels.SignIn.get_CurrentPlayer().Name,
  2009. fullID: String(warlight.shared.viewmodels.SignIn.get_CurrentPlayer().ProfileToken).substring(0, 2) + warlight.shared.viewmodels.SignIn.get_CurrentPlayer().ID + String(warlight.shared.viewmodels.SignIn.get_CurrentPlayer().ProfileToken).substring(2, 4),
  2010. team: $("[data-playerid='" + warlight.shared.viewmodels.SignIn.get_CurrentPlayer().ID + "'] td:nth-of-type(2)").text()
  2011. };
  2012. window.currentPlayer = self;
  2013. $.each($("#PlayingPlayers tr"), function (key, playerRow) {
  2014. var id = $(playerRow).attr("data-playerid");
  2015. var fullID = $(playerRow).find("a").get($(playerRow).find("a").length - 1).href.replace(/.*warlight.net\/Profile\?p=/, "");
  2016. var name = $(playerRow).find("td a").text();
  2017. var img = $(playerRow).find("td img").attr("src");
  2018. var team = $("[data-playerid='" + id + "'] td:nth-of-type(2)").text();
  2019. if (img && img.indexOf("MemberIcon") > -1) {
  2020. img = "";
  2021. }
  2022. window.players.push({
  2023. id: id,
  2024. fullID: fullID,
  2025. name: name,
  2026. img: img,
  2027. team: team
  2028. });
  2029. });
  2030.  
  2031.  
  2032. $("#playerSelectInput").on('input', function (data) {
  2033. $(".playerElement").remove();
  2034. var search = $(this).val().toLowerCase();
  2035. $("#playerContainer").append("<div class='playerElement' onclick='setCurrentplayer(self)'>" + self.name + " (Me)</div>")
  2036. $.each(window.players, function (key, player) {
  2037. if (player.name.toLowerCase().indexOf(search) > -1 && self.name != player.name) {
  2038. var img = player.img ? "<img src='" + player.img + "'>" : "";
  2039. $("#playerContainer").append("<div onclick='setCurrentplayer(players[" + key + "])' class='playerElement'>" + img + "<span>" + htmlEscape(player.name) + "</span>" + "</div>")
  2040. }
  2041. });
  2042.  
  2043. $("#activePlayer").html(window.currentPlayer.name == self.name ? "Me" : window.currentPlayer.name);
  2044. $("#playerContainer").scrollTop(0)
  2045.  
  2046. });
  2047. $("#playerSelectInput").trigger("input");
  2048.  
  2049. $("#showPlayerSelect").on("click", function () {
  2050. $("#selectContainer").toggle(100);
  2051. $("#playerContainer").scrollTop(0);
  2052. $("#playerSelectInput").trigger("input");
  2053. $("#playerSelectInput").focus();
  2054. });
  2055. createSelector("#playerSelectInputContainer", "height: 28px; ");
  2056. createSelector(".border-red", "border: 3px red solid !important; ");
  2057. createSelector(".playerElement span, .playerElement img", "display:inline-block; margin-right: 10px");
  2058. createSelector("#showPlayerSelect", "color: #DDDDDD;font-size: 14px;margin: 5px 5px 0 -3px;cursor: pointer; display: inline-block;margin-right: 10px;");
  2059. createSelector("#playerSelectInput", "display: block;margin: 5px 3%;width: 93%;");
  2060. createSelector("#activePlayer", "cursor:pointer");
  2061. createSelector(".playerElement", "border-bottom: 1px gray solid;padding: 7px;color: white; clear:both; height: 14px; font-weight: normal;");
  2062. createSelector(".playerElement:hover", "background: rgb(102, 102, 102);");
  2063. createSelector("#playerContainer", "border: 2px gray solid; overflow-y: auto; overflow-x: hidden;max-height: 275px; min-width: 175px; ");
  2064. createSelector("#selectContainer", "cursor: pointer; background:rgb(23, 23, 23);position: fixed; z-index: 10;border: 2px gray solid;border-radius: 5px;box-shadow: 0 20px 50px 3px black;margin-top: 16px;display: none");
  2065.  
  2066.  
  2067.  
  2068. }
  2069.  
  2070.  
  2071. window.setCurrentplayer = function (player) {
  2072. window.currentPlayer = {
  2073. id: player.id,
  2074. name: player.name,
  2075. fullID: player.fullID,
  2076. team: player.team
  2077. };
  2078. $("#selectContainer").toggle(100);
  2079. $("#activePlayer").html(htmlEscape(player.name == self.name ? "Me" : player.name));
  2080. $("#playerSelectInput").val("");
  2081. panzoomMatrix = undefined;
  2082. findMeIndex = 0;
  2083. window.findInTournament();
  2084. }
  2085.  
  2086. var panzoomMatrix;
  2087. window.findInTournament = function () {
  2088. var id;
  2089. $("#selectContainer").hide(100);
  2090. if ($("[href='#PlayersTab']").parent().hasClass("ui-state-active")) {
  2091. id = window.currentPlayer.id;
  2092. if ($("#PlayingPlayers [data-playerid='" + id + "']").length > 0) {
  2093. var player = $("#PlayingPlayers [data-playerid='" + id + "']");
  2094. var box = $("#CenterTabs").parent()
  2095. var offset = player.offset().top - box.offset().top - box.height() / 2
  2096.  
  2097. box.stop().animate({
  2098. scrollTop: offset
  2099. }, '500', 'swing');
  2100.  
  2101. window.setTimeout(function () {
  2102. $("#PlayingPlayers [data-playerid='" + window.currentPlayer.id + "']").addClass("pulsate");
  2103. window.setTimeout(function () {
  2104. $(".pulsate").removeClass("pulsate");
  2105. }, 1000);
  2106. }, 250);
  2107. } else {
  2108. showInfo("You didn't join this tournament.", $("#findMe").offset().top + 25, $("#findMe").offset().left + 25);
  2109. }
  2110.  
  2111. } else if ($("[href='#BracketTab']").parent().hasClass("ui-state-active") && $("[src='https://d2wcw7vp66n8b3.cloudfront.net/Images/TournamentIconBig_RR.png']").length == 0) {
  2112. id = window.currentPlayer.fullID;
  2113. if (getPlayerBoxes().length > 0) {
  2114.  
  2115. if (!panzoomMatrix) {
  2116. var currentMatrix = $("#Visualize").panzoom("getMatrix");
  2117. $("#Visualize").panzoom("reset", {
  2118. animate: false
  2119. });
  2120.  
  2121. VisualizePanzoom.panzoom("zoom", {
  2122. increment: 0.75,
  2123. animate: false
  2124. })
  2125. var boxes = getPlayerBoxes();
  2126. $(".TeamBoxHighlighted").removeClass("TeamBoxHighlighted");
  2127. boxes.addClass("TeamBoxHighlighted");
  2128. var offsetTop = $(boxes.get(findMeIndex)).offset().top - $("#VisualizeContainer").offset().top - $("#VisualizeContainer").height() / 4;
  2129. var offsetLeft = $(boxes.get(findMeIndex)).offset().left - $("#VisualizeContainer").offset().left - $("#VisualizeContainer").width() / 2;
  2130.  
  2131. $(".border-red").removeClass("border-red");
  2132. $(boxes.get(findMeIndex)).addClass("border-red");
  2133. $("#Visualize").panzoom("pan", 0 - offsetLeft, 100 - offsetTop, {
  2134. relative: true,
  2135. animate: false
  2136. });
  2137.  
  2138. panzoomMatrix = $("#Visualize").panzoom("getMatrix");
  2139. $("#Visualize").panzoom("setMatrix", currentMatrix, {
  2140. animate: false
  2141. });
  2142. }
  2143.  
  2144. window.setTimeout(function () {
  2145. $("#Visualize").panzoom("setMatrix", panzoomMatrix, {
  2146. animate: true
  2147. })
  2148. window.setTimeout(function () {
  2149. //getPlayerBoxes().addClass("pulsate-border");
  2150. window.setTimeout(function() {
  2151. $(".pulsate-border").removeClass("pulsate-border");
  2152. }, 2000)
  2153. }, 400);
  2154. }, 10)
  2155.  
  2156. } else {
  2157. if ($("#PlayingPlayers [data-playerid='" + window.currentPlayer.id + "']").length == 0) {
  2158. showInfo("You didn't join this tournament.", $("#findMe").offset().top + 25, $("#findMe").offset().left + 25);
  2159.  
  2160. } else {
  2161. showInfo("This tournament didn't start yet.", $("#findMe").offset().top + 25, $("#findMe").offset().left + 25);
  2162.  
  2163. }
  2164. }
  2165. }
  2166. }
  2167.  
  2168. function getPlayerBoxes() {
  2169. var boxes = $(".GameBox [href='/Profile?p=" + window.currentPlayer.fullID + "']").closest(".TeamBox");
  2170. if(boxes.length == 0) {
  2171. boxes = $("[title='" + window.currentPlayer.team + "']").closest(".TeamBox");
  2172. }
  2173. return boxes;
  2174. }
  2175.  
  2176. function htmlEscape(str) {
  2177. return String(str)
  2178. .replace(/&/g, '&amp;')
  2179. .replace(/"/g, '&quot;')
  2180. .replace(/'/g, '&#39;')
  2181. .replace(/</g, '&lt;')
  2182. .replace(/>/g, '&gt;');
  2183. }
  2184.  
  2185.  
  2186. $("#BookmarkTable").bind("contextmenu", function (event) {
  2187. $(".highlightedBookmark").removeClass("highlightedBookmark")
  2188. $(event.target).closest("tr").addClass("highlightedBookmark")
  2189. // Avoid the real one
  2190. event.preventDefault();
  2191. bookmarkId = $(event.target).closest("tr").attr("data-bookmarkid")
  2192. // Show contextmenu
  2193. $(".context-menu").finish().toggle(100).
  2194. // In the right position (the mouse)
  2195. css({
  2196. top: event.pageY + "px",
  2197. left: event.pageX + "px"
  2198. });
  2199. });
  2200.  
  2201.  
  2202. // If the document is clicked somewhere
  2203. $(document).bind("mousedown", function (e) {
  2204. // If the clicked element is not the menu
  2205. if (!$(e.target).parents(".context-menu").length > 0) {
  2206. // Hide it
  2207. $(".context-menu").hide(100);
  2208. $(".highlightedBookmark").removeClass("highlightedBookmark")
  2209. }
  2210. });
  2211.  
  2212.  
  2213. // If the menu element is clicked
  2214. $(".context-menu li").click(function(){
  2215. // This is the triggered action name
  2216. switch($(this).attr("data-action")) {
  2217. // A case for each action. Your actions here
  2218. case "first": alert("first"); break;
  2219. case "second": alert("second"); break;
  2220. case "third": alert("third"); break;
  2221. }
  2222. // Hide it AFTER the action was triggered
  2223. $(".context-menu").hide(100);
  2224. });
  2225.  
  2226.  
  2227.  
  2228. function setupExternalJS() {
  2229. if(pageIsProfile()) {
  2230. setupRandomizedBonus()
  2231. }
  2232. if(pageIsForum()) {
  2233. setupForumSpammerBeGone()
  2234. }
  2235. }
  2236.  
  2237. function setupRandomizedBonus() {
  2238. console.log("loaded random bonus")
  2239.  
  2240. var selectField = document.createElement("select")
  2241. selectField.id = "templateSelect"
  2242. var templates = [{id: 12345, text: "Strategic Earth"}, {id: 54345, text: "Strategic Earth 2"}]
  2243.  
  2244. for(var i = 0; i < templates.length; i++) {
  2245. var option = new Option();
  2246. option.value = templates[i].id;
  2247. option.text = templates[i].text;
  2248. selectField.options.add(option);
  2249. }
  2250.  
  2251. $("#gameId").before(selectField)
  2252.  
  2253. $("#templateSelect").on("change", function() {
  2254. $("#gameId").val(this.value)
  2255. })
  2256. }
  2257.  
  2258. function setupForumSpammerBeGone() {
  2259. console.log("loaded forum spam")
  2260. }
  2261.  
  2262. window.setInterval(setRTLadderTime, 1000)
  2263. function setupRealTimeLadder() {
  2264. if($("#RealTimeLadderTable").length == 0) {
  2265. $(".SideColumn").append('<table class="dataTable" cellspacing="0" width="100%" id="RealTimeLadderTable"><thead><tr><td>Real-Time Ladder</td></tr></thead><tbody><tr><td>Nobody is playing in the real-time ladder.<a href="/LadderSeason?ID=3">Ladder Page</a></td></tr> </tbody></table>')
  2266. }
  2267. if( $(".extendedRTLadderRow").length == 0) {
  2268. createSelector(".extendedRTLadderRow .rtBox", "width: calc(100%/2);");
  2269. createSelector(".extendedRTLadderRow span", "");
  2270. createSelector(".rtLeft", "float:left");
  2271. createSelector(".rtRight", "float:Right");
  2272. createSelector(".rtRight a", " padding: 10px 30px;position: absolute;margin-left: -75px;");
  2273. createSelector(".newGamesRT", "display:block");
  2274. createSelector(".rtLabelBig", "font-size: 18px; margin: 5px");
  2275. }
  2276. $(".extendedRTLadderRow").remove()
  2277. $("#RealTimeLadderTable tbody").append('<tr class="extendedRTLadderRow"><td colspan="2"><div class="rtLeft rtBox"><span class="newGamesRT">New Games in<br></span><div class="rtLabelBig"><span class="rtMin">00</span>:<span class="rtSec">00</span></div></div><div class="rtRight rtBox"><a href="https://www.warlight.net/LadderJoin?Ladder=RealTime" class="rtLabelBig">Join!</a></div></td></tr>')
  2278. $("[href='/LadderSeason?ID=3'").text("Ladder Page")
  2279. setRTLadderTime()
  2280. }
  2281.  
  2282.  
  2283. function setRTLadderTime() {
  2284. var date = new Date()
  2285. date.setMinutes(Math.ceil((new Date().getMinutes() + date.getSeconds() / 60) / 5) * 5)
  2286. date.setSeconds(0)
  2287. var diff = (date - new Date()) / 1000
  2288. var min = Math.floor(diff / 60) % 60
  2289. diff -= min * 60
  2290. var sec = diff % 60
  2291. $(".rtMin").text(padLeft(min))
  2292. $(".rtSec").text(padLeft(sec))
  2293. }
  2294.  
  2295. function padLeft(str) {
  2296. str = Math.round(str)
  2297. len = 2
  2298. symbol = '0'
  2299. while(String(str).length < len) {
  2300. str = symbol + str;
  2301. }
  2302. return str
  2303. }
  2304.  
  2305.  
  2306.  
  2307.  
  2308. /* Snowfall jquery plugin */
  2309. // requestAnimationFrame polyfill from https://github.com/darius/requestAnimationFrame
  2310. if (!Date.now)
  2311. Date.now = function() { return new Date().getTime(); };
  2312.  
  2313. (function() {
  2314. 'use strict';
  2315.  
  2316. var vendors = ['webkit', 'moz'];
  2317. for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
  2318. var vp = vendors[i];
  2319. window.requestAnimationFrame = window[vp+'RequestAnimationFrame'];
  2320. window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame']
  2321. || window[vp+'CancelRequestAnimationFrame']);
  2322. }
  2323. if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy
  2324. || !window.requestAnimationFrame || !window.cancelAnimationFrame) {
  2325. var lastTime = 0;
  2326. window.requestAnimationFrame = function(callback) {
  2327. var now = Date.now();
  2328. var nextTime = Math.max(lastTime + 16, now);
  2329. return setTimeout(function() { callback(lastTime = nextTime); },
  2330. nextTime - now);
  2331. };
  2332. window.cancelAnimationFrame = clearTimeout;
  2333. }
  2334. }());
  2335.  
  2336. function setupClotTable() {
  2337. if($("#ClotTable").length == 0) {
  2338. $(".SideColumn").append('<table class="dataTable" cellspacing="0" width="100%" id="ClotTable" style="text-align: left"><thead><tr><td style="text-align: center">CLOTs</td></tr></thead><tbody></tbody></table>')
  2339. }
  2340. parseClotTable()
  2341. loadClots()
  2342. createSelector(".clotLabel", "display: inline-block; width: 70px")
  2343. createSelector(".clotPlayers", "display: inline-block; margin-left: 5px; color:gray; ")
  2344. }
  2345.  
  2346. function setupLadderClotOverview() {
  2347. $("h1").text($("h1").text() + " & CLOTs")
  2348. var clotInfo = getClots()
  2349. if(!clotInfo) {
  2350. return
  2351. }
  2352. var clots = $.parseJSON(clotInfo)[0]
  2353. var ladders = clots['ladders']
  2354. var md = ""
  2355. var rt = ""
  2356. var counter = 0
  2357. $.each(ladders, function (key, val) {
  2358. if (val.type == "realtime") {
  2359. rt += "<li><big><a target='_blank' href=" + val.url + ">" + val.name + "</a> using Real-Time boot times</big></li><br><br>"
  2360. counter++
  2361. } else if (val.type == "multiday") {
  2362. md += "<li><big><a target='_blank' href = " + val.url + ">" + val.name + "</a> using Multi-Day boot times</big></li><br><br>"
  2363. counter++
  2364. }
  2365. })
  2366. $("#MainSiteContent > div").append("Warlight currently has " + toWords(counter) + " <a href='https://www.warlight.net/wiki/CLOT'>CLOTs</a><br><br>")
  2367. $("#MainSiteContent > div").append("<ul id='clotInfo'></ul>")
  2368. $("#clotInfo").append(rt)
  2369. $("#clotInfo").append(md)
  2370. }
  2371.  
  2372. function parseClotTable() {
  2373. try {
  2374. var clotInfo = getClots()
  2375. if(!clotInfo) {
  2376. return
  2377. }
  2378. clots = $.parseJSON(clotInfo)[0]
  2379. var ladders = clots['ladders']
  2380. var md = ""
  2381. var rt = ""
  2382. $.each(ladders, function (key, val) {
  2383. if (val.type == "realtime") {
  2384. rt += "<tr><td><a target='_blank' href=" + val.url + ">" + val.name + " (RT)</a> <span class='clotPlayers'>" + val.players + " Players joined</span></td></tr>"
  2385. } else if (val.type == "multiday") {
  2386. md += "<tr><td><a target='_blank' href = " + val.url + ">" + val.name + " (MD)</a><span class='clotPlayers'>" + val.players + " Players joined</span></td></tr>"
  2387. }
  2388. })
  2389. $("#ClotTable tbody tr").remove()
  2390. $("#ClotTable tbody").append(md)
  2391. $("#ClotTable tbody").append(rt)
  2392. $(window).trigger('resize');
  2393. } catch (e) {
  2394. console.log("Error reading CLOTs")
  2395. console.log(e.message)
  2396. hideTable("#ClotTable")
  2397. }
  2398. }
  2399. function getClots() {
  2400. return '[{"ladders":[{"url":"http:\/\/real-time-ladder.appspot.com\/lot\/5649391675244544","name":"Real Time Ladder","players":0,"type":"realtime"},{"url":"http:\/\/wl1v1-clot.appspot.com\/lot\/5629499534213120","name":"Old 1v1 Ladder","players":21,"type":"multiday"},{"url":"http:\/\/multi-day-ladder.appspot.com\/lot\/5629499534213120","error":"timeout"},{"url":"http:\/\/warladder.net","name":"Dutch ladder","players":"19","type":"multiday"}],"datetime":"2015\/12\/26 11:07:00"}]'
  2401. return localStorage.getItem('clots')
  2402. }
  2403.  
  2404. function loadClots() {
  2405. /*GM_xmlhttpRequest({
  2406. method: "GET",
  2407. url: "http://php-psenough.rhcloud.com/hub/list.php",
  2408. onload: function(response) {
  2409. try {
  2410. var json = '[' + response.responseText + ']'
  2411. if(isJson(json)) {
  2412. localStorage.setItem('clots', '[' + response.responseText + ']');
  2413. parseClotTable()
  2414. console.log("clot update " + clots['datetime'])
  2415. }
  2416. } catch (e) {
  2417. console.log("Error parsing CLOTs")
  2418. console.log(e.message)
  2419. }
  2420. }
  2421. })*/
  2422. }
  2423. function isJson(str) {
  2424. try {
  2425. JSON.parse(str);
  2426. } catch (e) {
  2427. return false;
  2428. }
  2429. return true;
  2430. }
  2431.  
  2432.  
  2433. function setupRightColumn(isInit) {
  2434. if(isInit) {
  2435. createSelector(".SideColumn > table", "margin-bottom: 17px;")
  2436. }
  2437. //Bookmarks
  2438. if(isInit) {
  2439. setupBookmarkTable()
  2440. } else {
  2441. refreshBookmarks()
  2442. }
  2443. //Tournament
  2444. // #MyTournamentsTable
  2445. //Clots
  2446. setupClotTable()
  2447. //RT Ladder
  2448. setupRealTimeLadder()
  2449. //Map of the Week
  2450. //Forum Posts
  2451. hideBlacklistedThreads()
  2452. //Blog Posts
  2453. //Coin Leaderboard
  2454. var sideColumn = $(".SideColumn")
  2455. $.each(getSortTables(), function(key, table) {
  2456. if(table.hidden == true) {
  2457. hideTable(table.id)
  2458. } else {
  2459. var table = $(table.id)
  2460. if(table.prev().hasClass("followWrap")) {
  2461. var wrap = table.prev().remove()
  2462. sideColumn.append(wrap)
  2463. }
  2464. table = table.detach()
  2465. sideColumn.append(table)
  2466. }
  2467. })
  2468. $(".SideColumn > br").remove()
  2469. if(isInit && isEnabled('scrollGames')) {
  2470. setupFixedTitlesInSideColumn()
  2471. }
  2472. }
  2473.  
  2474. function toWords(num) {
  2475. if(num == 1) {
  2476. return "one"
  2477. } else if(num == 2) {
  2478. return "two"
  2479. } else if(num == 3) {
  2480. return "three"
  2481. } else if(num == 4) {
  2482. return "four"
  2483. } else if(num == 5) {
  2484. return "five"
  2485. } else if(num == 6) {
  2486. return "six"
  2487. } else if(num == 7) {
  2488. return "seven"
  2489. } else if(num == 8) {
  2490. return "eight"
  2491. } else if(num == 9) {
  2492. return "nine"
  2493. } else if(num == 10) {
  2494. return "ten"
  2495. } else if(num == 0) {
  2496. return "zero"
  2497. }
  2498. }
  2499.  
  2500. function hideTable(seletor) {
  2501. if( $(seletor).prev().hasClass("followWrap")) {
  2502. $(seletor).prev().remove()
  2503. }
  2504. $(seletor).remove()
  2505. }
  2506.  
  2507. $(document).ready(function() {
  2508. (function(){
  2509. $.snowfall = function(element, options){
  2510. var flakes = [],
  2511. defaults = {
  2512. flakeCount : 50,
  2513. flakeColor : '#ffffff',
  2514. flakePosition: 'absolute',
  2515. flakeIndex: 999999,
  2516. minSize : 1,
  2517. maxSize : 2,
  2518. minSpeed : 1,
  2519. maxSpeed : 5,
  2520. round : false,
  2521. shadow : false,
  2522. collection : false,
  2523. collectionHeight : 40,
  2524. deviceorientation : false
  2525. },
  2526. options = $.extend(defaults, options),
  2527. random = function random(min, max){
  2528. return Math.round(min + Math.random()*(max-min));
  2529. };
  2530.  
  2531. $(element).data("snowfall", this);
  2532.  
  2533. // Snow flake object
  2534. function Flake(_x, _y, _size, _speed){
  2535. // Flake properties
  2536. this.x = _x;
  2537. this.y = _y;
  2538. this.size = _size;
  2539. this.speed = _speed;
  2540. this.step = 0;
  2541. this.stepSize = random(1,10) / 100;
  2542.  
  2543. if(options.collection){
  2544. this.target = canvasCollection[random(0,canvasCollection.length-1)];
  2545. }
  2546.  
  2547. var flakeMarkup = null;
  2548.  
  2549. if(options.image){
  2550. flakeMarkup = document.createElement("img");
  2551. flakeMarkup.src = options.image;
  2552. }else{
  2553. flakeMarkup = document.createElement("div");
  2554. $(flakeMarkup).css({'background' : options.flakeColor});
  2555. }
  2556.  
  2557. $(flakeMarkup).attr({
  2558. 'class': 'snowfall-flakes',
  2559. }).css({
  2560. 'width' : this.size,
  2561. 'height' : this.size,
  2562. 'position' : options.flakePosition,
  2563. 'top' : this.y,
  2564. 'left' : this.x,
  2565. 'fontSize' : 0,
  2566. 'zIndex' : options.flakeIndex
  2567. });
  2568.  
  2569. if($(element).get(0).tagName === $(document).get(0).tagName){
  2570. $('body').append($(flakeMarkup));
  2571. element = $('body');
  2572. }else{
  2573. $(element).append($(flakeMarkup));
  2574. }
  2575.  
  2576. this.element = flakeMarkup;
  2577.  
  2578. // Update function, used to update the snow flakes, and checks current snowflake against bounds
  2579. this.update = function(){
  2580. this.y += this.speed;
  2581.  
  2582. if(this.y > (elHeight) - (this.size + 6)){
  2583. this.reset();
  2584. }
  2585.  
  2586. this.element.style.top = this.y + 'px';
  2587. this.element.style.left = this.x + 'px';
  2588.  
  2589. this.step += this.stepSize;
  2590.  
  2591. if (doRatio === false) {
  2592. this.x += Math.cos(this.step);
  2593. } else {
  2594. this.x += (doRatio + Math.cos(this.step));
  2595. }
  2596.  
  2597. // Pileup check
  2598. if(options.collection){
  2599. if(this.x > this.target.x && this.x < this.target.width + this.target.x && this.y > this.target.y && this.y < this.target.height + this.target.y){
  2600. var ctx = this.target.element.getContext("2d"),
  2601. curX = this.x - this.target.x,
  2602. curY = this.y - this.target.y,
  2603. colData = this.target.colData;
  2604.  
  2605. if(colData[parseInt(curX)][parseInt(curY+this.speed+this.size)] !== undefined || curY+this.speed+this.size > this.target.height){
  2606. if(curY+this.speed+this.size > this.target.height){
  2607. while(curY+this.speed+this.size > this.target.height && this.speed > 0){
  2608. this.speed *= .5;
  2609. }
  2610.  
  2611. ctx.fillStyle = "#fff";
  2612.  
  2613. if(colData[parseInt(curX)][parseInt(curY+this.speed+this.size)] == undefined){
  2614. colData[parseInt(curX)][parseInt(curY+this.speed+this.size)] = 1;
  2615. ctx.fillRect(curX, (curY)+this.speed+this.size, this.size, this.size);
  2616. }else{
  2617. colData[parseInt(curX)][parseInt(curY+this.speed)] = 1;
  2618. ctx.fillRect(curX, curY+this.speed, this.size, this.size);
  2619. }
  2620. this.reset();
  2621. }else{
  2622. // flow to the sides
  2623. this.speed = 1;
  2624. this.stepSize = 0;
  2625.  
  2626. if(parseInt(curX)+1 < this.target.width && colData[parseInt(curX)+1][parseInt(curY)+1] == undefined ){
  2627. // go left
  2628. this.x++;
  2629. }else if(parseInt(curX)-1 > 0 && colData[parseInt(curX)-1][parseInt(curY)+1] == undefined ){
  2630. // go right
  2631. this.x--;
  2632. }else{
  2633. //stop
  2634. ctx.fillStyle = "#fff";
  2635. ctx.fillRect(curX, curY, this.size, this.size);
  2636. colData[parseInt(curX)][parseInt(curY)] = 1;
  2637. this.reset();
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643.  
  2644. if(this.x + this.size > (elWidth) - widthOffset || this.x < widthOffset){
  2645. this.reset();
  2646. }
  2647. }
  2648.  
  2649. // Resets the snowflake once it reaches one of the bounds set
  2650. this.reset = function(){
  2651. this.y = 0;
  2652. this.x = random(widthOffset, elWidth - widthOffset);
  2653. this.stepSize = random(1,10) / 100;
  2654. this.size = random((options.minSize * 100), (options.maxSize * 100)) / 100;
  2655. this.element.style.width = this.size + 'px';
  2656. this.element.style.height = this.size + 'px';
  2657. this.speed = random(options.minSpeed, options.maxSpeed);
  2658. }
  2659. }
  2660.  
  2661. // local vars
  2662. var i = 0,
  2663. elHeight = $(element).height(),
  2664. elWidth = $(element).width(),
  2665. widthOffset = 0,
  2666. snowTimeout = 0;
  2667.  
  2668. // Collection Piece ******************************
  2669. if(options.collection !== false){
  2670. var testElem = document.createElement('canvas');
  2671. if(!!(testElem.getContext && testElem.getContext('2d'))){
  2672. var canvasCollection = [],
  2673. elements = $(options.collection),
  2674. collectionHeight = options.collectionHeight;
  2675.  
  2676. for(var i =0; i < elements.length; i++){
  2677. var bounds = elements[i].getBoundingClientRect(),
  2678. $canvas = $('<canvas/>',
  2679. {
  2680. 'class' : 'snowfall-canvas'
  2681. }),
  2682. collisionData = [];
  2683.  
  2684. if(bounds.top-collectionHeight > 0){
  2685. $('body').append($canvas);
  2686.  
  2687. $canvas.css({
  2688. 'position' : options.flakePosition,
  2689. 'left' : bounds.left + 'px',
  2690. 'top' : bounds.top-collectionHeight + 'px'
  2691. })
  2692. .prop({
  2693. width: bounds.width,
  2694. height: collectionHeight
  2695. });
  2696.  
  2697. for(var w = 0; w < bounds.width; w++){
  2698. collisionData[w] = [];
  2699. }
  2700.  
  2701. canvasCollection.push({
  2702. element : $canvas.get(0),
  2703. x : bounds.left,
  2704. y : bounds.top-collectionHeight,
  2705. width : bounds.width,
  2706. height: collectionHeight,
  2707. colData : collisionData
  2708. });
  2709. }
  2710. }
  2711. }else{
  2712. // Canvas element isnt supported
  2713. options.collection = false;
  2714. }
  2715. }
  2716. // ************************************************
  2717.  
  2718. // This will reduce the horizontal scroll bar from displaying, when the effect is applied to the whole page
  2719. if($(element).get(0).tagName === $(document).get(0).tagName){
  2720. widthOffset = 25;
  2721. }
  2722.  
  2723. // Bind the Window resize event so we can get the innerHeight again
  2724. $(window).bind("resize", function(){
  2725. elHeight = $(element)[0].clientHeight;
  2726. elWidth = $(element)[0].offsetWidth;
  2727. });
  2728.  
  2729.  
  2730. // initialize the flakes
  2731. for(i = 0; i < options.flakeCount; i+=1){
  2732. flakes.push(new Flake(random(widthOffset,elWidth - widthOffset), random(0, elHeight), random((options.minSize * 100), (options.maxSize * 100)) / 100, random(options.minSpeed, options.maxSpeed)));
  2733. }
  2734.  
  2735. // This adds the style to make the snowflakes round via border radius property
  2736. if(options.round){
  2737. $('.snowfall-flakes').css({'-moz-border-radius' : options.maxSize, '-webkit-border-radius' : options.maxSize, 'border-radius' : options.maxSize});
  2738. }
  2739.  
  2740. // This adds shadows just below the snowflake so they pop a bit on lighter colored web pages
  2741. if(options.shadow){
  2742. $('.snowfall-flakes').css({'-moz-box-shadow' : '1px 1px 1px #555', '-webkit-box-shadow' : '1px 1px 1px #555', 'box-shadow' : '1px 1px 1px #555'});
  2743. }
  2744.  
  2745. // On newer Macbooks Snowflakes will fall based on deviceorientation
  2746. var doRatio = false;
  2747. if (options.deviceorientation) {
  2748. $(window).bind('deviceorientation', function(event) {
  2749. doRatio = event.originalEvent.gamma * 0.1;
  2750. });
  2751. }
  2752.  
  2753. // this controls flow of the updating snow
  2754. function snow(){
  2755. for( i = 0; i < flakes.length; i += 1){
  2756. flakes[i].update();
  2757. }
  2758.  
  2759. snowTimeout = requestAnimationFrame(function(){snow()});
  2760. }
  2761.  
  2762. snow();
  2763.  
  2764. // clears the snowflakes
  2765. this.clear = function(){
  2766. $('.snowfall-canvas').remove();
  2767. $(element).children('.snowfall-flakes').remove();
  2768. cancelAnimationFrame(snowTimeout);
  2769. }
  2770. };
  2771.  
  2772. // Initialize the options and the plugin
  2773. $.fn.snowfall = function(options){
  2774. if(typeof(options) == "object" || options == undefined){
  2775. return this.each(function(i){
  2776. (new $.snowfall(this, options));
  2777. });
  2778. }else if (typeof(options) == "string") {
  2779. return this.each(function(i){
  2780. var snow = $(this).data('snowfall');
  2781. if(snow){
  2782. snow.clear();
  2783. }
  2784. });
  2785. }
  2786. };
  2787. })(jQuery);
  2788. if(!isEnabled('disableSnow')) {
  2789. var flakes;
  2790. if(isEnabled('snowLight')) {
  2791. flakes = pageIsGame() ? 40 : 125
  2792. } else {
  2793. flakes = pageIsGame() ? 75 : 225
  2794. }
  2795. $(document).snowfall({flakeCount : flakes});
  2796. }
  2797. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址