warlight

Warlight Userscript

当前为 2015-04-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name warlight
  3. // @grant none
  4. // @match https://www.warlight.net/MultiPlayer/
  5. // @description Warlight Userscript
  6. // @version 0.0.1.20150405112900
  7. // @namespace https://gf.qytechs.cn/users/10154
  8. // ==/UserScript==
  9.  
  10.  
  11. /*
  12. * Userscript Settings
  13. */
  14.  
  15. var inputs = "";
  16. inputs += '<label for="scrollGames">Fixed window with scrollable Games</label><input type="checkbox" id="scrollGames"><br>';
  17. inputs += '<label for="hideMyGamesIcons">Hide Icons in "My Games"</label><input type="checkbox" id="hideMyGamesIcons"><br>';
  18. inputs += '<label for="autoRefreshOnFocus">Automatically refresh Games on Tabfocus</label><input type="checkbox" id="autoRefreshOnFocus"><br>';
  19. inputs += '<label for="hightlightTournaments">Hightlight Tournament invites</label><input type="checkbox" id="hightlightTournaments"><br>';
  20. inputs += '<div class="close-userscript">Close and Refresh</div>';
  21.  
  22. lastRefresh = new Date()
  23. $("#RefreshBtn").replaceWith($("#RefreshBtn").clone().removeAttr("id").attr("id","refreshAll"));
  24. $("#refreshAll").appendTo("body");
  25. $("#refreshAll").on("click", function() {
  26. if(new Date() - lastRefresh > 3000) {
  27. lastRefresh = new Date()
  28. refreshAll();
  29. }
  30. })
  31.  
  32.  
  33. $("body").append("<div class='userscript-container userscript-show'></div><div class='userscript userscript-show'><div class='head'>Change Userscript Settings<img class='close-userscript-img' src='https://i.imgur.com/RItbpDS.png' height='25' width='25'></div>"+inputs+"</div>");
  34.  
  35. $(".userscript").on("change", function() {
  36. storeVariables();
  37. })
  38.  
  39. /*
  40. * Read Localstorage
  41. */
  42.  
  43. var scrollGames = localStorage.getItem("scrollGames") == "true";
  44. $("#scrollGames").prop("checked", scrollGames)
  45.  
  46. var autoRefreshOnFocus = localStorage.getItem("autoRefreshOnFocus") == "true";
  47. $("#autoRefreshOnFocus").prop("checked", autoRefreshOnFocus)
  48.  
  49. var hightlightTournaments = localStorage.getItem("hightlightTournaments") == "true";
  50. $("#hightlightTournaments").prop("checked", hightlightTournaments)
  51.  
  52. var hideMyGamesIcons = localStorage.getItem("hideMyGamesIcons") == "true";
  53. $("#hideMyGamesIcons").prop("checked", hideMyGamesIcons)
  54. var hideCoinSymbol = true;
  55.  
  56. /*
  57. * Hide coin Symbol
  58. */
  59. if(hideCoinSymbol) {
  60. createSelector('#PromotedGamesTable td:last-of-type a img', 'display:none')
  61. }
  62.  
  63. /*
  64. * Delayed Functions
  65. */
  66. var showAllGames = "";
  67. var showAllCoinGames = "";
  68. styleInterval = setInterval(delayed, 100);
  69. setTimeout(function() { clearInterval(styleInterval)}, 3000);
  70.  
  71. /*
  72. * Refresh Animation
  73. */
  74. $("#OpenGamesTable").prepend("<div class='loading loading-open'><img src='https://www.adobe.com/business/calculator/VIP/image/loader.gif' height='32' width='32'></div>");
  75. $("#MyGamesTable").prepend("<div class='loading loading-my'><img src='https://www.adobe.com/business/calculator/VIP/image/loader.gif' height='32' width='32'></div>");
  76. $("#PromotedGamesTable").prepend("<div class='loading loading-prom'><img src='https://www.adobe.com/business/calculator/VIP/image/loader.gif' height='32' width='32'></div>");
  77.  
  78. $("label[for='Refresh']").on("click", function() {
  79. refreshAll();
  80. })
  81.  
  82. var lastRefresh = new Date();
  83. if(autoRefreshOnFocus) {
  84. $(window).on('focus', function() {
  85. if(new Date() - lastRefresh > 30000) {
  86. lastRefresh = new Date()
  87. refreshAll();
  88. }
  89. });
  90. }
  91.  
  92.  
  93. $("body").keyup(function(event){
  94. //R
  95. if(event.which == 82) {
  96. if(new Date() - lastRefresh > 3000) {
  97. lastRefresh = new Date()
  98. refreshAll();
  99. }
  100. }
  101. });
  102.  
  103. /*
  104. * Highlight Tournaments
  105. */
  106. if(hightlightTournaments) {
  107. createSelector("#MyTournamentsTable tbody", "background:#4C4C33;");
  108. }
  109.  
  110. /*
  111. * Hide Icons in My Games
  112. */
  113. if(hideMyGamesIcons) {
  114. createSelector("#MyGamesTable td img", "display:none;");
  115. }
  116.  
  117.  
  118. /*
  119. * CSS
  120. */
  121. createSelector(".GameRow a", "font-size:16px !important;");
  122. 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;");
  123. createSelector("#MyGamesTable a img, #MyGamesTable span img", "display:inline-block;");
  124. createSelector(".GameRow:hover", "background-color:rgb(50, 50, 50);cursor:pointer;");
  125. createSelector(".BootTimeLabel", "color:white !important;font-weight:normal!important;font-style:italic;font-size:13px!important;z-index:50;");
  126. createSelector(".GameRow a:hover", "text-decoration:none;");
  127. createSelector(".ui-buttonset label", "font-size:11px;");
  128. createSelector("#OpenGamesTable label:hover", " border: 1px solid #59b4d4;background: #0078a3 50% 50% repeat-x;font-weight: bold;color: #ffffff;");
  129. createSelector("#OpenGamesTable td:last-child,#MyGamesTable td:last-child, #PromotedGamesTable td:last-child" , "position: relative;");
  130. //createSelector("#PromotedGamesTable tbody td:nth-of-type(2),#OpenGamesTable tbody td:nth-of-type(2), #MyGamesTable tbody td:nth-of-type(2)","display: inline-block;width: 402px;")
  131. 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;");
  132. 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;");
  133. createSelector(".loading img", "position: absolute;top: 50%;left: 50%;margin-left: -16px;margin-top: -16px;");
  134. createSelector("img", "position: relative;z-index:50;");
  135. createSelector("input", "z-index: 1000;position: relative;");
  136. createSelector(".userscript", "position: fixed;width: 420px;left: 50%;background: #171717;margin-left: -250px;top: 100px;z-index: 50000001; color:white;padding:60px 30px 30px 30px;border: 2px solid gray;border-radius:8px");
  137. createSelector(".userscript-menu", "display: block;color: #555;text-decoration: none;line-height: 18px;padding: 3px 15px;margin: 0;white-space: nowrap;")
  138. createSelector(".userscript-menu:hover", "cursor:pointer;background-color: #08C;color: #FFF;cursor: pointer;")
  139. createSelector(".close-userscript", "margin-top: 40px;width: 100%;text-align: center;font-size: 15px;cursor: pointer;background: gray;line-height: 30px;border-radius: 8px;");
  140. createSelector(".close-userscript-img", "float:right;margin:5px;cursor:pointer");
  141. createSelector(".userscript label","width: 80%;display: inline-block;font-size: 15px;margin: 5px;")
  142. createSelector(".userscript input", "width: 20px;height: 20px;margin-left:30px;margin: 5px");
  143. createSelector(".userscript-container","display: block;position: absolute;background: white;top: 0;left: 0;right: 0;bottom: 0;z-index: 50000000;opacity: 0.5;");
  144. createSelector(".userscript .head","position: absolute;height: 40px;background: #330000;width: 100%;left: 0;right: 0;top: 0;color: white;font-size: 15px;text-align: center;line-height: 40px;border-top-left-radius:8px;border-top-right-radius:8px;");
  145. createSelector(".userscript-show","display:none");
  146. createSelector(".showGames table thead td","display:table-cell;width:100%;");
  147. createSelector(".showGames table thead tr","display:table;width:100%;");
  148. createSelector(".showGames table tbody","display:table;width:100%;");
  149.  
  150.  
  151. /*
  152. * Single Column Fixed
  153. */
  154. var gameButtons = "";
  155. var showGamesActive = "ShowMyGames";
  156.  
  157.  
  158. if(scrollGames) {
  159. gameButtons = '<div style="margin: 10px;" id="switchGameRadio" class="ui-buttonset"><input type="radio" id="ShowMyGames" name="switchGames" checked="checked" class="ui-helper-hidden-accessible"><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><input type="radio" id="ShowOpenGames" name="switchGames" class="ui-helper-hidden-accessible"><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><input type="radio" id="ShowCoinGames" name="switchGames" class="ui-helper-hidden-accessible"><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></div>';
  160. $(".MainColumn ").prepend('<div class="showGamesContainer">'+gameButtons+'<div class="showGames"></div></div>');
  161. $("#MyGamesTable").appendTo(".showGames");
  162. $(".MainColumn ").after('<div class="showSide"></div>');
  163. $(".SideColumn").appendTo(".showSide");
  164. /*
  165. * Fixed Titles
  166. */
  167. $("#BlogTable").before("<div class='followMeBar'>"+ $("#BlogTable > thead > tr > td").html() + "</div>");
  168. $("#RealTimeLadderTable").before("<div class='followMeBar'>"+ $("#RealTimeLadderTable > thead > tr > td").html() + "</div>");
  169. $("#ForumTable").before("<div class='followMeBar'>"+ $("#ForumTable > thead > tr > td").html() + "</div>");
  170. $("#ClanForumTable").before("<div class='followMeBar'>"+ $("#ClanForumTable > thead > tr > td").html() + "</div>");
  171. $("#MapOfTheWeekTable").before("<div class='followMeBar'>"+ $("#MapOfTheWeekTable > thead > tr > td").html() + "</div>");
  172. $("#LeaderboardTable").before("<div class='followMeBar'>"+ $("#LeaderboardTable > thead > tr > td").html() + "</div>");
  173. $("#MyTournamentsTable").before("<div class='followMeBar'>"+ $("#MyTournamentsTable > thead > tr > td").html() + "</div>");
  174.  
  175. 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");
  176. var top = parseInt($(".showSide").offset().top) +parseInt(43);
  177. createSelector(".followMeBar.fixed","position: fixed;top: "+ top +"px;z-index: 0;z-index:100;");
  178. createSelector(".followMeBar.fixed.absolute","position: absolute;");
  179. createSelector(".showSide", "overflow-y:scroll;float: left;margin-top: 43px;padding-right: 6px;");
  180. createSelector(".showSide thead", "display:none");
  181. createSelector(".showSide table", "border-top-right-radius:0;border-top-left-radius:0");
  182. /**
  183. * Other CSS
  184. */
  185. createSelector("#switchGameRadio label","margin-left: 6px !important")
  186. createSelector(".showGames table","display:block !important")
  187. 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);")
  188. createSelector("#MyGamesTable, #PromotedGamesTable, #OpenGamesTable","display:none")
  189. createSelector("#MainSiteContent > table > tbody > tr > td","width:100%")
  190. //createSelector(".showGamesContainer", "max-width:625px")
  191. //createSelector(".MainColumn", "max-width:650px")
  192. createSelector(".MainColumn", "min-width:535px")
  193. createSelector(".MainColumn", "width:40.55% !important")
  194. createSelector(".SideColumn", "float:left !important")
  195. createSelector("h2 + span", "margin-right: 50px;")
  196. createSelector(".fakerow div", "height: 0px;display: inline-block;opacity: 0;")
  197. createSelector(".fakerow td", "border:none !important")
  198. createSelector("body", "overflow:hidden");
  199. createSelector(".SideColumn", "width: 100% !important;");
  200. createSelector("#MyGamesFilter","width:200px");
  201. createSelector(".showGames table thead","position:fixed; z-index:500; border-top-left-radius:8px")
  202. createSelector(".showGames table", "display:block; overflow-y:scroll; overflow-x:hidden; border:1px gray solid; border-radius:8px");
  203. createSelector(".adsbygoogle", "margin-top: 25px;");
  204. 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");
  205. createSelector("#refreshAll","position: absolute;top: 85px;right: 31px;");
  206. new stickyTitles(jQuery(".followMeBar")).load();
  207. refreshSingleColumnSize()
  208.  
  209. $("#switchGameRadio label").on("click", function() {
  210. var newShowGames = $(this).attr("for");
  211. //if(newShowGames != showGamesActive) {
  212. $.each($("#switchGameRadio label"), function( key, value ) {
  213. $(this).removeClass("ui-state-active");
  214. });
  215. $(this).addClass("ui-state-active");
  216.  
  217. if(newShowGames == "ShowMyGames") {
  218. showGamesActive = newShowGames;
  219. $("#PromotedGamesTable").appendTo("body");
  220. $("#OpenGamesTable").appendTo("body");
  221. $("#MyGamesTable").appendTo(".showGames");
  222. }
  223. else if(newShowGames == "ShowCoinGames") {
  224. showGamesActive = newShowGames;
  225. $("#MyGamesTable").appendTo("body");
  226. $("#OpenGamesTable").appendTo("body");
  227. $("#PromotedGamesTable").appendTo(".showGames");
  228. }
  229.  
  230. else if(newShowGames == "ShowOpenGames") {
  231. showGamesActive = newShowGames;
  232. $("#MyGamesTable").appendTo("body");
  233. $("#PromotedGamesTable").appendTo("body");
  234. $("#OpenGamesTable").appendTo(".showGames");
  235. }
  236. showAllGames.trigger("click");
  237. refreshSingleColumnSize()
  238.  
  239. // }
  240. });
  241. }
  242.  
  243. $("#TopRightDropDown ul").append('<li><div class="userscript-menu ">Userscript</div></li>')
  244.  
  245. $(".userscript-menu").on("click", function() {
  246. $(".userscript-show").fadeToggle();
  247. $("#TopRightDropDown").fadeToggle();
  248. })
  249.  
  250. $(".close-userscript").on("click", function() {
  251. $(".userscript-show").fadeToggle();
  252. location.reload();
  253. })
  254.  
  255. $(".close-userscript-img").on("click", function() {
  256. $(".userscript-show").fadeToggle();
  257. })
  258.  
  259. $("label").on("click", function() {
  260. //showAllGames.trigger("click");
  261. //showAllCoinGames.trigger("click");
  262. })
  263.  
  264. $("label[for='MultiDayRadio']").on("click", function() {
  265. $("#OpenGamesTable").scrollTop(0);
  266. })
  267. $("label[for='RealTimeRadio']").on("click", function() {
  268. $("#OpenGamesTable").scrollTop(0);
  269. })
  270. $("label[for='BothRadio']").on("click", function() {
  271. $("#OpenGamesTable").scrollTop(0);
  272. })
  273.  
  274. $( window ).resize(function() {
  275. if(scrollGames) {
  276. refreshSingleColumnSize();
  277. }
  278. });
  279.  
  280. function delayed() {
  281. //Expand Games
  282. if(showAllGames == "") {
  283. showAllGames = $("#ShowMoreOpenGamesLink")
  284. showAllGames.trigger("click");
  285. }
  286. if(showAllCoinGames == "") {
  287. showAllCoinGames = $("#ShowMorePromotedGamesLink");
  288. showAllCoinGames.trigger("click");
  289. }
  290. }
  291.  
  292. function storeVariables() {
  293. localStorage.setItem("autoRefreshOnFocus", $("#autoRefreshOnFocus").prop("checked"));
  294. localStorage.setItem("hightlightTournaments", $("#hightlightTournaments").prop("checked"));
  295. localStorage.setItem("hideMyGamesIcons", $("#hideMyGamesIcons").prop("checked"));
  296. localStorage.setItem("scrollGames", $("#scrollGames").prop("checked"));
  297.  
  298. }
  299. function refreshSingleColumnSize() {
  300. $(".showSide").scrollTop(0)
  301. /**
  302. * Sticky Titles
  303. */
  304. $(".followMeBar").each(function(){
  305. $(this).removeClass("fixed");
  306. if($(this).parent().hasClass("followWrap")) {
  307. $(this).unwrap();
  308. }
  309. var thisSticky = $(this).wrap('<div class="followWrap" />');
  310. thisSticky.parent().height(thisSticky.outerHeight());
  311. var pos = parseInt(thisSticky.offset().top) - parseInt($(".showSide").offset().top);
  312. $.data(thisSticky[0], 'pos', pos);
  313. });
  314. var width = $("#ForumTable").width();
  315. createSelector(".followMeBar", "width:"+width+"px;");
  316. $(".fakerow").remove();
  317. $(".showGames table").css({ height:window.innerHeight-150});
  318. $(".showGames table thead").css({ width:$(".showGames").width()-20});
  319. var height = $(".showGames table thead").height()+6;
  320. createSelector(".showGames table tbody tr:first-of-type td", "padding-top:"+height+"px");
  321. $(".showSide").css({ height:window.innerHeight-150});
  322. $(".showGames table tbody tr:first-of-type td").css("padding-top", $(".showGames table thead").height()+6)
  323.  
  324. }
  325.  
  326. function refreshHeight() {
  327. $("#MyGamesTable").css({ height:window.innerHeight-110, display:"block", "overflow-y":"scroll", "overflow-x":"hidden", "border":"1px gray solid", "border-radius":"8px"});
  328. $("#OpenGamesTable").css({ height:window.innerHeight-110, display:"block", "overflow-y":"scroll", "overflow-x":"hidden", "border":"1px gray solid", "border-radius":"8px"});
  329. }
  330.  
  331. function createSelector(name,rules){
  332. var style = document.createElement('style');
  333. style.type = 'text/css';
  334. document.getElementsByTagName('head')[0].appendChild(style);
  335. if(!(style.sheet||{}).insertRule)
  336. (style.styleSheet || style.sheet).addRule(name, rules);
  337. else
  338. style.sheet.insertRule(name+"{"+rules+"}",0);
  339. }
  340.  
  341. function refreshAll() {
  342. $("#MyGamesTable tbody").fadeTo('slow',0.15);
  343. $("#OpenGamesTable tbody").fadeTo('slow',0.15);
  344. $("#PromotedGamesTable tbody").fadeTo('slow',0.15);
  345. var page = $('<div />').load('https://www.warlight.net/MultiPlayer/ ', function() {
  346. var myGames = page.find('#MyGamesTable tbody tr');
  347. var openGames = page.find('#OpenGamesTable tbody tr');
  348. var promotedGames = page.find('#PromotedGamesTable tbody tr');
  349. $.each($("#PromotedGamesTable tbody tr"), function( key, value ) {
  350. if($(value).html().indexOf("PastGames") < 0) {
  351. $(value).remove();
  352. }
  353. });
  354. $("#OpenGamesTable tbody tr").remove();
  355. $("#PromotedGamesTable tbody tr").remove();
  356. $.each($("#MyGamesTable tbody tr"), function( key, value ) {
  357. if($(value).html().indexOf("PastGames") < 0) {
  358. $(value).remove();
  359. }
  360. });
  361. $("#OpenGamesTable").scrollTop(0);
  362. $("#MyGamesTable").scrollTop(0)
  363. $("#PromotedGamesTable").scrollTop(0)
  364. $("#MyGamesTable tbody").prepend(myGames);
  365. $("#OpenGamesTable tbody").prepend(openGames);
  366. $("#PromotedGamesTable tbody").prepend(promotedGames) ;
  367. $("#ShowMorePromotedGamesLinkContainer").remove();
  368. showAllGames.trigger("click");
  369. showAllCoinGames.trigger("click");
  370. $("#MyGamesTable tbody").fadeTo('slow',1);
  371. $("#OpenGamesTable tbody").fadeTo('slow',1);
  372. $("#PromotedGamesTable tbody").fadeTo('slow',1);
  373. if(scrollGames) {
  374. refreshSingleColumnSize()
  375. }
  376. });
  377. }
  378.  
  379. jQuery.fn.outerHTML = function(s) {
  380. return s
  381. ? this.before(s).remove()
  382. : jQuery("<p>").append(this.eq(0).clone()).html();
  383. };
  384.  
  385. function stickyTitles(stickies) {
  386. var thisObj = this;
  387.  
  388. thisObj.load = function() {
  389.  
  390. stickies.each(function(){
  391. var thisSticky = $(this).wrap('<div class="followWrap" />');
  392. thisSticky.parent().height(thisSticky.outerHeight());
  393. var pos = parseInt(thisSticky.offset().top) - parseInt($(".showSide").offset().top);
  394. $.data(thisSticky[0], 'pos', pos);
  395. });
  396. $(".showSide").off("scroll.stickies").on("scroll.stickies", function() {
  397. thisObj.scroll();
  398. });
  399. }
  400. thisObj.scroll = function() {
  401. stickies.each(function(i){
  402. var thisSticky = $(this),
  403. nextSticky = stickies.eq(i+1),
  404. prevSticky = stickies.eq(i-1),
  405. pos = $.data(thisSticky[0], 'pos');
  406. if (pos <= $(".showSide").scrollTop()) {
  407. thisSticky.addClass("fixed");
  408. if (nextSticky.length > 0 && thisSticky.offset().top >= $.data(nextSticky[0], 'pos') - thisSticky.outerHeight()) {
  409. thisSticky.addClass("absolute").css("top", jQuery.data(nextSticky[0], 'pos') - thisSticky.outerHeight());
  410. }
  411. } else {
  412. thisSticky.removeClass("fixed");
  413. if (prevSticky.length > 0 && $(".showSide").scrollTop() <= $.data(thisSticky[0], 'pos') - prevSticky.outerHeight()) {
  414. prevSticky.removeClass("absolute").removeAttr("style");
  415. }
  416. }
  417. });
  418. }
  419. }

QingJ © 2025

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