warlight

Warlight Userscript

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

  1. // ==UserScript==
  2. // @name warlight
  3. // @grant none
  4. // @match https://www.warlight.net/MultiPlayer/
  5. // @description Warlight Userscript
  6. // @version 0.0.1.20150404111755
  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").on("click", function() {
  25. if(new Date() - lastRefresh > 3000) {
  26. lastRefresh = new Date()
  27. refreshAll();
  28. }
  29. })
  30.  
  31.  
  32. $("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>");
  33.  
  34. $(".userscript").on("change", function() {
  35. storeVariables();
  36. })
  37.  
  38. /*
  39. * Read Localstorage
  40. */
  41.  
  42. var scrollGames = localStorage.getItem("scrollGames") == "true";
  43. $("#scrollGames").prop("checked", scrollGames)
  44.  
  45. var autoRefreshOnFocus = localStorage.getItem("autoRefreshOnFocus") == "true";
  46. $("#autoRefreshOnFocus").prop("checked", autoRefreshOnFocus)
  47.  
  48. var hightlightTournaments = localStorage.getItem("hightlightTournaments") == "true";
  49. $("#hightlightTournaments").prop("checked", hightlightTournaments)
  50.  
  51. var hideMyGamesIcons = localStorage.getItem("hideMyGamesIcons") == "true";
  52. $("#hideMyGamesIcons").prop("checked", hideMyGamesIcons)
  53. var hideCoinSymbol = true;
  54.  
  55. /*
  56. * Hide coin Symbol
  57. */
  58. if(hideCoinSymbol) {
  59. createSelector('#PromotedGamesTable td:last-of-type a img', 'display:none')
  60. }
  61.  
  62. /*
  63. * Delayed Functions
  64. */
  65. var showAllGames = "";
  66. var showAllCoinGames = "";
  67. styleInterval = setInterval(delayed, 100);
  68. setTimeout(function() { clearInterval(styleInterval)}, 3000);
  69.  
  70. /*
  71. * Refresh Animation
  72. */
  73. $("#OpenGamesTable").prepend("<div class='loading loading-open'><img src='https://www.adobe.com/business/calculator/VIP/image/loader.gif' height='32' width='32'></div>");
  74. $("#MyGamesTable").prepend("<div class='loading loading-my'><img src='https://www.adobe.com/business/calculator/VIP/image/loader.gif' height='32' width='32'></div>");
  75. $("#PromotedGamesTable").prepend("<div class='loading loading-prom'><img src='https://www.adobe.com/business/calculator/VIP/image/loader.gif' height='32' width='32'></div>");
  76.  
  77. $("label[for='Refresh']").on("click", function() {
  78. refreshAll();
  79. })
  80.  
  81. var lastRefresh = new Date();
  82. if(autoRefreshOnFocus) {
  83. $(window).on('focus', function() {
  84. if(new Date() - lastRefresh > 30000) {
  85. lastRefresh = new Date()
  86. refreshAll();
  87. }
  88. });
  89. }
  90.  
  91.  
  92. $("body").keyup(function(event){
  93. //R
  94. if(event.which == 82) {
  95. if(new Date() - lastRefresh > 3000) {
  96. lastRefresh = new Date()
  97. refreshAll();
  98. }
  99. }
  100. });
  101.  
  102. /*
  103. * Highlight Tournaments
  104. */
  105. if(hightlightTournaments) {
  106. createSelector("#MyTournamentsTable tbody", "background:#4C4C33;");
  107. }
  108.  
  109. /*
  110. * Hide Icons in My Games
  111. */
  112. if(hideMyGamesIcons) {
  113. createSelector("#MyGamesTable td img", "display:none;");
  114. }
  115.  
  116.  
  117. /*
  118. * CSS
  119. */
  120. createSelector(".GameRow a", "font-size:16px !important;");
  121. 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;");
  122. createSelector("#MyGamesTable a img, #MyGamesTable span img", "display:inline-block;");
  123. createSelector(".GameRow:hover", "background-color:rgb(50, 50, 50);cursor:pointer;");
  124. createSelector(".BootTimeLabel", "color:white !important;font-weight:normal!important;font-style:italic;font-size:13px!important;z-index:50;");
  125. createSelector(".GameRow a:hover", "text-decoration:none;");
  126. createSelector(".ui-buttonset label", "font-size:11px;");
  127. createSelector("#OpenGamesTable label:hover", " border: 1px solid #59b4d4;background: #0078a3 50% 50% repeat-x;font-weight: bold;color: #ffffff;");
  128. createSelector("#OpenGamesTable td:last-child,#MyGamesTable td:last-child, #PromotedGamesTable td:last-child" , "position: relative;");
  129. //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;")
  130. 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;");
  131. 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;");
  132. createSelector(".loading img", "position: absolute;top: 50%;left: 50%;margin-left: -16px;margin-top: -16px;");
  133. createSelector("img", "position: relative;z-index:50;");
  134. createSelector("input", "z-index: 1000;position: relative;");
  135. 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");
  136. createSelector(".userscript-menu", "display: block;color: #555;text-decoration: none;line-height: 18px;padding: 3px 15px;margin: 0;white-space: nowrap;")
  137. createSelector(".userscript-menu:hover", "cursor:pointer;background-color: #08C;color: #FFF;cursor: pointer;")
  138. createSelector(".close-userscript", "margin-top: 40px;width: 100%;text-align: center;font-size: 15px;cursor: pointer;background: gray;line-height: 30px;border-radius: 8px;");
  139. createSelector(".close-userscript-img", "float:right;margin:5px;cursor:pointer");
  140. createSelector(".userscript label","width: 80%;display: inline-block;font-size: 15px;margin: 5px;")
  141. createSelector(".userscript input", "width: 20px;height: 20px;margin-left:30px;margin: 5px");
  142. createSelector(".userscript-container","display: block;position: absolute;background: white;top: 0;left: 0;right: 0;bottom: 0;z-index: 50000000;opacity: 0.5;");
  143. 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;");
  144. createSelector(".userscript-show","display:none");
  145. createSelector(".showGames table thead td","display:table-cell;width:100%;");
  146. createSelector(".showGames table thead tr","display:table;width:100%;");
  147. createSelector(".showGames table tbody","display:table;width:100%;");
  148.  
  149.  
  150. /*
  151. * Single Column Fixed
  152. */
  153. var gameButtons = "";
  154. var showGamesActive = "ShowMyGames";
  155.  
  156.  
  157. if(scrollGames) {
  158. 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>';
  159. $(".MainColumn ").prepend('<div class="showGamesContainer">'+gameButtons+'<div class="showGames"></div></div>');
  160. $("#MyGamesTable").appendTo(".showGames");
  161. $(".MainColumn ").after('<div class="showSide"></div>');
  162. $(".SideColumn").appendTo(".showSide");
  163. /*
  164. * Fixed Titles
  165. */
  166. $("#BlogTable").before("<div class='followMeBar'>"+ $("#BlogTable > thead > tr > td").html() + "</div>");
  167. $("#RealTimeLadderTable").before("<div class='followMeBar'>"+ $("#RealTimeLadderTable > thead > tr > td").html() + "</div>");
  168. $("#ForumTable").before("<div class='followMeBar'>"+ $("#ForumTable > thead > tr > td").html() + "</div>");
  169. $("#ClanForumTable").before("<div class='followMeBar'>"+ $("#ClanForumTable > thead > tr > td").html() + "</div>");
  170. $("#MapOfTheWeekTable").before("<div class='followMeBar'>"+ $("#MapOfTheWeekTable > thead > tr > td").html() + "</div>");
  171. $("#LeaderboardTable").before("<div class='followMeBar'>"+ $("#LeaderboardTable > thead > tr > td").html() + "</div>");
  172. $("#MyTournamentsTable").before("<div class='followMeBar'>"+ $("#MyTournamentsTable > thead > tr > td").html() + "</div>");
  173.  
  174. createSelector(".followMeBar","background: #330000;padding: 5px 20px;position: relative;z-index: 1;color: #fff;border-top-right-radius:8px;border-top-left-radius:8px;border: 1px solid gray;border-bottom:none");
  175. //createSelector(".followMeBar.fixed","position: fixed;top: 0;width: 100%;box-sizing: border-box;z-index: 0;");
  176. var top = parseInt($(".showSide").offset().top) +parseInt(43);
  177. var width = 450;
  178. createSelector(".followMeBar.fixed","position: fixed;top: "+ top +"px;width: 100%;box-sizing: border-box;z-index: 0;width:"+width+"px;z-index:100;");
  179. createSelector(".followMeBar.fixed.absolute","position: absolute;");
  180. createSelector(".showSide", "overflow-y:scroll;float: left;margin-top: 43px;padding-right: 6px;");
  181. createSelector(".showSide thead", "display:none");
  182. createSelector(".showSide table", "border-top-right-radius:0;border-top-left-radius:0");
  183. /**
  184. * Other CSS
  185. */
  186. createSelector("#switchGameRadio label","margin-left: 6px !important")
  187. createSelector(".showGames table","display:block !important")
  188. 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);")
  189. createSelector("#MyGamesTable, #PromotedGamesTable, #OpenGamesTable","display:none")
  190. createSelector("#MainSiteContent > table > tbody > tr > td","width:100%")
  191. createSelector(".showGamesContainer", "max-width:625px")
  192. createSelector(".MainColumn", "max-width:650px")
  193. createSelector(".SideColumn", "float:left !important")
  194. createSelector("h2 + span", "margin-right: 50px;")
  195. createSelector(".fakerow div", "height: 0px;display: inline-block;opacity: 0;")
  196. createSelector(".fakerow td", "border:none !important")
  197. createSelector("body", "overflow:hidden");
  198. createSelector(".SideColumn", "width: 450px !important; margin-left: 20px;");
  199. createSelector("#MyGamesFilter","width:200px");
  200. createSelector(".showGames table thead","position:fixed; z-index:500; border-top-left-radius:8px")
  201. createSelector(".showGames table", "display:block; overflow-y:scroll; overflow-x:hidden; border:1px gray solid; border-radius:8px");
  202. createSelector(".showSide", "overflow-y:scroll;float: left;margin-top: 43px;padding-right: 6px;");
  203. new stickyTitles(jQuery(".followMeBar")).load();
  204. refreshSingleColumnSize()
  205.  
  206. $("#switchGameRadio label").on("click", function() {
  207. var newShowGames = $(this).attr("for");
  208. if(newShowGames != showGamesActive) {
  209. $.each($("#switchGameRadio label"), function( key, value ) {
  210. $(this).removeClass("ui-state-active");
  211. });
  212. $(this).addClass("ui-state-active");
  213.  
  214. if(newShowGames == "ShowMyGames") {
  215. showGamesActive = newShowGames;
  216. $("#PromotedGamesTable").appendTo("body");
  217. $("#OpenGamesTable").appendTo("body");
  218. $("#MyGamesTable").appendTo(".showGames");
  219. }
  220. else if(newShowGames == "ShowCoinGames") {
  221. showGamesActive = newShowGames;
  222. $("#MyGamesTable").appendTo("body");
  223. $("#OpenGamesTable").appendTo("body");
  224. $("#PromotedGamesTable").appendTo(".showGames");
  225. //showAllCoinGames.trigger("click");
  226. }
  227.  
  228. else if(newShowGames == "ShowOpenGames") {
  229. showGamesActive = newShowGames;
  230. $("#MyGamesTable").appendTo("body");
  231. $("#PromotedGamesTable").appendTo("body");
  232. $("#OpenGamesTable").appendTo(".showGames");
  233. }
  234. showAllGames.trigger("click");
  235. refreshSingleColumnSize()
  236.  
  237. }
  238. });
  239. }
  240.  
  241. $("#TopRightDropDown ul").append('<li><div class="userscript-menu ">Userscript</div></li>')
  242.  
  243. $(".userscript-menu").on("click", function() {
  244. $(".userscript-show").fadeToggle();
  245. $("#TopRightDropDown").fadeToggle();
  246. })
  247.  
  248. $(".close-userscript").on("click", function() {
  249. $(".userscript-show").fadeToggle();
  250. location.reload();
  251. })
  252.  
  253. $(".close-userscript-img").on("click", function() {
  254. $(".userscript-show").fadeToggle();
  255. })
  256.  
  257. $("label").on("click", function() {
  258. //showAllGames.trigger("click");
  259. //showAllCoinGames.trigger("click");
  260. })
  261.  
  262. $("label[for='MultiDayRadio']").on("click", function() {
  263. $("#OpenGamesTable").scrollTop(0);
  264. })
  265. $("label[for='RealTimeRadio']").on("click", function() {
  266. $("#OpenGamesTable").scrollTop(0);
  267. })
  268. $("label[for='BothRadio']").on("click", function() {
  269. $("#OpenGamesTable").scrollTop(0);
  270. })
  271.  
  272. $( window ).resize(function() {
  273. if(scrollGames) {
  274. refreshSingleColumnSize();
  275. }
  276. });
  277.  
  278. function delayed() {
  279. //Expand Games
  280. if(showAllGames == "") {
  281. showAllGames = $("#ShowMoreOpenGamesLink")
  282. showAllGames.trigger("click");
  283. }
  284. if(showAllCoinGames == "") {
  285. showAllCoinGames = $("#ShowMorePromotedGamesLink");
  286. showAllCoinGames.trigger("click");
  287. }
  288. }
  289.  
  290. function storeVariables() {
  291. localStorage.setItem("autoRefreshOnFocus", $("#autoRefreshOnFocus").prop("checked"));
  292. localStorage.setItem("hightlightTournaments", $("#hightlightTournaments").prop("checked"));
  293. localStorage.setItem("hideMyGamesIcons", $("#hideMyGamesIcons").prop("checked"));
  294. localStorage.setItem("scrollGames", $("#scrollGames").prop("checked"));
  295.  
  296. }
  297. function refreshSingleColumnSize() {
  298. $(".showSide").scrollTop(0)
  299. if($(window).width() < 1300) {
  300. $(".MainColumn").css('width', 550);
  301. //$("#OpenGamesTable thead tr td h2").css('margin-right', 29);
  302. } else {
  303. $(".MainColumn").css('width', "");
  304. //$("#OpenGamesTable thead tr td h2").css('margin-right', 57);
  305. }
  306. $(".followMeBar").each(function(){
  307. $(this).removeClass("fixed");
  308. if($(this).parent().hasClass("followWrap")) {
  309. $(this).unwrap();
  310. }
  311. var thisSticky = $(this).wrap('<div class="followWrap" />');
  312. thisSticky.parent().height(thisSticky.outerHeight());
  313. var pos = parseInt(thisSticky.offset().top) - parseInt($(".showSide").offset().top);
  314. $.data(thisSticky[0], 'pos', pos);
  315. });
  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或关注我们的公众号极客氢云获取最新地址