Jz Warlight

Adds extra filters for tournaments and dashboard games, including a fun filter that brings up a strange mix of games. Allows note-taking in games. A couple of easter eggs are also included.

当前为 2017-03-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Jz Warlight
  3. // @namespace https://greasyfork.org/en/users/44200-jz
  4. // @version 1.2.6
  5. // @grant none
  6. // @match https://www.warlight.net/*
  7. // @description Adds extra filters for tournaments and dashboard games, including a fun filter that brings up a strange mix of games. Allows note-taking in games. A couple of easter eggs are also included.
  8. // @require https://greasyfork.org/scripts/28001-jz-warlight-library/code/Jz%20Warlight%20Library.js
  9. // ==/UserScript==
  10.  
  11. main();
  12. function main() {
  13. try{
  14. setupSettings();
  15. var filter_setting = localStorage.getItem('setting_extra_filters');
  16. if(pageIsDashboard()) {
  17. if(filter_setting == 'true') {
  18. //$("#MyGamesFilter").append('<option value="0">Games that are active</option>');
  19. $("#MyGamesFilter").append('<option value="7">Games that are active or have unread chat messages</option>');
  20. $("#MyGamesFilter").append('<option value="3">Super-awesome filter of weirdness!</option>');
  21. }
  22. }
  23. if(pageIsTournaments()) {
  24. var muli_setting = localStorage.getItem('setting_enhance_muli');
  25. if(muli_setting == 'true') {
  26. // Add filters for tournaments, to expand the functionality Muli provided
  27. var filter = $('<select id="tournamentFilter" title="After updating the tournament data using Muli\'s script, pick a filter." style="float: right;margin: 0 10px;"/>');
  28. filter.append($('<option value="showAll">Show all</option>'));
  29. filter.append($('<option value="showGamesLeft">Tournaments with games left</option>'));
  30. filter.append($('<option value="showInProgress">Tournaments with games in progress</option>'));
  31. filter.append($('<option value="showNotEliminated">Tournaments that I am not eliminated from</option>'));
  32. filter.append($('<option value="showAlmostDone">Tournaments that are almost done</option>'));
  33. filter.append($('<option value="showCoin">Coin Tournaments</option>'));
  34. filter.on("change", function () {
  35. var selected = $( this ).val();
  36. var tds = $("td .tournamentData");
  37. for(var i = 0; i < tds.length; i++) {
  38. var td = tds[i];
  39. var parentTr = $(td).parent('tr');
  40. if(selected == "showAll") {
  41. parentTr.show();
  42. } else if(selected == "showGamesLeft") {
  43. if(td.innerHTML.indexOf('<font color="#858585">Games left:</font> None <br>') > 0) {
  44. parentTr.hide();
  45. } else {
  46. parentTr.show();
  47. }
  48. } else if(selected == "showInProgress") {
  49. if(td.innerHTML.indexOf('<font color="#858585">Playing:</font> 0 <br>') > 0) {
  50. parentTr.hide();
  51. } else if(td.innerHTML.indexOf('<font color="#858585">Playing:</font>') > 0) {
  52. parentTr.show();
  53. } else {
  54. parentTr.hide();
  55. }
  56. } else if(selected == "showNotEliminated") {
  57. // Show round robins, tournaments with games in progress, and tournaments with games left
  58. if(parentTr.html().indexOf('Round robin tournament') >= 0) {
  59. parentTr.show();
  60. } else if(td.innerHTML.indexOf('<font color="#858585">Playing:</font>') > 0
  61. && td.innerHTML.indexOf('<font color="#858585">Playing:</font> 0 <br>') == -1) {
  62. parentTr.show();
  63. } else if(td.innerHTML.indexOf('<font color="#858585">Games left:</font> None <br>') == -1) {
  64. parentTr.show();
  65. } else {
  66. parentTr.hide();
  67. }
  68. } else if(selected == "showAlmostDone") {
  69. if(td.innerHTML.indexOf('Almost done') > 0) {
  70. parentTr.show();
  71. } else {
  72. parentTr.hide();
  73. }
  74. } else if(selected == "showCoin") {
  75. if(parentTr.html().indexOf('https://d2wcw7vp66n8b3.cloudfront.net/Images/Coins/SmallCoins.png') != -1) {
  76. parentTr.show();
  77. } else {
  78. parentTr.hide();
  79. }
  80. }
  81. }
  82. });
  83. $("#MyTournamentsTable h2").after(filter);
  84. }
  85. }
  86. if(pageIsPastTournaments()) {
  87. if(filter_setting == 'true') {
  88. //$("#Filter").append('<option value="4">Actionable</option>');
  89. $("#Filter").append('<option value="5">Tournaments with unread chat</option>');
  90. //$("#Filter").append('<option value="6">Actionable or unread chat</option>');
  91. //$("#Filter").append('<option value="8">Not Complete that I joined</option>');
  92. }
  93. }
  94. if(pageIsGame()) {
  95. var note_setting = localStorage.getItem('setting_enable_notes');
  96. if(note_setting == 'true') {
  97. setupNotes();
  98. }
  99. }
  100. if(pageIsForum()) {
  101. // The following code was taken from Master of the Dead's blacklist script and modified to allow me to personally troll him
  102. var troll_setting = localStorage.getItem('setting_troll_motd');
  103. var forumPosts = $("#MainSiteContent").find("table:first").find("table");
  104. forumPosts.find("tr").each(function(i, post){
  105. var tdCell = $(post).find("td:first");
  106. var poster_cell = getPosterAnchor(tdCell);
  107. var poster_id = getPosterId(poster_cell);
  108. if(troll_setting == 'true' && poster_id == '2428496679') {
  109. changeAvatar(tdCell, "http://icons.iconarchive.com/icons/giannis-zographos/english-football-club/256/Liverpool-FC-icon.png");
  110. if(tdCell.html() != null) {
  111. tdCell.html(tdCell.html().replace('Level 62', 'Level 26'));
  112. tdCell.html(tdCell.html().replace('Level 63', 'Level 36'));
  113. }
  114. }
  115. if(troll_setting == 'true' && (poster_id == '1552135718' || poster_id == '397429597')) {
  116. changeAvatar(tdCell, "https://lh3.googleusercontent.com/-iDzlv7IG4rY/AAAAAAAAAAI/AAAAAAACsik/FnDXDKxLt5I/s0-c-k-no-ns/photo.jpg");
  117. if(tdCell.html() != null) {
  118. tdCell.html(tdCell.html().replace('Level 58', 'Level 85'));
  119. tdCell.html(tdCell.html().replace('Level 59', 'Level 95'));
  120. }
  121. }
  122. // Tag alts (alts retrieved from the library)
  123. for(var main_count = 0; main_count < mains.length; main_count++) {
  124. var main = mains[main_count];
  125. for(var alt_count = 0; alt_count < main.alts.length; alt_count++) {
  126. var alt = main.alts[alt_count];
  127. if(poster_id == alt) {
  128. var username = poster_cell.html();
  129. poster_cell.html(username + " (" + main.name + ")");
  130. }
  131. }
  132. }
  133. });
  134. }
  135. var extra_features = localStorage.getItem('setting_extra_features');
  136. if(extra_features == 'true' && testDate()) {
  137. console.log(new Date());
  138. }
  139. } catch(err) {
  140. console.log(err);
  141. }
  142. }
  143.  
  144. function getPosterAnchor(tdCell) {
  145. var posterCell = tdCell.find('a[href*="/Profile?p="]').first();
  146. return posterCell;
  147. }
  148.  
  149. function getPosterId(posterCell) {
  150. if(posterCell !== undefined && posterCell != null){
  151. var postAuthor = posterCell.attr("href");
  152. if(postAuthor != null && postAuthor.length > 11) {
  153. return postAuthor.substring(11);
  154. }
  155. }
  156. return null;
  157. }
  158.  
  159. function setupSettings() {
  160. // Menu item is a modification from Muli's userscript: https://greasyfork.org/en/scripts/8936-tidy-up-your-dashboard
  161. $("#TopRightDropDown .dropdown-divider").before('<li><div class="jz-userscript-menu">Jz\'s Userscript</div></li>');
  162. addStyle(".jz-userscript-menu", "display: block;color: #555;text-decoration: none;line-height: 18px;padding: 3px 15px;margin: 0;white-space: nowrap;");
  163. addStyle(".jz-userscript-menu:hover", "cursor:pointer;background-color: #08C;color: #FFF;cursor: pointer;");
  164. var settings_dialog = $('<div id="settingsdialog" title="Settings (Automatically Saved)"></div>');
  165. addSetting(settings_dialog, "Enable Special Features", "setting_extra_features", "false", "Enable the secret easter egg features");
  166. addSetting(settings_dialog, "Enable Note Taking", "setting_enable_notes", "true", "Allow note taking in games");
  167. addSetting(settings_dialog, "Add extra filters", "setting_extra_filters", "true", "Add extra filters to the dashboard and past tournaments pages");
  168. addSetting(settings_dialog, "Add features to enhance Muli's userscript", "setting_enhance_muli", "true", "If muli's script is installed, add features to enhance it.");
  169. addSetting(settings_dialog, "Master of the Dead deserves to be trolled", "setting_troll_motd", "true", "He insulted my trollhood, and so he deserves to be trolled.");
  170. //addStyle(".jz-userscript-menu img", "height: 18px;display: inline-block;position: relative;margin-bottom: -5px;margin-right: 7px;");
  171. $(".jz-userscript-menu").on("click", function () {
  172. settings_dialog.dialog();
  173. });
  174. }
  175.  
  176. function addSetting(settings_dialog, label, id, default_val, title) {
  177. var setting_header = $('<label for="setting_' + id + '" title="' + title + '">' + label + ': </label>');
  178. var setting = $('<input type="checkbox" id="setting_' + id + '"/>');
  179. settings_dialog.append(setting_header);
  180. settings_dialog.append(setting);
  181. settings_dialog.append($('<br/>'));
  182. var stored_value = localStorage.getItem(id);
  183. if(stored_value == null) {
  184. stored_value = default_val;
  185. localStorage.setItem(id, default_val);
  186. }
  187. if(stored_value == 'true') {
  188. setting.prop('checked', true);
  189. }
  190. setting.on('change', function() {
  191. if(setting.prop('checked')) {
  192. localStorage.setItem(id, 'true');
  193. } else {
  194. if(id == 'setting_troll_motd') {
  195. alert('Fool, change your settings, Master of the Dead DOES need to be trolled.');
  196. }
  197. localStorage.setItem(id, 'false');
  198. }
  199. });
  200. }
  201.  
  202. /**
  203. * Create a CSS selector
  204. * Taken from Muli's Userscript and renamed from createSelector (to avoid conflict): https://greasyfork.org/en/scripts/8936-tidy-up-your-dashboard
  205. * @param name The name of the object, which the rules are applied to
  206. * @param rules The CSS rules
  207. */
  208. function addStyle(name, rules) {
  209. var style = document.createElement('style');
  210. style.type = 'text/css';
  211. document.getElementsByTagName('head')[0].appendChild(style);
  212. if (!(style.sheet || {}).insertRule) {
  213. (style.styleSheet || style.sheet).addRule(name, rules);
  214. } else {
  215. style.sheet.insertRule(name + "{" + rules + "}", 0);
  216. }
  217. }
  218.  
  219. function setupNotes() {
  220. // Add the notes header
  221. var notesHeader = $('<td data-subtabcell="Notes" class="SubTabCell" nowrap="nowrap"><a style="cursor:pointer">Notes</a></td>');
  222. $("#SubTabRow").append(notesHeader);
  223.  
  224. // Parse the gameid
  225. var gameid = getGameID();
  226.  
  227. // Create the popup for the notes
  228. var gameNotes = $('<textarea id="GameNotes" rows="4" cols="30"/>');
  229. var notesdialog = $('<div id="notesdialog" title="Notes"></div>');
  230. // Set the position of the dialog and then close it
  231. notesdialog.append(gameNotes);
  232. var position = { my: "left top", at: "right bottom", of: window};
  233. notesdialog.dialog({
  234. position: position
  235. });
  236. notesdialog.dialog('close');
  237.  
  238. // Create the events
  239. // Save the note automatically
  240. gameNotes.on('change', function() {
  241. saveNote(gameNotes, gameid, notesHeader);
  242. });
  243. // Open the notes dialog when the Notes header is clicked
  244. notesHeader.on('click', function() {
  245. openCloseNotesDialog(notesdialog);
  246. });
  247.  
  248. // Populate the notes field and set the background color for the notes
  249. var notes = getNotesFromStorage();
  250. var note = notes[gameid];
  251. if(note != null && note.value != null && note.value.length > 0) {
  252. gameNotes.val(note.value);
  253. notesdialog.dialog();
  254.  
  255. // Resaving it updates the timestamp
  256. saveNote(gameNotes, gameid, notesHeader);
  257. }
  258. colorNotesHeader(gameNotes, notesHeader);
  259. }
  260.  
  261. function openCloseNotesDialog(notesdialog) {
  262. if(notesdialog.dialog('isOpen') == true) {
  263. notesdialog.dialog('close');
  264. } else {
  265. notesdialog.dialog();
  266. }
  267. }
  268.  
  269. function getGameID() {
  270. var gameid = location.href.substring(location.href.indexOf('GameID=') + 7)
  271. if(gameid.indexOf('&') > 0) {
  272. gameid = gameid.substring(0, gameid.indexOf('&'));
  273. }
  274. return gameid;
  275. }
  276.  
  277. function getNotesFromStorage() {
  278. var notesString = localStorage.getItem("notes");
  279. if(notesString != null) {
  280. return JSON.parse(notesString);
  281. } else {
  282. return {};
  283. }
  284. }
  285.  
  286. function saveNotesToStorage(notes) {
  287. localStorage.setItem("notes", JSON.stringify(notes));
  288. }
  289.  
  290. function saveNote(gameNotes, gameid, notesHeader) {
  291. var notes = getNotesFromStorage();
  292. var note = notes[gameid];
  293. if(note == null) {
  294. note = {};
  295. }
  296. note.date = new Date();
  297. note.value = gameNotes.val();
  298. notes[gameid] = note;
  299. if(note.value == null || note.value.length == 0) {
  300. delete notes[gameid];
  301. }
  302. //alert(JSON.stringify(notes));
  303. saveNotesToStorage(notes);
  304. colorNotesHeader(gameNotes, notesHeader);
  305. }
  306.  
  307. function colorNotesHeader(gameNotes, notesHeader) {
  308. var color = "";
  309. if(gameNotes.val() != null && gameNotes.val().length > 0) {
  310. color = '#FFAA00';
  311. }
  312. notesHeader.find('a').first().css('color',color);
  313. }
  314.  
  315. function pageIsDashboard() {
  316. return location.href.match(/.*warlight[.]net\/MultiPlayer\/#?$/i);
  317. }
  318.  
  319. function pageIsTournaments() {
  320. return location.href.match(/.*warlight[.]net\/MultiPlayer\/Tournaments\/$/i);
  321. }
  322.  
  323.  
  324. function pageIsPastTournaments() {
  325. return location.href.match(/.*warlight[.]net\/MultiPlayer\/Tournaments\/Past/i);
  326. }
  327.  
  328. function pageIsGame() {
  329. return location.href.match(/.*warlight[.]net\/MultiPlayer\?GameID=/i);
  330. }
  331.  
  332. function pageIsForum() {
  333. return location.href.match(/.*warlight[.]net\/Forum/i);
  334. }
  335.  
  336. function testDate() {
  337. var profilelink = $('a[href*="/Profile?p="]').first();
  338. var linkhref = profilelink.attr("href");
  339. var profid = linkhref.substring(linkhref.indexOf("=")+1);
  340. var date = new Date();
  341. var day = date.getDay();
  342. if(date.getHours() >= 0 && date.getHours() <=2) {
  343. changeProfile("Sleep is for the weak", null, null);
  344. return true;
  345. } else if(date.getHours() > 2 && date.getHours() <= 5) {
  346. changeProfile("Seriously, why are you awake at this hour?", null, null);
  347. return true;
  348. }
  349.  
  350. if(profid == '2214950915') {
  351. if(day = 2) {
  352. changeProfile('Master of Disaster', null, '0');
  353. } else if(day == 3) {
  354. changeProfile('Elitist', 'L99', '999999');
  355. }
  356. //return true;
  357. } else if(profid == '6319040229') {
  358. if(day == 2) {
  359. changeProfile('Jefferspoon', null, '-35');
  360. }
  361. if((day == 6)) {
  362. if(date.getMilliseconds() < 50) {
  363. var player2 = document.createElement("iframe");
  364. player2.setAttribute("src", "https://www.youtube.com/embed/L16toHuQFc4?autoplay=1&autohide=1&border=0&wmode=opaque&enablejsapi=1");
  365. player2.width = 5;
  366. player2.height = 5;
  367. document.body.appendChild(player2);
  368. return true;
  369. }
  370. }
  371. //return true;
  372. } else if(profid == '2428496679') {
  373. if(day == 2) {
  374. changeProfile('Miles Edgeworth', 'L59', null);
  375. } else if(day == 3) {
  376. changeProfile('Mercer', 'L31', null);
  377. } else if(day == 1) {
  378. changeProfile(null, 'L61', null);
  379. }
  380. //return true;
  381. } else if(profid == '9911415828') {
  382. if(day == 2) {
  383. changeProfile('Master Sephiroth', 'L1', '180479');
  384. }
  385. //return true;
  386. } else if(profid == '4439722815') {
  387. //return true;
  388. }
  389. if(date.getMilliseconds() == 0) {
  390. $("#MailImgNormal").hide();
  391. $("#MailImgFlashing").show();
  392. //$("#MailLink").attr("href", "https://www.youtube.com/watch?v=xDwlUZLTRbs");
  393. $("#MailLink").attr("href", "https://www.warlight.net/Forum/154263-troll-awards-war-begins");
  394. return true;
  395. }
  396. return false;
  397. }
  398.  
  399. function changeProfile(username, level, coins) {
  400. if(username != null) {
  401. $('a[href*="/Profile?p="]').first().html(username);
  402. }
  403. if(level != null) {
  404. $('#LevelLink').html(level);
  405. }
  406. if(coins != null) {
  407. var coinsobj = $('#CoinsText');
  408. //coins.html(coins.html() * 100);
  409. coinsobj.html(coins);
  410. }
  411. }
  412.  
  413. function changeAvatar(tdCell, src) {
  414. var image1 = $(tdCell).find("img:first");
  415. if(image1 != null && image1.attr('src').indexOf('https://s3.amazonaws.com/data.warlight.net/Data/Players') == 0) {
  416. image1.attr('src', src);
  417. } else {
  418. tdCell.prepend('<br/><img src="' + src + '" border="0" width="50" height="50" />');
  419. }
  420. }