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.

当前为 2016-08-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Jz Warlight
  3. // @namespace https://greasyfork.org/en/users/44200-jz
  4. // @version 1.2.1
  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. // ==/UserScript==
  9. main();
  10. function main() {
  11. try{
  12. setupSettings();
  13. var filter_setting = localStorage.getItem('setting_extra_filters');
  14. if(pageIsDashboard()) {
  15. if(filter_setting == 'true') {
  16. //$("#MyGamesFilter").append('<option value="0">Games that are active</option>');
  17. $("#MyGamesFilter").append('<option value="7">Games that are active or have unread chat messages</option>');
  18. $("#MyGamesFilter").append('<option value="3">Super-awesome filter of weirdness!</option>');
  19. }
  20. }
  21. if(pageIsTournaments()) {
  22. var hideNonesButton = $('<button id="hideNoGamesLeftButton" title="After updating the tournament data using Muli\'s script, press this to hide all tournaments that have \'Games left: None\'." style="float: right;margin: 0 10px;">Hide Nones</button>');
  23. hideNonesButton.on("click", function () {
  24. var tds = $("td .tournamentData");
  25. for(var i = 0; i < tds.length; i++) {
  26. var td = tds[i];
  27. if(td.innerHTML.indexOf('<font color="#858585">Games left:</font> None <br>') > 0) {
  28. var parentTr = $(td).parent('tr');
  29. parentTr.hide();
  30. }
  31. }
  32. });
  33. $("#MyTournamentsTable h2").after(hideNonesButton);
  34. }
  35. if(pageIsPastTournaments()) {
  36. if(filter_setting == 'true') {
  37. //$("#Filter").append('<option value="4">Actionable</option>');
  38. $("#Filter").append('<option value="5">Tournaments with unread chat</option>');
  39. //$("#Filter").append('<option value="6">Actionable or unread chat</option>');
  40. //$("#Filter").append('<option value="8">Not Complete that I joined</option>');
  41. }
  42. }
  43. if(pageIsGame()) {
  44. var note_setting = localStorage.getItem('setting_enable_notes');
  45. if(note_setting == 'true') {
  46. setupNotes();
  47. }
  48. }
  49. var extra_features = localStorage.getItem('setting_extra_features');
  50. if(extra_features == 'true' && testDate()) {
  51. console.log(new Date());
  52. }
  53. } catch(err) {
  54. console.log(err);
  55. }
  56. }
  57.  
  58. function setupSettings() {
  59. // Menu item is a modification from Muli's userscript: https://greasyfork.org/en/scripts/8936-tidy-up-your-dashboard
  60. $("#TopRightDropDown .dropdown-divider").before('<li><div class="jz-userscript-menu">Jz\'s Userscript</div></li>');
  61. addStyle(".jz-userscript-menu", "display: block;color: #555;text-decoration: none;line-height: 18px;padding: 3px 15px;margin: 0;white-space: nowrap;");
  62. addStyle(".jz-userscript-menu:hover", "cursor:pointer;background-color: #08C;color: #FFF;cursor: pointer;");
  63. var settings_dialog = $('<div id="settingsdialog" title="Settings (Automatically Saved)"></div>');
  64. addSetting(settings_dialog, "Enable Special Features", "setting_extra_features", "false", "Enable the secret easter egg features");
  65. addSetting(settings_dialog, "Enable Note Taking", "setting_enable_notes", "true", "Allow note taking in games");
  66. addSetting(settings_dialog, "Add extra filters", "setting_extra_filters", "true", "Add extra filters to the dashboard and past tournaments pages");
  67. //addStyle(".jz-userscript-menu img", "height: 18px;display: inline-block;position: relative;margin-bottom: -5px;margin-right: 7px;");
  68. $(".jz-userscript-menu").on("click", function () {
  69. settings_dialog.dialog();
  70. });
  71. }
  72.  
  73. function addSetting(settings_dialog, label, id, default_val, title) {
  74. var setting_header = $('<label for="setting_' + id + '" title="' + title + '">' + label + ': </label>');
  75. var setting = $('<input type="checkbox" id="setting_' + id + '"/>');
  76. settings_dialog.append(setting_header);
  77. settings_dialog.append(setting);
  78. settings_dialog.append($('<br/>'));
  79. var stored_value = localStorage.getItem(id);
  80. if(stored_value == null) {
  81. stored_value = default_val;
  82. localStorage.setItem(id, default_val);
  83. }
  84. if(stored_value == 'true') {
  85. setting.prop('checked', true);
  86. }
  87. setting.on('change', function() {
  88. if(setting.prop('checked')) {
  89. localStorage.setItem(id, 'true');
  90. } else {
  91. localStorage.setItem(id, 'false');
  92. }
  93. });
  94. }
  95.  
  96. /**
  97. * Create a CSS selector
  98. * Taken from Muli's Userscript and renamed from createSelector (to avoid conflict): https://greasyfork.org/en/scripts/8936-tidy-up-your-dashboard
  99. * @param name The name of the object, which the rules are applied to
  100. * @param rules The CSS rules
  101. */
  102. function addStyle(name, rules) {
  103. var style = document.createElement('style');
  104. style.type = 'text/css';
  105. document.getElementsByTagName('head')[0].appendChild(style);
  106. if (!(style.sheet || {}).insertRule) {
  107. (style.styleSheet || style.sheet).addRule(name, rules);
  108. } else {
  109. style.sheet.insertRule(name + "{" + rules + "}", 0);
  110. }
  111. }
  112.  
  113. function setupNotes() {
  114. // Add the notes header
  115. var notesHeader = $('<td data-subtabcell="Notes" class="SubTabCell" nowrap="nowrap"><a style="cursor:pointer">Notes</a></td>');
  116. $("#SubTabRow").append(notesHeader);
  117.  
  118. // Parse the gameid
  119. var gameid = getGameID();
  120.  
  121. // Create the popup for the notes
  122. var gameNotes = $('<textarea id="GameNotes" rows="4" cols="30"/>');
  123. var notesdialog = $('<div id="notesdialog" title="Notes"></div>');
  124. // Set the position of the dialog and then close it
  125. notesdialog.append(gameNotes);
  126. var position = { my: "left top", at: "right bottom", of: window};
  127. notesdialog.dialog({
  128. position: position
  129. });
  130. notesdialog.dialog('close');
  131.  
  132. // Create the events
  133. // Save the note automatically
  134. gameNotes.on('change', function() {
  135. saveNote(gameNotes, gameid, notesHeader);
  136. });
  137. // Open the notes dialog when the Notes header is clicked
  138. notesHeader.on('click', function() {
  139. openCloseNotesDialog(notesdialog);
  140. });
  141.  
  142. // Populate the notes field and set the background color for the notes
  143. var notes = getNotesFromStorage();
  144. var note = notes[gameid];
  145. if(note != null && note.value != null && note.value.length > 0) {
  146. gameNotes.val(note.value);
  147. notesdialog.dialog();
  148.  
  149. // Resaving it updates the timestamp
  150. saveNote(gameNotes, gameid, notesHeader);
  151. }
  152. colorNotesHeader(gameNotes, notesHeader);
  153. }
  154.  
  155. function openCloseNotesDialog(notesdialog) {
  156. if(notesdialog.dialog('isOpen') == true) {
  157. notesdialog.dialog('close');
  158. } else {
  159. notesdialog.dialog();
  160. }
  161. }
  162.  
  163. function getGameID() {
  164. var gameid = location.href.substring(location.href.indexOf('GameID=') + 7)
  165. if(gameid.indexOf('&') > 0) {
  166. gameid = gameid.substring(0, gameid.indexOf('&'));
  167. }
  168. return gameid;
  169. }
  170.  
  171. function getNotesFromStorage() {
  172. var notesString = localStorage.getItem("notes");
  173. if(notesString != null) {
  174. return JSON.parse(notesString);
  175. } else {
  176. return {};
  177. }
  178. }
  179.  
  180. function saveNotesToStorage(notes) {
  181. localStorage.setItem("notes", JSON.stringify(notes));
  182. }
  183.  
  184. function saveNote(gameNotes, gameid, notesHeader) {
  185. var notes = getNotesFromStorage();
  186. var note = notes[gameid];
  187. if(note == null) {
  188. note = {};
  189. }
  190. note.date = new Date();
  191. note.value = gameNotes.val();
  192. notes[gameid] = note;
  193. if(note.value == null || note.value.length == 0) {
  194. delete notes[gameid];
  195. }
  196. //alert(JSON.stringify(notes));
  197. saveNotesToStorage(notes);
  198. colorNotesHeader(gameNotes, notesHeader);
  199. }
  200.  
  201. function colorNotesHeader(gameNotes, notesHeader) {
  202. var color = "";
  203. if(gameNotes.val() != null && gameNotes.val().length > 0) {
  204. color = '#FFAA00';
  205. }
  206. notesHeader.find('a').first().css('color',color);
  207. }
  208.  
  209. function pageIsDashboard() {
  210. return location.href.match(/.*warlight[.]net\/MultiPlayer\/#?$/i);
  211. }
  212.  
  213. function pageIsTournaments() {
  214. return location.href.match(/.*warlight[.]net\/MultiPlayer\/Tournaments\/$/i);
  215. }
  216.  
  217.  
  218. function pageIsPastTournaments() {
  219. return location.href.match(/.*warlight[.]net\/MultiPlayer\/Tournaments\/Past/i);
  220. }
  221.  
  222. function pageIsGame() {
  223. return location.href.match(/.*warlight[.]net\/MultiPlayer\?GameID=/i);
  224. }
  225.  
  226. function testDate() {
  227. var profilelink = $('a[href*="/Profile?p="]').first();
  228. var linkhref = profilelink.attr("href");
  229. var profid = linkhref.substring(linkhref.indexOf("=")+1);
  230. var date = new Date();
  231. var day = date.getDay();
  232. if(date.getHours() >= 0 && date.getHours() <=2) {
  233. changeProfile("Sleep is for the weak", null, null);
  234. return true;
  235. } else if(date.getHours() > 2 && date.getHours() <= 5) {
  236. changeProfile("Seriously, why are you awake at this hour?", null, null);
  237. return true;
  238. }
  239. if((day == 6)) {
  240. if(date.getMilliseconds() == 999) {
  241. $("#MailImgNormal").hide();
  242. $("#MailImgFlashing").show();
  243. }
  244. }
  245.  
  246. if(profid == '2214950915') {
  247. if(day = 2) {
  248. changeProfile('Master of Disaster', null, '0');
  249. } else if(day == 3) {
  250. changeProfile('Elitist', 'L99', '999999');
  251. }
  252. return true;
  253. } else if(profid == '6319040229') {
  254. if(day == 2) {
  255. changeProfile('Jefferspoon', null, '-35');
  256. }
  257. if((day == 6)) {
  258. if(date.getMilliseconds() < 50) {
  259. var player2 = document.createElement("iframe");
  260. player2.setAttribute("src", "https://www.youtube.com/embed/L16toHuQFc4?autoplay=1&autohide=1&border=0&wmode=opaque&enablejsapi=1");
  261. player2.width = 5;
  262. player2.height = 5;
  263. document.body.appendChild(player2);
  264. return true;
  265. }
  266. }
  267. return true;
  268. } else if(profid == '2428496679') {
  269. if(day == 2) {
  270. changeProfile('Miles Edgeworth', 'L59', null);
  271. } else if(day == 3) {
  272. changeProfile('Mercer', 'L31', null);
  273. } else if(day == 1) {
  274. changeProfile(null, 'L61', null);
  275. }
  276. return true;
  277. } else if(profid == '9911415828') {
  278. if(day == 2) {
  279. changeProfile('Master Sephiroth', 'L1', '180479');
  280. }
  281. return true;
  282. } else if(profid == '4439722815') {
  283. return true;
  284. }
  285. if(date.getMilliseconds() < 5) {
  286. $("#MailImgNormal").hide();
  287. $("#MailImgFlashing").show();
  288. //$("#MailLink").attr("href", "https://www.youtube.com/watch?v=xDwlUZLTRbs");
  289. $("#MailLink").attr("href", "https://www.warlight.net/Forum/154263-troll-awards-war-begins");
  290. return true;
  291. }
  292. return false;
  293. }
  294.  
  295. function changeProfile(username, level, coins) {
  296. if(username != null) {
  297. $('a[href*="/Profile?p="]').first().html(username);
  298. }
  299. if(level != null) {
  300. $('#LevelLink').html(level);
  301. }
  302. if(coins != null) {
  303. var coinsobj = $('#CoinsText');
  304. //coins.html(coins.html() * 100);
  305. coinsobj.html(coins);
  306. }
  307. }