Tidy up your Dashboard

Customizable Userscript which tidies up your Dashboard!

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

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

QingJ © 2025

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